aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-09-17 01:28:55 +0200
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commitb095aedd386e076d1f5a56b7384b836e653387d1 (patch)
treea9dd7d7cbcfba19005ce8aa9486a70d31091d5c3 /include
parent2928e5f74983f5dd33bc65f192298af87996a037 (diff)
Add support for r8-r15 registers, pass args to registers directly (sys-v)
Diffstat (limited to 'include')
-rw-r--r--include/bytecode/bytecode.h21
-rw-r--r--include/ssa/ssa.h7
2 files changed, 16 insertions, 12 deletions
diff --git a/include/bytecode/bytecode.h b/include/bytecode/bytecode.h
index 346455c..8f786a2 100644
--- a/include/bytecode/bytecode.h
+++ b/include/bytecode/bytecode.h
@@ -9,7 +9,7 @@
#include <setjmp.h>
/*doc(Instructions)
- Variable length instructions. Instruction size ranges from 1 to 5 bytes.
+ Variable length instructions. Instruction size ranges from 1 to 4 bytes.
# Instruction formats
Instructions can be in 7 different formats:
1. 1 byte: Opcode(u8)
@@ -26,8 +26,7 @@
6.2 Opcode(u8) + register(i8) + intermediate(u16)\
6.3 Opcode(u8) + register(i8) + data(u16)\
6.4 Opcode(u8) + flags(u8) + num_local_var_reg(u16)\
- 6.5 Opcode(u8) + stack_offset(i24)
- 7. 5 bytes: Opcode(u8) + index(u8) + index(u16) + num_args(u8)
+ 6.5 Opcode(u8) + index(u8) + index(u16)
# Registers
Registers have a range of 128. Local variables start from register 0 and increment while parameters start from -1
and decrement. Registers have the scope of functions and reset after instructions reach a new function (AMAL_OP_FUNC_START).
@@ -48,13 +47,14 @@ typedef enum {
AMAL_OP_MUL, /* mul dst, reg1, reg2 - Unsigned multiplication */
AMAL_OP_IDIV, /* idiv dst, reg1, reg2 - Signed division */
AMAL_OP_DIV, /* div dst, reg1, reg2 - Unsigned division */
- AMAL_OP_PUSH, /* push reg - Push register onto stack */
- AMAL_OP_PUSHI, /* pushi int - Push intermediate onto stack */
- AMAL_OP_PUSHD, /* pushd data - Push data onto stack */
- AMAL_OP_PUSH_RET, /* push_ret reg - Push register onto stack as a return value of the next function call */
- AMAL_OP_CALL, /* call ii, fi, num_args - Call a function in imported file (ii, import index) using function index (fi) and num_args arguments. ii is u8, fi is u16 and num_args is u8 */
- AMAL_OP_CALLR, /* callr reg, num_args - Call a function using a register. Used for function pointers. num_args is u8 */
- AMAL_OP_CALLE, /* calle ii, efi, num_args - Call an extern function in imported file (ii, import index) using extern function index (efi) and num_args arguments. ii is u8, efi is u16 and num_args is u8 */
+ AMAL_OP_PUSH, /* push reg - Push register for CALL. Values are pushed right before a CALL, with no other instructions between */
+ AMAL_OP_PUSHI, /* pushi int - Push intermediate for CALL. Values are pushed right before a CALL, with no other instructions between */
+ AMAL_OP_PUSHD, /* pushd data - Push data for CALL. Values are pushed right before a CALL, with no other instructions between */
+ AMAL_OP_PUSH_RET, /* push_ret reg - Push register as a return value of the next function call */
+ AMAL_OP_CALL_START, /* call_start num_args - Start of a CALL with @num_args number of arguments. Arguments for the next CALL is pushed immediately after this, followed by a CALL. @num_args is u8 */
+ AMAL_OP_CALL, /* call ii, fi - Call a function in imported file (ii, import index) using function index (fi). The number of arguments is the number of values pushed to stack. ii is u8, fi is u16 */
+ AMAL_OP_CALLR, /* callr reg - Call a function using a register. Used for function pointers. The number of arguments is the number of values pushed to stack */
+ AMAL_OP_CALLE, /* calle ii, efi - Call an extern function in imported file (ii, import index) using extern function index (efi). The number of arguments is the number of values pushed to stack. ii is u8, efi is u16 */
AMAL_OP_CMP, /* cmp dst, reg1, reg2 - Set dst to 1 if reg1 equals reg2, otherwise set it to 0 */
AMAL_OP_JZ, /* jz reg, label - Jump to label in the current function if reg is zero. label is u16 */
AMAL_OP_JMP, /* jmp label - Unconditional jump to label in the current function. label is u16 */
@@ -64,6 +64,7 @@ typedef enum {
AMAL_OP_LABEL /* label - Label. This is the target of a jump instruction. Jump instructions only jump to labels in the same function scope */
} AmalOpcode;
+/* dec05eba = ba5ec0de = basecode */
#define AMAL_BYTECODE_MAGIC_NUMBER "\xde\xc0\x5e\xba"
#define AMAL_BYTECODE_MAGIC_NUMBER_SIZE 4
#define AMAL_BYTECODE_MAJOR_VERSION 1
diff --git a/include/ssa/ssa.h b/include/ssa/ssa.h
index 0b6501b..0ec43b0 100644
--- a/include/ssa/ssa.h
+++ b/include/ssa/ssa.h
@@ -26,6 +26,7 @@ typedef enum {
SSA_FUNC_END,
SSA_PUSH,
SSA_PUSH_RET,
+ SSA_CALL_START,
SSA_CALL,
SSA_CALL_EXTERN,
SSA_JUMP_ZERO,
@@ -109,18 +110,20 @@ typedef struct {
} SsaInsFuncStart;
typedef struct {
- u8 num_args;
FunctionDecl *func_decl;
u8 import_index;
} SsaInsFuncCall;
typedef struct {
- u8 num_args;
LhsExpr *func_decl_lhs;
int import_index;
} SsaInsFuncCallExtern;
typedef struct {
+ u8 num_args;
+} SsaInsCallStart;
+
+typedef struct {
SsaRegister condition_reg;
SsaLabelIndex target_label;
} SsaInsJumpZero;