From f090d484ab9425be9d7e4e3f42ba4224dde35c2d Mon Sep 17 00:00:00 2001 From: A404M Date: Wed, 29 Jan 2025 03:06:16 +0330 Subject: move assembly to new file make constants to have a separate token --- src/compiler/code-generator.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'src/compiler/code-generator.c') diff --git a/src/compiler/code-generator.c b/src/compiler/code-generator.c index 342c790..27a0fdc 100644 --- a/src/compiler/code-generator.c +++ b/src/compiler/code-generator.c @@ -81,7 +81,7 @@ CodeGeneratorCodes *codeGenerator(AstTreeRoot *astTreeRoot) { case AST_TREE_TOKEN_TYPE_FUNCTION: case AST_TREE_TOKEN_TYPE_VOID: case AST_TREE_TOKEN_VALUE_U64: - case AST_TREE_TOKEN_VARIABLE: + case AST_TREE_TOKEN_CONSTANT: case AST_TREE_TOKEN_KEYWORD_PRINT_U64: case AST_TREE_TOKEN_FUNCTION_CALL: case AST_TREE_TOKEN_TYPE_U64: @@ -110,7 +110,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, printLog("Not implemented"); exit(0); } - if (function->token != AST_TREE_TOKEN_VARIABLE) { + if (function->token != AST_TREE_TOKEN_CONSTANT) { printLog("Not implemented"); exit(0); } @@ -132,7 +132,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, codes, createGenerateCode(label_begin, label_end, CODE_GENERATOR_INSTRUCTION_PRINT_U64, (void *)value)); - } else if (metadata->token == AST_TREE_TOKEN_VARIABLE) { + } else if (metadata->token == AST_TREE_TOKEN_CONSTANT) { AstTreeVariable *variable = metadata->metadata; CodeGeneratorOperandU64 value = (AstTreeU64)variable->value->metadata; generateCodePushCode( @@ -146,7 +146,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, } goto OK; case AST_TREE_TOKEN_VALUE_U64: - case AST_TREE_TOKEN_VARIABLE: + case AST_TREE_TOKEN_CONSTANT: case AST_TREE_TOKEN_FUNCTION: case AST_TREE_TOKEN_TYPE_TYPE: case AST_TREE_TOKEN_TYPE_FUNCTION: @@ -169,13 +169,7 @@ bool codeGeneratorAstTreeFunction(char *label_begin, char *label_end, } static const char TEMPLATE[] = - "format ELF64 executable 3\n\nSYS_exit = 60\nSYS_write = 1\nSTDOUT = " - "1\n\nsegment readable executable\nentry _start\n\n; rdi = the " - "number\nprint_u64:\nmov rcx, rsp\nmov rax, rdi\nmov rbx, 10\n\n.L:\nxor " - "rdx, rdx\ndiv rbx\nadd dl, '0'\ndec rcx\nmov [rcx],dl\ncmp rax, 0\njnz " - ".L\n\nmov rax, SYS_write\nmov rdi, STDOUT\nmov rsi, rcx\n\nmov rdx, " - "rsp\nsub rdx, rcx\n\nsyscall\nret\n\n_start:\ncall main\nmov rax, " - "SYS_exit\nxor rdi,rdi\nsyscall\n"; + "include 'stdlib/main.asm'\n"; static const size_t TEMPLATE_LEN = sizeof(TEMPLATE) / sizeof(*TEMPLATE) - sizeof(*TEMPLATE); -- cgit v1.2.3