aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAryadev Chavali <aryadev@aryadevchavali.com>2023-10-21 23:40:03 +0100
committerAryadev Chavali <aryadev@aryadevchavali.com>2023-10-21 23:40:03 +0100
commitf9b2c8ed777148739eae4ef050eb66b02cddbd51 (patch)
tree98027d989932f3dee2e14ff5affa7508e1cdd36e /src
parentd2cdb211b2d15c3a15b15737645f2a68641f34ee (diff)
downloadovm-f9b2c8ed777148739eae4ef050eb66b02cddbd51.tar.gz
ovm-f9b2c8ed777148739eae4ef050eb66b02cddbd51.tar.bz2
ovm-f9b2c8ed777148739eae4ef050eb66b02cddbd51.zip
Cleaned up and used macro magic to shorten the INST_* macros
Instead of having 3 differing macros for each typed version of each opcode, just supply the type as a symbol to the macro, which will concatenated the type to all the places necessary. Relies on D(BYTE|HWORD|WORD) and OP_*_(BYTE|HWORD|WORD) being a consistent naming style.
Diffstat (limited to 'src')
-rw-r--r--src/inst.h34
1 files changed, 8 insertions, 26 deletions
diff --git a/src/inst.h b/src/inst.h
index f72470c..805822b 100644
--- a/src/inst.h
+++ b/src/inst.h
@@ -23,6 +23,7 @@ typedef enum
{
OP_NOOP = 0,
+ // Dealing with data and registers
OP_PUSH_BYTE,
OP_PUSH_HWORD,
OP_PUSH_WORD,
@@ -67,34 +68,15 @@ inst_t *insts_read_bytecode(darr_t *, size_t *);
void insts_write_bytecode_file(inst_t *, size_t, FILE *);
inst_t *insts_read_bytecode_file(FILE *, size_t *);
-#define INST_BPUSH(BYTE) \
- ((inst_t){.opcode = OP_PUSH_BYTE, .operand = DBYTE(BYTE)})
+#define INST_PUSH(TYPE, OP) \
+ ((inst_t){.opcode = OP_PUSH_##TYPE, .operand = D##TYPE(OP)})
-#define INST_WPUSH(WORD) \
- ((inst_t){.opcode = OP_PUSH_WORD, .operand = DWORD(WORD)})
+#define INST_MOV(TYPE, OP) \
+ ((inst_t){.opcode = OP_MOV_##TYPE, .operand = D##TYPE(OP)})
-#define INST_FPUSH(FLOAT) \
- ((inst_t){.opcode = OP_PUSH_FLOAT, .operand = DFLOAT(FLOAT)})
+#define INST_POP(TYPE) ((inst_t){.opcode = OP_POP_##TYPE})
-#define INST_BMOV(REG) ((inst_t){.opcode = OP_MOV_BYTE, .operand = DBYTE(REG)})
-
-#define INST_WMOV(REG) ((inst_t){.opcode = OP_MOV_WORD, .operand = DBYTE(REG)})
-
-#define INST_FMOV(REG) ((inst_t){.opcode = OP_MOV_FLOAT, .operand = DBYTE(REG)})
-
-#define INST_BPOP ((inst_t){.opcode = OP_POP_BYTE})
-
-#define INST_WPOP ((inst_t){.opcode = OP_POP_WORD})
-
-#define INST_FPOP ((inst_t){.opcode = OP_POP_FLOAT})
-
-#define INST_BPUSH_REG(REG) \
- ((inst_t){.opcode = OP_PUSH_REGISTER_BYTE, .operand = DBYTE(REG)})
-
-#define INST_WPUSH_REG(REG) \
- ((inst_t){.opcode = OP_PUSH_REGISTER_WORD, .operand = DBYTE(REG)})
-
-#define INST_FPUSH_REG(REG) \
- ((inst_t){.opcode = OP_PUSH_REGISTER_FLOAT, .operand = DBYTE(REG)})
+#define INST_PUSH_REG(TYPE, REG) \
+ ((inst_t){.opcode = OP_PUSH_REGISTER_##TYPE, .operand = D##TYPE(REG)})
#endif