2021-10-26 16:17:53 +01:00
|
|
|
module compiler.codegen.instruction;
|
|
|
|
|
|
|
|
import std.conv : to;
|
2021-11-09 17:16:51 +00:00
|
|
|
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
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-11-10 15:15:27 +00:00
|
|
|
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;
|
|
|
|
|
2021-10-26 19:36:39 +01:00
|
|
|
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;
|
2021-10-26 19:44:10 +01:00
|
|
|
|
|
|
|
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 19:58:42 +01:00
|
|
|
|
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-02-15 13:04:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 2022 New things
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2022-02-18 12:32:45 +00:00
|
|
|
//public class CallInstr : Instruction
|
|
|
|
public class CallInstr : Value
|
2022-02-15 13:04:16 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public class FuncCallInstr : CallInstr
|
|
|
|
{
|
2022-02-18 12:32:45 +00:00
|
|
|
/* Per-argument instrructions */
|
|
|
|
private Instruction[] evaluationInstructions;
|
|
|
|
|
|
|
|
private string functionName;
|
|
|
|
|
|
|
|
this(string functionName, ulong argEvalInstrsSize)
|
|
|
|
{
|
|
|
|
this.functionName = functionName;
|
|
|
|
evaluationInstructions.length = argEvalInstrsSize;
|
|
|
|
|
2022-02-20 13:35:18 +00:00
|
|
|
updateAddInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FuncCallInstr is built-bit-by-bit so toString information will change
|
|
|
|
*/
|
|
|
|
private void updateAddInfo()
|
|
|
|
{
|
|
|
|
addInfo = "FunctionName: "~functionName ~" EvalInstrs: "~ to!(string)(getEvaluationInstructions());
|
2022-02-18 12:32:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setEvalInstr(ulong argPos, Instruction instr)
|
|
|
|
{
|
|
|
|
evaluationInstructions[argPos] = instr;
|
2022-02-20 13:35:18 +00:00
|
|
|
updateAddInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
public Instruction[] getEvaluationInstructions()
|
|
|
|
{
|
|
|
|
return evaluationInstructions;
|
2022-02-18 12:32:45 +00:00
|
|
|
}
|
2021-10-26 16:17:53 +01:00
|
|
|
}
|