From c11e0792f4020d823779e0fe853abb8bb82a832e Mon Sep 17 00:00:00 2001 From: Curle Date: Thu, 7 Dec 2023 22:33:51 +0000 Subject: [PATCH] Minor fixes for the linux assembler --- src/assemble/LinuxGASAssembler.c | 19 +++++++++---------- tests/printf.er | 2 +- tests/switch.er | 2 +- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/assemble/LinuxGASAssembler.c b/src/assemble/LinuxGASAssembler.c index 8983aee..a961e5e 100644 --- a/src/assemble/LinuxGASAssembler.c +++ b/src/assemble/LinuxGASAssembler.c @@ -734,6 +734,8 @@ static void AsGlobalSymbol(struct SymbolTableEntry* Entry) { fprintf(OutputFile,"\t.globl\t%s\n", Entry->Name); fprintf(OutputFile, "%s:\n", Entry->Name); + printf("%s, %d\n", Entry->Name, Entry->Length); + for (i = 0; i < Entry->Length; i++) { init = 0; if (Entry->InitialValues != NULL) @@ -780,13 +782,10 @@ static int AsCall(struct SymbolTableEntry* Entry, int Args) { printf("\t\t\tFunction returns into %s\n", Registers[OutRegister]); // Allocate shadow space - fprintf(OutputFile, "\taddq\t$-32, %%rsp\n"); fprintf(OutputFile, "\tcall\t%s\n", Entry->Name); // Deallocate arguments and stack space. - if (Args > 4) - fprintf(OutputFile, "\taddq\t$%d, %%rsp\n", (8 * (Args - 4)) + 32); - else - fprintf(OutputFile, "\taddq\t$32, %%rsp\n"); + if (Args > 6) + fprintf(OutputFile, "\taddq\t$%d, %%rsp\n", 8 * (Args - 6)); fprintf(OutputFile, "\tmovq\t%%rax, %s\n", Registers[OutRegister]); @@ -1020,11 +1019,11 @@ static void AsFunctionPreamble(struct SymbolTableEntry* Entry) { if (ParamCount > 6) { // We only have 6 argument registers Param->SinkOffset = ParamOffset; ParamOffset += 8; + } else { + Entry->SinkOffset = AsCalcOffset(Param->Type); + AsStrLocalVar(Param, ParamReg--); } - - Entry->SinkOffset = AsCalcOffset(Param->Type); - AsStrLocalVar(Param, ParamReg--); - } + } // If we have more parameters, move them to the stack for (Local = Locals; Local != NULL; Local = Local->NextSymbol) { @@ -1032,7 +1031,7 @@ static void AsFunctionPreamble(struct SymbolTableEntry* Entry) { } // With all the parameters on the stack, we can allocate the shadow space - StackFrameOffset = ((LocalVarOffset + 31) & ~31); + StackFrameOffset = ((LocalVarOffset + 15) & ~16); fprintf(OutputFile, "\taddq\t$%d, %%rsp\n", -StackFrameOffset); diff --git a/tests/printf.er b/tests/printf.er index 4596c9f..9b173a2 100644 --- a/tests/printf.er +++ b/tests/printf.er @@ -1,4 +1,4 @@ -import "tests/print.em" +import "print.em" int :: main () { printf("%s\r\n", "hi there"); diff --git a/tests/switch.er b/tests/switch.er index fa1a040..420bd9e 100644 --- a/tests/switch.er +++ b/tests/switch.er @@ -1,4 +1,4 @@ -import "tests/print.em" +import "import/defs.eh" int stuff[] = { 5, 7, 9 };