22
33#include " llvmtypeanalyzer.h"
44#include " llvminstruction.h"
5- #include " llvmvariableptr.h"
65
76using namespace libscratchcpp ;
87
98static const std::unordered_set<LLVMInstruction::Type>
109 BEGIN_LOOP_INSTRUCTIONS = { LLVMInstruction::Type::BeginRepeatLoop, LLVMInstruction::Type::BeginWhileLoop, LLVMInstruction::Type::BeginRepeatUntilLoop };
1110
12- Compiler::StaticType LLVMTypeAnalyzer::variableType (LLVMVariablePtr *varPtr , LLVMInstruction *pos, Compiler::StaticType previousType) const
11+ Compiler::StaticType LLVMTypeAnalyzer::variableType (Variable *var , LLVMInstruction *pos, Compiler::StaticType previousType) const
1312{
14- if (!varPtr || !pos)
13+ if (!var || !pos)
1514 return Compiler::StaticType::Unknown;
1615
1716 // Check the last write operation before the instruction
@@ -36,7 +35,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(LLVMVariablePtr *varPtr, LLV
3635 firstElseBranch = ins;
3736 ins = skipBranch (ins);
3837 continue ;
39- } else if (isVariableWrite (ins, varPtr )) {
38+ } else if (isVariableWrite (ins, var )) {
4039 if (level <= 0 ) { // ignore nested branches (they're handled by the branch analyzer)
4140 write = ins;
4241 break ;
@@ -57,8 +56,8 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(LLVMVariablePtr *varPtr, LLV
5756 Compiler::StaticType elseBranchType = previousType;
5857
5958 if (!ignoreWriteAfterPos) {
60- firstBranchType = variableTypeAfterBranch (varPtr , firstBranch, previousType);
61- elseBranchType = variableTypeAfterBranch (varPtr , firstElseBranch, previousType);
59+ firstBranchType = variableTypeAfterBranch (var , firstBranch, previousType);
60+ elseBranchType = variableTypeAfterBranch (var , firstElseBranch, previousType);
6261 }
6362
6463 if (typesMatch (firstBranchType, elseBranchType))
@@ -74,9 +73,9 @@ Compiler::StaticType LLVMTypeAnalyzer::variableType(LLVMVariablePtr *varPtr, LLV
7473 return previousType;
7574}
7675
77- Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranch (LLVMVariablePtr *varPtr , LLVMInstruction *start, Compiler::StaticType previousType) const
76+ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranch (Variable *var , LLVMInstruction *start, Compiler::StaticType previousType) const
7877{
79- if (!varPtr || !start)
78+ if (!var || !start)
8079 return previousType;
8180
8281 assert (isLoopStart (start) || isIfStart (start) || isElse (start));
@@ -103,10 +102,10 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranch(LLVMVariablePtr *
103102
104103 // Process the branch from end
105104 bool write = false ; // only used internally (the compiler doesn't need this)
106- return variableTypeAfterBranchFromEnd (varPtr , ins, previousType, write);
105+ return variableTypeAfterBranchFromEnd (var , ins, previousType, write);
107106}
108107
109- Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd (LLVMVariablePtr *varPtr , LLVMInstruction *end, Compiler::StaticType previousType, bool &write) const
108+ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd (Variable *var , LLVMInstruction *end, Compiler::StaticType previousType, bool &write) const
110109{
111110 // Find the last write instruction
112111 LLVMInstruction *ins = end->previous ;
@@ -115,7 +114,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(LLVMVariab
115114 while (ins && !isLoopStart (ins) && !isIfStart (ins)) {
116115 if (isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) {
117116 // Process the nested loop or if statement
118- Compiler::StaticType ret = variableTypeAfterBranchFromEnd (varPtr , ins, previousType, write);
117+ Compiler::StaticType ret = variableTypeAfterBranchFromEnd (var , ins, previousType, write);
119118
120119 if (typesMatch (ret, previousType)) {
121120 if (write)
@@ -127,7 +126,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(LLVMVariab
127126
128127 if (isElse (ins)) {
129128 // Process if branch (the else branch is already processed)
130- ret = variableTypeAfterBranchFromEnd (varPtr , ins, previousType, write);
129+ ret = variableTypeAfterBranchFromEnd (var , ins, previousType, write);
131130
132131 if (typesMatch (ret, previousType)) {
133132 if (write) {
@@ -141,7 +140,7 @@ Compiler::StaticType LLVMTypeAnalyzer::variableTypeAfterBranchFromEnd(LLVMVariab
141140
142141 ins = skipBranch (ins);
143142 }
144- } else if (isVariableWrite (ins, varPtr )) {
143+ } else if (isVariableWrite (ins, var )) {
145144 // Variable write instruction
146145 Compiler::StaticType writeType = writeValueType (ins);
147146 write = true ;
@@ -209,9 +208,9 @@ bool LLVMTypeAnalyzer::isIfEnd(LLVMInstruction *ins) const
209208 return (ins->type == LLVMInstruction::Type::EndIf);
210209}
211210
212- bool LLVMTypeAnalyzer::isVariableWrite (LLVMInstruction *ins, LLVMVariablePtr *varPtr ) const
211+ bool LLVMTypeAnalyzer::isVariableWrite (LLVMInstruction *ins, Variable *var ) const
213212{
214- return (ins->type == LLVMInstruction::Type::WriteVariable && ins->workVariable == varPtr-> var );
213+ return (ins->type == LLVMInstruction::Type::WriteVariable && ins->workVariable == var);
215214}
216215
217216Compiler::StaticType LLVMTypeAnalyzer::optimizeRegisterType (LLVMRegister *reg) const
0 commit comments