On 25/08/18 16:43, Luc Van Oostenryck wrote: > Opcodes are defined in linearize.c:enum opcode. > The file opcode.c also contains a table with opcodes properties. > > Centralize these definitions into a single file: opcode.def that opcode.def? Hmm, I think opcode-def.h may be better. > will then be reused for enum opcode & the table. > > Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> > --- > linearize.h | 116 ---------------------------------------------------- > opcode.c | 47 +++++---------------- > opcode.def | 114 +++++++++++++++++++++++++++++++++++++++++++++++++++ > opcode.h | 9 ++++ > 4 files changed, 134 insertions(+), 152 deletions(-) > create mode 100644 opcode.def > > diff --git a/linearize.h b/linearize.h > index d1fe7a2f0..53644d0a7 100644 > --- a/linearize.h > +++ b/linearize.h > @@ -145,122 +145,6 @@ struct instruction { > }; > }; > > -enum opcode { > - OP_BADOP, > - > - /* Entry */ > - OP_ENTRY, > - > - /* Terminator */ > - OP_TERMINATOR, > - OP_RET = OP_TERMINATOR, > - OP_BR, > - OP_CBR, > - OP_SWITCH, > - OP_COMPUTEDGOTO, > - OP_TERMINATOR_END = OP_COMPUTEDGOTO, > - > - /* Binary */ > - OP_BINARY, > - OP_ADD = OP_BINARY, > - OP_SUB, > - OP_MUL, > - OP_DIVU, OP_DIVS, > - OP_MODU, OP_MODS, > - OP_SHL, > - OP_LSR, OP_ASR, > - > - /* Floating-point binops */ > - OP_FADD, > - OP_FSUB, > - OP_FMUL, > - OP_FDIV, > - > - /* Logical */ > - OP_AND, > - OP_OR, > - OP_XOR, > - OP_BINARY_END = OP_XOR, > - > - /* floating-point comparison */ > - OP_FPCMP, > - OP_FCMP_ORD = OP_FPCMP, > - OP_FCMP_OEQ, > - OP_FCMP_ONE, > - OP_FCMP_OLE, > - OP_FCMP_OGE, > - OP_FCMP_OLT, > - OP_FCMP_OGT, > - OP_FCMP_UEQ, > - OP_FCMP_UNE, > - OP_FCMP_ULE, > - OP_FCMP_UGE, > - OP_FCMP_ULT, > - OP_FCMP_UGT, > - OP_FCMP_UNO, > - OP_FPCMP_END = OP_FCMP_UNO, > - > - /* Binary comparison */ > - OP_BINCMP, > - OP_SET_EQ = OP_BINCMP, > - OP_SET_NE, > - OP_SET_LE, > - OP_SET_GE, > - OP_SET_LT, > - OP_SET_GT, > - OP_SET_B, > - OP_SET_A, > - OP_SET_BE, > - OP_SET_AE, > - OP_BINCMP_END = OP_SET_AE, > - > - /* Uni */ > - OP_UNOP, > - OP_NOT = OP_UNOP, > - OP_NEG, > - OP_FNEG, > - > - /* Casts */ > - OP_TRUNC, > - OP_ZEXT, OP_SEXT, > - OP_FCVTU, OP_FCVTS, > - OP_UCVTF, OP_SCVTF, > - OP_FCVTF, > - OP_UTPTR, > - OP_PTRTU, > - OP_PTRCAST, > - OP_UNOP_END = OP_PTRCAST, > - > - /* Select - three input values */ > - OP_SEL, > - > - /* Memory */ > - OP_LOAD, > - OP_STORE, > - OP_SETVAL, > - OP_SETFVAL, > - OP_SYMADDR, > - > - /* Other */ > - OP_PHI, > - OP_PHISOURCE, > - OP_INLINED_CALL, > - OP_CALL, > - OP_SLICE, > - OP_NOP, > - OP_DEATHNOTE, > - OP_ASM, > - > - /* Sparse tagging (line numbers, context, whatever) */ > - OP_CONTEXT, > - OP_RANGE, > - > - /* Needed to translate SSA back to normal form */ > - OP_COPY, > - > - OP_LAST, /* keep this one last! */ > -}; > - > struct basic_block_list; > struct instruction_list; > > diff --git a/opcode.c b/opcode.c > index d872556e4..67cede02d 100644 > --- a/opcode.c > +++ b/opcode.c > @@ -20,42 +20,17 @@ > * THE SOFTWARE. > */ > > -#include "linearize.h" > +#include "opcode.h" > > const struct opcode_table opcode_table[OP_LAST] = { > - [OP_SET_EQ] = { .negate = OP_SET_NE, .swap = OP_SET_EQ, .to_float = OP_FCMP_OEQ, }, > - [OP_SET_NE] = { .negate = OP_SET_EQ, .swap = OP_SET_NE, .to_float = OP_FCMP_UNE, }, > - [OP_SET_LT] = { .negate = OP_SET_GE, .swap = OP_SET_GT, .to_float = OP_FCMP_OLT, }, > - [OP_SET_LE] = { .negate = OP_SET_GT, .swap = OP_SET_GE, .to_float = OP_FCMP_OLE, }, > - [OP_SET_GE] = { .negate = OP_SET_LT, .swap = OP_SET_LE, .to_float = OP_FCMP_OGE, }, > - [OP_SET_GT] = { .negate = OP_SET_LE, .swap = OP_SET_LT, .to_float = OP_FCMP_OGT, }, > - [OP_SET_B ] = { .negate = OP_SET_AE, .swap = OP_SET_A , .to_float = OP_FCMP_OLT, }, > - [OP_SET_BE] = { .negate = OP_SET_A , .swap = OP_SET_AE, .to_float = OP_FCMP_OLE, }, > - [OP_SET_AE] = { .negate = OP_SET_B , .swap = OP_SET_BE, .to_float = OP_FCMP_OGE, }, > - [OP_SET_A ] = { .negate = OP_SET_BE, .swap = OP_SET_B , .to_float = OP_FCMP_OGT, }, > - > - [OP_FCMP_ORD] = { .negate = OP_FCMP_UNO, .swap = OP_FCMP_ORD, }, > - [OP_FCMP_UNO] = { .negate = OP_FCMP_ORD, .swap = OP_FCMP_UNO, }, > - > - [OP_FCMP_OEQ] = { .negate = OP_FCMP_UNE, .swap = OP_FCMP_OEQ, }, > - [OP_FCMP_ONE] = { .negate = OP_FCMP_UEQ, .swap = OP_FCMP_ONE, }, > - [OP_FCMP_UEQ] = { .negate = OP_FCMP_ONE, .swap = OP_FCMP_UEQ, }, > - [OP_FCMP_UNE] = { .negate = OP_FCMP_OEQ, .swap = OP_FCMP_UNE, }, > - > - [OP_FCMP_OLT] = { .negate = OP_FCMP_UGE, .swap = OP_FCMP_OGT, }, > - [OP_FCMP_OLE] = { .negate = OP_FCMP_UGT, .swap = OP_FCMP_OGE, }, > - [OP_FCMP_OGE] = { .negate = OP_FCMP_ULT, .swap = OP_FCMP_OLE, }, > - [OP_FCMP_OGT] = { .negate = OP_FCMP_ULE, .swap = OP_FCMP_OLT, }, > - > - [OP_FCMP_ULT] = { .negate = OP_FCMP_OGE, .swap = OP_FCMP_UGT, }, > - [OP_FCMP_ULE] = { .negate = OP_FCMP_OGT, .swap = OP_FCMP_UGE, }, > - [OP_FCMP_UGE] = { .negate = OP_FCMP_OLT, .swap = OP_FCMP_ULE, }, > - [OP_FCMP_UGT] = { .negate = OP_FCMP_OLE, .swap = OP_FCMP_ULT, }, > - > - [OP_ADD] = { .to_float = OP_FADD, }, > - [OP_SUB] = { .to_float = OP_FSUB, }, > - [OP_MUL] = { .to_float = OP_FMUL, }, > - [OP_DIVS] = { .to_float = OP_FDIV, }, > - [OP_DIVU] = { .to_float = OP_FDIV, }, > - [OP_NEG] = { .to_float = OP_FNEG, }, > +#define OPCODE(OP,NG,SW,TF) \ > + [OP_##OP] = { \ > + .negate = OP_##NG, \ > + .swap = OP_##SW, \ > + .to_float = OP_##TF, \ > + }, > +#define OPCODE_RANGE(OP,S,E) > +#include "opcode.def" > +#undef OPCODE > +#undef OPCODE_RANGE > }; > diff --git a/opcode.def b/opcode.def > new file mode 100644 > index 000000000..7add0b879 > --- /dev/null > +++ b/opcode.def > @@ -0,0 +1,114 @@ > +// OPCODE negated swaped float > + > +OPCODE(BADOP, BADOP, BADOP, BADOP) Heh, something is wrong with \t chars in this table. This line looked fine in the original email, but when 'quoted' with '> ', it looks wrong. However, some other lines ... > + > +/* Entry */ > +OPCODE(ENTRY, BADOP, BADOP, BADOP) > + > +/* Terminator */ > +OPCODE(RET, BADOP, BADOP, BADOP) > +OPCODE(BR, BADOP, BADOP, BADOP) > +OPCODE(CBR, BADOP, BADOP, BADOP) > +OPCODE(SWITCH, BADOP, BADOP, BADOP) > +OPCODE(COMPUTEDGOTO, BADOP, BADOP, BADOP) > +OPCODE_RANGE(TERMINATOR, RET, COMPUTEDGOTO) > + > +/* Binary */ > +OPCODE(ADD, BADOP, BADOP, FADD) > +OPCODE(SUB, BADOP, BADOP, FSUB) > +OPCODE(MUL, BADOP, BADOP, FMUL) > +OPCODE(DIVU, BADOP, BADOP, FDIV) > +OPCODE(DIVS, BADOP, BADOP, FDIV) > +OPCODE(MODU, BADOP, BADOP, BADOP) > +OPCODE(MODS, BADOP, BADOP, BADOP) > +OPCODE(SHL, BADOP, BADOP, BADOP) > +OPCODE(LSR, BADOP, BADOP, BADOP) > +OPCODE(ASR, BADOP, BADOP, BADOP) > + > +/* Floating-point binops */ > +OPCODE(FADD, BADOP, BADOP, BADOP) > +OPCODE(FSUB, BADOP, BADOP, BADOP) > +OPCODE(FMUL, BADOP, BADOP, BADOP) > +OPCODE(FDIV, BADOP, BADOP, BADOP) > + > +/* Logical */ > +OPCODE(AND_BOOL, BADOP, BADOP, BADOP) > +OPCODE(OR_BOOL, BADOP, BADOP, BADOP) ... like this one, look wrong in the original email also! ;-) > +OPCODE(AND, BADOP, BADOP, BADOP) > +OPCODE(OR, BADOP, BADOP, BADOP) > +OPCODE(XOR, BADOP, BADOP, BADOP) > +OPCODE_RANGE(BINARY, ADD, XOR) > + > +/* floating-point comparison */ > +OPCODE(FCMP_ORD, FCMP_UNO, FCMP_ORD, BADOP) > +OPCODE(FCMP_OEQ, FCMP_UNE, FCMP_OEQ, BADOP) > +OPCODE(FCMP_ONE, FCMP_UEQ, FCMP_ONE, BADOP) > +OPCODE(FCMP_UEQ, FCMP_ONE, FCMP_UEQ, BADOP) > +OPCODE(FCMP_UNE, FCMP_OEQ, FCMP_UNE, BADOP) > +OPCODE(FCMP_OLT, FCMP_UGE, FCMP_OGT, BADOP) > +OPCODE(FCMP_OLE, FCMP_UGT, FCMP_OGE, BADOP) > +OPCODE(FCMP_OGE, FCMP_ULT, FCMP_OLE, BADOP) > +OPCODE(FCMP_OGT, FCMP_ULE, FCMP_OLT, BADOP) > +OPCODE(FCMP_ULT, FCMP_OGE, FCMP_UGT, BADOP) > +OPCODE(FCMP_ULE, FCMP_OGT, FCMP_UGE, BADOP) > +OPCODE(FCMP_UGE, FCMP_OLT, FCMP_ULE, BADOP) > +OPCODE(FCMP_UGT, FCMP_OLE, FCMP_ULT, BADOP) > +OPCODE(FCMP_UNO, FCMP_ORD, FCMP_UNO, BADOP) > +OPCODE_RANGE(FPCMP, FCMP_ORD, FCMP_UNO) > + > +/* Binary comparison */ > +OPCODE(SET_EQ, SET_NE, SET_EQ, FCMP_OEQ) > +OPCODE(SET_LT, SET_GE, SET_GT, FCMP_OLT) > +OPCODE(SET_LE, SET_GT, SET_GE, FCMP_OLE) > +OPCODE(SET_GE, SET_LT, SET_LE, FCMP_OGE) > +OPCODE(SET_GT, SET_LE, SET_LT, FCMP_OGT) > +OPCODE(SET_B, SET_AE, SET_A, FCMP_OLT) > +OPCODE(SET_BE, SET_A, SET_AE, FCMP_OLE) > +OPCODE(SET_AE, SET_B, SET_BE, FCMP_OGE) > +OPCODE(SET_A, SET_BE, SET_B, FCMP_OGT) > +OPCODE(SET_NE, SET_EQ, SET_NE, FCMP_UNE) > +OPCODE_RANGE(BINCMP, SET_EQ, SET_NE) > + > +/* Uni */ > +OPCODE(NOT, BADOP, BADOP, BADOP) > +OPCODE(NEG, BADOP, BADOP, FNEG) > +OPCODE(FNEG, BADOP, BADOP, BADOP) > +OPCODE(TRUNC, BADOP, BADOP, BADOP) > +OPCODE(ZEXT, BADOP, BADOP, BADOP) > +OPCODE(SEXT, BADOP, BADOP, BADOP) > +OPCODE(FCVTU, BADOP, BADOP, BADOP) > +OPCODE(FCVTS, BADOP, BADOP, BADOP) > +OPCODE(UCVTF, BADOP, BADOP, BADOP) > +OPCODE(SCVTF, BADOP, BADOP, BADOP) > +OPCODE(FCVTF, BADOP, BADOP, BADOP) > +OPCODE(UTPTR, BADOP, BADOP, BADOP) > +OPCODE(PTRTU, BADOP, BADOP, BADOP) > +OPCODE(PTRCAST, BADOP, BADOP, BADOP) Whereas this looked wrong in the original mail, but fine when quoted! > +OPCODE_RANGE(UNOP, NOT, PTRCAST) > +OPCODE(SYMADDR, BADOP, BADOP, BADOP) ditto this line. > +OPCODE(SLICE, BADOP, BADOP, BADOP) > + > +/* Select - three input values */ > +OPCODE(SEL, BADOP, BADOP, BADOP) > + > +/* Memory */ > +OPCODE(LOAD, BADOP, BADOP, BADOP) > +OPCODE(STORE, BADOP, BADOP, BADOP) > + > +/* Other */ > +OPCODE(PHISOURCE, BADOP, BADOP, BADOP) > +OPCODE(PHI, BADOP, BADOP, BADOP) > +OPCODE(SETVAL, BADOP, BADOP, BADOP) > +OPCODE(SETFVAL, BADOP, BADOP, BADOP) er, wrong in both ... > +OPCODE(CALL, BADOP, BADOP, BADOP) > +OPCODE(INLINED_CALL, BADOP, BADOP, BADOP) > +OPCODE(NOP, BADOP, BADOP, BADOP) > +OPCODE(DEATHNOTE, BADOP, BADOP, BADOP) > +OPCODE(ASM, BADOP, BADOP, BADOP) > + > +/* Sparse tagging (line numbers, context, whatever) */ > +OPCODE(CONTEXT, BADOP, BADOP, BADOP) ... you get the idea. :-D ATB, Ramsay Jones > +OPCODE(RANGE, BADOP, BADOP, BADOP) > + > +/* Needed to translate SSA back to normal form */ > +OPCODE(COPY, BADOP, BADOP, BADOP) > diff --git a/opcode.h b/opcode.h > index eda4c3a74..171df36fc 100644 > --- a/opcode.h > +++ b/opcode.h > @@ -3,6 +3,15 @@ > > #include "symbol.h" > > +enum opcode { > +#define OPCODE(OP,NG,SW,TF) OP_##OP, > +#define OPCODE_RANGE(OP,S,E) OP_##OP = OP_##S, OP_##OP##_END = OP_##E, > +#include "opcode.def" > +#undef OPCODE > +#undef OPCODE_RANGE > + OP_LAST, /* keep this one last! */ > +}; > + > extern const struct opcode_table { > int negate:8; > int swap:8; >