libopid: expand operands and opcodes
[openpower-isa.git] / src / libopid / opid-dis.c
1 #include <stddef.h>
2 #include <stdint.h>
3
4 #include "opid.h"
5
6 static inline enum opid_state
7 opid_disassemble_operand(uint64_t insn,
8 size_t category,
9 struct opid_operand *operand);
10
11 #include "opid-dis-gen.c"
12
13 static inline enum opid_state
14 opid_disassemble_operands(struct opid_ctx *ctx, uint64_t insn) {
15 for (size_t id = 0; ((id != OPID_OPERANDS) && ctx->record->operands[id]); ++id) {
16 enum opid_state state;
17
18 state = opid_disassemble_operand(insn,
19 ctx->record->operands[id],
20 &ctx->operands[id]);
21 if (state != OPID_SUCCESS) {
22 if (state == OPID_ERROR_OPERAND_0)
23 state = (enum opid_state)((size_t)state + id);
24 return state;
25 }
26 }
27
28 return OPID_SUCCESS;
29 }
30
31 enum opid_state
32 opid_disassemble(struct opid_ctx *ctx, uint64_t insn) {
33 ctx->record = opid_lookup_insn(insn);
34
35 if (ctx->record == NULL)
36 return OPID_ERROR_LOOKUP;
37
38 return opid_disassemble_operands(ctx, insn);
39 }