Code emitter can now emit all variable sizes

This commit is contained in:
Tristan B. Kildaire 2021-11-02 15:27:17 +02:00
parent 43891b1dfb
commit 536206fdc5
2 changed files with 66 additions and 6 deletions

View File

@ -8,8 +8,19 @@ import std.stdio;
import std.file;
public final class DCodeEmitter : CodeEmitter
{
/**
* TODO:
*
* 1. We need to keep track of pushes
* 2. WHen entering a new function we save old, use a queue
* 3. So we need to do something like that to be able to restore
*/
this(TypeChecker typeChecker, File file)
{
super(typeChecker, file);
@ -63,15 +74,56 @@ public final class DCodeEmitter : CodeEmitter
{
VariableDeclaration varDecInstr = cast(compiler.codegen.instruction.VariableDeclaration)instruction;
file.writeln(`asm
/**
* Byte-sized variable
*/
if(varDecInstr.length == 1)
{
sub RSP, 4;
mov dword ptr [RSP], 69;
file.writeln(`asm
{
sub RSP, 1;
mov byte ptr [RSP], 69;
}
`);
}
/**
* Short-sized variable
*/
else if(varDecInstr.length == 2)
{
file.writeln(`asm
{
sub RSP, 2;
mov word ptr [RSP], 69;
}
`);
}
/**
* Long-sized variable
*/
else if(varDecInstr.length == 4)
{
file.writeln(`asm
{
sub RSP, 4;
mov dword ptr [RSP], 69;
}
`);
}
/**
* Quad-sized variable
*/
else if(varDecInstr.length == 8)
{
file.writeln(`asm
{
sub RSP, 8;
mov qword ptr [RSP], 69;
}
`);
}
`);
/* TODO: We need to build map of stakc positions, maybe not */
}
/**
@ -81,6 +133,8 @@ public final class DCodeEmitter : CodeEmitter
{
VariableAssignmentInstr varAssInstr = cast(compiler.codegen.instruction.VariableAssignmentInstr)instruction;
/* Recursively descend soon */
// writeln("int "~varDecInstr.varName~";");

6
test.d
View File

@ -11,18 +11,24 @@ asm
{
sub RSP, 4;
mov dword ptr [RSP], 69;
mov dword ptr CR3, 32;
}
asm
{
sub RSP, 4;
mov dword ptr [RSP], 69;
mov dword ptr CR3, 32;
}
asm
{
sub RSP, 4;
mov dword ptr [RSP], 69;
mov dword ptr CR3, 32;
}