44
55#include < scratchcpp/compiler.h>
66
7+ #include " ../instruction.h"
78#include " llvmregister.h"
89
910namespace libscratchcpp
@@ -12,102 +13,12 @@ namespace libscratchcpp
1213class LLVMLocalVariableInfo ;
1314class BlockPrototype ;
1415
15- struct LLVMInstruction
16+ struct LLVMInstruction : Instruction<LLVMInstruction, LLVMRegister>
1617{
17- enum class Type
18- {
19- FunctionCall,
20- Add,
21- Sub,
22- Mul,
23- Div,
24- Random,
25- RandomInt,
26- CmpEQ,
27- CmpGT,
28- CmpLT,
29- StrCmpEQCS, // case sensitive
30- StrCmpEQCI, // case insensitive
31- And,
32- Or,
33- Not,
34- Mod,
35- Round,
36- Abs,
37- Floor,
38- Ceil,
39- Sqrt,
40- Sin,
41- Cos,
42- Tan,
43- Asin,
44- Acos,
45- Atan,
46- Ln,
47- Log10,
48- Exp,
49- Exp10,
50- StringConcat,
51- StringChar,
52- StringLength,
53- Select,
54- CreateLocalVariable,
55- WriteLocalVariable,
56- ReadLocalVariable,
57- WriteVariable,
58- ReadVariable,
59- ClearList,
60- RemoveListItem,
61- AppendToList,
62- InsertToList,
63- ListReplace,
64- GetListContents,
65- GetListItem,
66- GetListSize,
67- GetListItemIndex,
68- ListContainsItem,
69- Yield,
70- BeginIf,
71- BeginElse,
72- EndIf,
73- BeginRepeatLoop,
74- LoopIndex,
75- BeginWhileLoop,
76- BeginRepeatUntilLoop,
77- BeginLoopCondition,
78- EndLoop,
79- Stop,
80- ThreadStop,
81- InvalidateTarget,
82- CallProcedure,
83- ProcedureArg,
84- Print
85- };
18+ using Type = Instruction<LLVMInstruction, LLVMRegister>::Type;
19+ using Instruction<LLVMInstruction, LLVMRegister>::Instruction; // inherit constructor
8620
87- LLVMInstruction (Type type, bool loopCondition) :
88- type (type),
89- loopCondition (loopCondition)
90- {
91- }
92-
93- Type type;
94- std::string functionName;
95- std::vector<std::pair<Compiler::StaticType, LLVMRegister *>> args; // target type, register
96- LLVMRegister *functionReturnReg = nullptr ;
97- bool functionTargetArg = false ; // whether to add target ptr to function parameters
98- bool functionCtxArg = false ; // whether to add execution context ptr to function parameters
99- LLVMLocalVariableInfo *localVarInfo = nullptr ; // for local variables
100- Variable *targetVariable = nullptr ; // for variables
101- List *targetList = nullptr ; // for lists
102- Compiler::StaticType targetType = Compiler::StaticType::Unknown; // variable or list type (before read/write operation)
103- BlockPrototype *procedurePrototype = nullptr ;
104- size_t procedureArgIndex = 0 ;
105- bool loopCondition = false ; // whether the instruction is part of a loop condition
106-
107- // Linked list
108- LLVMInstruction *previous = nullptr ;
109- LLVMInstruction *next = nullptr ;
110- std::shared_ptr<LLVMInstruction> _next; // ensure items are not deleted
21+ LLVMLocalVariableInfo *localVarInfo = nullptr ; // for local variables
11122};
11223
11324} // namespace libscratchcpp
0 commit comments