summaryrefslogtreecommitdiff
path: root/src/gas_assembly_generator.h
diff options
context:
space:
mode:
authorCarlos Maniero <carlos@maniero.me>2023-05-10 14:26:40 -0300
committerCarlos Maniero <carlos@maniero.me>2023-05-10 14:26:40 -0300
commit2cf0bcb409f3a1fd298b664103d57c945c6349f5 (patch)
tree6756f530d3007d529fae11fd0168c235355bc220 /src/gas_assembly_generator.h
parentf1b1c191975581d5ef13bd04f33b6965235d00b4 (diff)
gas: Removes Linux entrypoint logic from function declaration
Before this commit, function declarations were making syscalls to interrupt the flow. This is a fair approach considering all our examples just have a main function. But won't work if the namespace has more then a single function. The return now always sets the return value on RAX and jumps to the function return label. The function return label, will restore RBP and jump back to callee's next instruction using RET instruction. Function labels are kept, which means that a function called my_fn will have the assembly label my_fn, so then, they can have INTEROP with other languages. Signed-off-by: Carlos Maniero <carlos@maniero.me>
Diffstat (limited to 'src/gas_assembly_generator.h')
-rw-r--r--src/gas_assembly_generator.h6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/gas_assembly_generator.h b/src/gas_assembly_generator.h
index e400d2c..18ffb7f 100644
--- a/src/gas_assembly_generator.h
+++ b/src/gas_assembly_generator.h
@@ -48,7 +48,8 @@ typedef struct gas_assembly_generator_t
FILE *stream;
vector_t *refs;
int stack_offset;
- uint64_t cur_label_index;
+ uint64_t counter_label_index;
+ uint64_t return_label_index;
evaluation_result_t latest_evaluation;
} gas_assembly_generator_t;
@@ -58,4 +59,7 @@ gas_assembly_generator_init(gas_assembly_generator_t *gen, FILE *stream);
void
gas_assembly_generator_compile(gas_assembly_generator_t *gen, ast_node_t *ast);
+void
+gas_assembly_generator_compile_linux_main(gas_assembly_generator_t *gen, ast_node_t *func);
+
#endif /* GAS_ASSEMBLY_GENERATOR_H */