tlang/source/tlang/compiler/codegen/instruction.d

177 lines
3.4 KiB
D
Raw Normal View History

2021-10-26 16:17:53 +01:00
module compiler.codegen.instruction;
import std.conv : to;
import compiler.typecheck.dependency.core : Context;
2021-10-26 16:17:53 +01:00
public class Instruction
{
2021-11-09 13:49:59 +00:00
/* Context for the Instruction (used in emitter for name resolution) */
2021-11-09 17:00:23 +00:00
public Context context;
2021-11-09 13:49:59 +00:00
2021-10-26 16:17:53 +01:00
protected string addInfo;
this()
{
// this.instructionName = instructionName;
}
public final override string toString()
{
return "[Instruction: "~this.classinfo.name~":"~addInfo~"]";
}
}
public class FetchInst : Instruction
{
}
public class Value : Instruction
{
}
public class StorageDeclaratio : Instruction
{
}
public class ClassStaticInitAllocate : Instruction
{
this(string className)
{
addInfo = "classStaticInitAllocate: "~className;
}
}
2021-10-26 19:32:47 +01:00
public class VariableAssignmentInstr : Instruction
{
/* Name of variable being declared */
public string varName; /*TODO: Might not be needed */
public Instruction data;
this(string varName, Instruction data)
{
this.varName = varName;
this.data = data;
addInfo = "assignTo: "~varName~", valInstr: "~data.toString();
2021-10-26 19:32:47 +01:00
}
}
2021-10-26 16:17:53 +01:00
public final class VariableDeclaration : StorageDeclaratio
{
/* Name of variable being declared */
public string varName;
/* Length */
public byte length;
this(string varName, byte len)
{
this.varName = varName;
this.length = len;
2021-10-26 19:32:47 +01:00
addInfo = "varName: "~varName;
2021-10-26 16:17:53 +01:00
}
}
public final class FetchValueVar : Value
{
/* Name of variable to fetch from */
public string varName;
/* Length */
public byte length;
this(string varName, byte len)
{
this.varName = varName;
this.length = len;
addInfo = "fetchVarValName: "~varName~", VarLen: "~to!(string)(length);
2021-10-26 16:17:53 +01:00
}
}
public final class LiteralValue : Value
{
/* Data */
public ulong data;
public byte len;
this(ulong data, byte len)
{
this.data = data;
this.len = len;
addInfo = "Data: "~to!(string)(data)~", Length: "~to!(string)(len);
}
}
/**
2021-10-26 21:03:48 +01:00
* BinOpInstr instruction
2021-10-26 16:17:53 +01:00
*
2021-10-26 21:03:48 +01:00
* Any sort of Binary Operator
2021-10-26 16:17:53 +01:00
*/
2021-10-26 21:03:48 +01:00
public class BinOpInstr : Instruction
2021-10-26 16:17:53 +01:00
{
2021-10-26 21:03:48 +01:00
import compiler.symbols.data;
2021-10-26 16:17:53 +01:00
private Instruction lhs;
private Instruction rhs;
2021-10-26 21:03:48 +01:00
private SymbolType operator;
2021-10-26 16:17:53 +01:00
2021-10-26 21:03:48 +01:00
this(Instruction lhs, Instruction rhs, SymbolType operator)
2021-10-26 16:17:53 +01:00
{
this.lhs = lhs;
this.rhs = rhs;
2021-10-26 21:03:48 +01:00
addInfo = "BinOpType: "~to!(string)(operator)~", LhsValInstr: "~lhs.toString()~", RhsValInstr: "~rhs.toString();
2021-10-26 16:17:53 +01:00
}
}
/**
* 2022 New things
*
*/
//public class CallInstr : Instruction
public class CallInstr : Value
{
}
public class FuncCallInstr : CallInstr
{
/* Per-argument instrructions */
private Instruction[] evaluationInstructions;
private string functionName;
this(string functionName, ulong argEvalInstrsSize)
{
this.functionName = functionName;
evaluationInstructions.length = argEvalInstrsSize;
updateAddInfo();
}
/**
* FuncCallInstr is built-bit-by-bit so toString information will change
*/
private void updateAddInfo()
{
addInfo = "FunctionName: "~functionName ~" EvalInstrs: "~ to!(string)(getEvaluationInstructions());
}
public void setEvalInstr(ulong argPos, Instruction instr)
{
evaluationInstructions[argPos] = instr;
updateAddInfo();
}
public Instruction[] getEvaluationInstructions()
{
return evaluationInstructions;
}
2021-10-26 16:17:53 +01:00
}