- Added some comments and now use the provided `outFile` for code emitting stage in `Compiler` class
This commit is contained in:
Tristan B. Velloza Kildaire 2023-01-16 12:07:11 +02:00
parent 167e946b34
commit 37debd8160
1 changed files with 7 additions and 9 deletions

View File

@ -30,6 +30,7 @@ public class Compiler
/* The chosen code emitter to use */ /* The chosen code emitter to use */
private CodeEmitter emitter; private CodeEmitter emitter;
private File emitOutFile;
/** /**
* Create a new compiler instance to compile the given * Create a new compiler instance to compile the given
@ -37,9 +38,10 @@ public class Compiler
* Params: * Params:
* sourceCode = the source code to compile * sourceCode = the source code to compile
*/ */
this(string sourceCode) this(string sourceCode, File emitOutFile)
{ {
this.inputSource = sourceCode; this.inputSource = sourceCode;
this.emitOutFile = emitOutFile;
} }
public void compile() public void compile()
@ -63,15 +65,11 @@ public class Compiler
/* Spawn a new typechecker/codegenerator on the module */ /* Spawn a new typechecker/codegenerator on the module */
this.typeChecker = new TypeChecker(modulle); this.typeChecker = new TypeChecker(modulle);
/* Perform code emitting */ /* Perform code emitting */
File outFile; this.emitter = new DCodeEmitter(typeChecker, emitOutFile);
outFile.open("tlangout.c", "w"); emitter.emit(); // Emit the code
this.emitter = new DCodeEmitter(typeChecker, outFile); emitOutFile.close(); // Flush (perform the write() syscall)
emitter.emit(); emitter.finalize(); // Call CC on the file containing generated C code
outFile.close();
// Cause the generation to happen
emitter.finalize();
} }
else else
{ {