summaryrefslogtreecommitdiffstats
path: root/opcode.h
diff options
context:
space:
mode:
Diffstat (limited to 'opcode.h')
-rw-r--r--opcode.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/opcode.h b/opcode.h
new file mode 100644
index 00000000..73948cd5
--- /dev/null
+++ b/opcode.h
@@ -0,0 +1,48 @@
+#ifndef OPCODE_H
+#define OPCODE_H
+#include <assert.h>
+
+typedef enum {
+#define OP(name, imm, in, out) name,
+#include "opcode_list.h"
+#undef OP
+} opcode;
+
+enum {
+ NUM_OPCODES =
+#define OP(name, imm, in, out) +1
+#include "opcode_list.h"
+#undef OP
+};
+
+enum {
+ OP_HAS_CONSTANT = 2,
+ OP_HAS_VARIABLE = 4,
+ OP_HAS_BRANCH = 8,
+ OP_HAS_SYMBOL = 16,
+ OP_HAS_CFUNC = 32,
+ OP_HAS_UFUNC = 64,
+ OP_IS_CALL_PSEUDO = 128,
+ OP_HAS_VARIABLE_LENGTH_ARGLIST = 256,
+ OP_HAS_BLOCK = 512,
+ OP_HAS_BINDING = 1024,
+};
+struct opcode_description {
+ opcode op;
+ const char* name;
+
+ int flags;
+
+ // length in 16-bit units
+ int length;
+
+ int stack_in, stack_out;
+};
+
+const struct opcode_description* opcode_describe(opcode op);
+
+static inline int opcode_length(opcode op) {
+ return opcode_describe(op)->length;
+}
+
+#endif