tlang/source/tlang/compiler/codegen/emit/core.d

78 lines
1.7 KiB
D
Raw Normal View History

2021-11-02 08:41:03 +00:00
module compiler.codegen.emit.core;
2021-06-01 14:18:09 +01:00
import compiler.symbols.data;
2021-11-02 08:41:03 +00:00
import compiler.typecheck.core;
import std.container.slist : SList;
import compiler.codegen.instruction;
import std.stdio;
import std.file;
import compiler.codegen.instruction : Instruction;
2021-06-01 14:18:09 +01:00
/**
* TODO: Perhaps have an interface that can emit(Context/Parent, Statement)
*/
/* TODO: Module linking (general overhaul required) */
2021-11-02 08:41:03 +00:00
public abstract class CodeEmitter
2021-06-01 14:18:09 +01:00
{
protected TypeChecker typeChecker;
2021-11-02 08:41:03 +00:00
/**
* Required queues
*/
protected SList!(Instruction) initQueue;
protected SList!(Instruction) codeQueue;
alias instructions = codeQueue;
protected File file;
protected string currentEmitBuildUp;
public void buildEmit(string data)
{
currentEmitBuildUp~=data;
}
public void flushEmit()
{
file.writeln(currentEmitBuildUp);
currentEmitBuildUp = "";
}
this(TypeChecker typeChecker, File file)
2021-06-01 14:18:09 +01:00
{
2021-11-02 08:41:03 +00:00
this.typeChecker = typeChecker;
/* Extract the allocation queue, the code queue */
initQueue = typeChecker.getInitQueue();
codeQueue = typeChecker.getCodeQueue();
this.file = file;
2021-06-01 14:18:09 +01:00
}
2021-06-01 14:24:13 +01:00
/**
* Begins the emit process
*/
2021-11-02 08:41:03 +00:00
public abstract void emit();
/**
* Finalizes the emitting process (only
* to be called after the `emit()` finishes)
*/
public abstract void finalize();
/**
* Transforms or emits a single Instruction
* and returns the transformation
*
* Params:
* instruction = The Instruction to transform/emit
* Returns: The Instruction emit as a string
*/
public abstract string transform(Instruction instruction);
2021-06-01 14:18:09 +01:00
}