From cd19f1e1d30f52c073b6871c436e770ce2ffdda0 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Sun, 15 Oct 2023 22:16:31 +0100 Subject: Better checking of opcode types Introduced an enum (opcode_type_t) for the masks and values of each opcode, which allows defining a single enum which checks an opcode by a opcode_type_t. --- src/inst.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'src/inst.h') diff --git a/src/inst.h b/src/inst.h index d8feb09..4ef26ac 100644 --- a/src/inst.h +++ b/src/inst.h @@ -39,10 +39,16 @@ typedef enum OP_HALT, } opcode_t; -#define OPCODE_IS_PUSH(OPCODE) (((OPCODE)&0b1) == 0b1) -#define OPCODE_IS_PUSH_REG(OPCODE) (((OPCODE)&0b10) == 0b10) -#define OPCODE_IS_POP(OPCODE) (((OPCODE)&0b100) == 0b100) -#define OPCODE_IS_MOV(OPCODE) (((OPCODE)&0b1000) == 0b1000) +// Masks and values to check if an opcode is of a type +typedef enum +{ + OP_TYPE_PUSH = 0b1, + OP_TYPE_PUSH_REGISTER = 0b10, + OP_TYPE_POP = 0b100, + OP_TYPE_MOV = 0b1000, +} opcode_type_t; + +#define OPCODE_IS_TYPE(OPCODE, TYPE) ((OPCODE & TYPE) == TYPE) typedef struct { -- cgit v1.2.3-13-gbd6f