summaryrefslogtreecommitdiff
path: root/src/pipac.c
diff options
context:
space:
mode:
authorJohnny Richard <johnny@johnnyrichard.com>2023-04-18 07:13:55 +0200
committerCarlos Maniero <carlosmaniero@gmail.com>2023-04-18 09:54:50 -0300
commite3761429de464c42cc2798dc858bf6b43883d9dc (patch)
tree7a0d37205db4aadc6fc079c5474cb3d36fd25328 /src/pipac.c
parentbf2bbaf31487a3935f1a27dc51886d6f53c3d73d (diff)
ast: Create AST visitor to traverse the tree
In the future we want to have the possibility of traverse the tree and pretty print it or generate binary for other platform like LLVM or transpile to C. This solution also implements the gas assembly x86_64 Linux code generation by using the visitor interface. Signed-off-by: Johnny Richard <johnny@johnnyrichard.com>
Diffstat (limited to 'src/pipac.c')
-rw-r--r--src/pipac.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/pipac.c b/src/pipac.c
index 6e6df9e..e56d8a1 100644
--- a/src/pipac.c
+++ b/src/pipac.c
@@ -21,21 +21,15 @@
#include "lexer.h"
#include "parser.h"
#include "string_view.h"
+#include "gas_assembly_generator.h"
void
generate_gas_x86_64_linux(ast_function_t *func)
{
- if (!string_view_eq(func->name, string_view_from_str("main"))) {
- fprintf(stderr, "[ERROR]: no main function has been defined!\n");
- exit(EXIT_FAILURE);
- }
+ gas_assembly_generator_t gen;
+ gas_assembly_generator_init(&gen, stdout);
- printf(".global _start\n");
- printf(".text\n");
- printf("_start:\n");
- printf(" mov $1, %%al\n");
- printf(" mov $%d, %%ebx\n", func->body.number);
- printf(" int $0x80\n");
+ ast_visitor_visit(&gen, func);
}
void