return EXIT_FAILURE;
}
- printf("%s [", ctx.record->name);
+ printf("%s [", ctx.name);
opid_foreach_operand(&ctx, operand) {
printf("(%" PRIi32 " ",
(int32_t)operand->value);
#include "opid-dis-gen.c"
static inline enum opid_state
-opid_disassemble_operands(struct opid_ctx *ctx, uint64_t insn) {
- for (size_t id = 0; ((id != OPID_OPERANDS) && ctx->record->operands[id]); ++id) {
+opid_disassemble_operands(struct opid_ctx *ctx,
+ struct opid_record const *record,
+ uint64_t insn) {
+ for (size_t id = 0; ((id != OPID_OPERANDS) && record->operands[id]); ++id) {
enum opid_state state;
state = opid_disassemble_operand(insn,
- ctx->record->operands[id],
+ record->operands[id],
&ctx->operands[id]);
if (state != OPID_SUCCESS) {
if (state == OPID_ERROR_OPERAND_0)
state = (enum opid_state)((size_t)state + id);
return state;
}
+
+ ctx->nr_operands = (id + 1);
}
return OPID_SUCCESS;
enum opid_state
opid_disassemble(struct opid_ctx *ctx, uint64_t insn) {
- ctx->record = opid_lookup_insn(insn);
-
- if (ctx->record == NULL)
+ enum opid_state state;
+ struct opid_record const *record;
+
+ record = opid_lookup_insn(insn);
+ if (record == NULL)
return OPID_ERROR_LOOKUP;
- return opid_disassemble_operands(ctx, insn);
+ state = opid_disassemble_operands(ctx, record, insn);
+ if (state != OPID_SUCCESS)
+ return state;
+
+ ctx->name = record->name;
+
+ return OPID_SUCCESS;
}
#define OPID_OPERAND_ADDRESS (UINT64_C(1) << UINT64_C(7))
struct opid_ctx {
- struct opid_record const *record;
+ char const *name;
+ size_t nr_operands;
struct opid_operand operands[OPID_OPERANDS];
};
#define opid_foreach_operand(ctx, operand) \
for (size_t id = 0; \
(((operand = &(ctx)->operands[id]), 1) && \
- ((id != OPID_OPERANDS) && (ctx)->record->operands[id])); \
+ ((id != OPID_OPERANDS) && (id != (ctx)->nr_operands))); \
operand = &(ctx)->operands[++id])
enum opid_state