11// SPDX-License-Identifier: Apache-2.0
22
3- #include " llvmloopanalyzer .h"
3+ #include " llvmtypeanalyzer .h"
44#include " llvminstruction.h"
55#include " llvmvariableptr.h"
66
@@ -9,7 +9,7 @@ using namespace libscratchcpp;
99static const std::unordered_set<LLVMInstruction::Type>
1010 BEGIN_LOOP_INSTRUCTIONS = { LLVMInstruction::Type::BeginRepeatLoop, LLVMInstruction::Type::BeginWhileLoop, LLVMInstruction::Type::BeginRepeatUntilLoop };
1111
12- bool LLVMLoopAnalyzer::variableTypeChanges (LLVMVariablePtr *varPtr, LLVMInstruction *loopBody, Compiler::StaticType preLoopType) const
12+ bool LLVMTypeAnalyzer::variableTypeChangesInLoop (LLVMVariablePtr *varPtr, LLVMInstruction *loopBody, Compiler::StaticType preLoopType) const
1313{
1414 if (!varPtr || !loopBody)
1515 return false ;
@@ -38,18 +38,18 @@ bool LLVMLoopAnalyzer::variableTypeChanges(LLVMVariablePtr *varPtr, LLVMInstruct
3838 return true ;
3939 }
4040
41- return variableTypeChangesFromEnd (varPtr, ins, preLoopType);
41+ return variableTypeChangesInLoopFromEnd (varPtr, ins, preLoopType);
4242}
4343
44- bool LLVMLoopAnalyzer::variableTypeChangesFromEnd (LLVMVariablePtr *varPtr, LLVMInstruction *loopEnd, Compiler::StaticType preLoopType) const
44+ bool LLVMTypeAnalyzer::variableTypeChangesInLoopFromEnd (LLVMVariablePtr *varPtr, LLVMInstruction *loopEnd, Compiler::StaticType preLoopType) const
4545{
4646 // Find the last write instruction
4747 LLVMInstruction *ins = loopEnd->previous ;
4848
4949 while (ins && !isLoopStart (ins)) {
5050 if (isLoopEnd (ins) || isIfEnd (ins) || isElse (ins)) {
5151 // Nested loop or if statement
52- if (variableTypeChangesFromEnd (varPtr, ins, preLoopType))
52+ if (variableTypeChangesInLoopFromEnd (varPtr, ins, preLoopType))
5353 return true ;
5454
5555 // Skip the loop or if statement
@@ -83,32 +83,32 @@ bool LLVMLoopAnalyzer::variableTypeChangesFromEnd(LLVMVariablePtr *varPtr, LLVMI
8383 return false ;
8484}
8585
86- bool LLVMLoopAnalyzer ::isLoopStart (LLVMInstruction *ins) const
86+ bool LLVMTypeAnalyzer ::isLoopStart (LLVMInstruction *ins) const
8787{
8888 return (BEGIN_LOOP_INSTRUCTIONS.find (ins->type ) != BEGIN_LOOP_INSTRUCTIONS.cend ());
8989}
9090
91- bool LLVMLoopAnalyzer ::isLoopEnd (LLVMInstruction *ins) const
91+ bool LLVMTypeAnalyzer ::isLoopEnd (LLVMInstruction *ins) const
9292{
9393 return (ins->type == LLVMInstruction::Type::EndLoop);
9494}
9595
96- bool LLVMLoopAnalyzer ::isIfStart (LLVMInstruction *ins) const
96+ bool LLVMTypeAnalyzer ::isIfStart (LLVMInstruction *ins) const
9797{
9898 return (ins->type == LLVMInstruction::Type::BeginIf);
9999}
100100
101- bool LLVMLoopAnalyzer ::isElse (LLVMInstruction *ins) const
101+ bool LLVMTypeAnalyzer ::isElse (LLVMInstruction *ins) const
102102{
103103 return (ins->type == LLVMInstruction::Type::BeginElse);
104104}
105105
106- bool LLVMLoopAnalyzer ::isIfEnd (LLVMInstruction *ins) const
106+ bool LLVMTypeAnalyzer ::isIfEnd (LLVMInstruction *ins) const
107107{
108108 return (ins->type == LLVMInstruction::Type::EndIf);
109109}
110110
111- Compiler::StaticType LLVMLoopAnalyzer ::optimizeRegisterType (LLVMRegister *reg) const
111+ Compiler::StaticType LLVMTypeAnalyzer ::optimizeRegisterType (LLVMRegister *reg) const
112112{
113113 // TODO: Move this method out if it's used in LLVMCodeBuilder too
114114 assert (reg);
@@ -122,15 +122,15 @@ Compiler::StaticType LLVMLoopAnalyzer::optimizeRegisterType(LLVMRegister *reg) c
122122 return ret;
123123}
124124
125- Compiler::StaticType LLVMLoopAnalyzer ::writeValueType (LLVMInstruction *ins) const
125+ Compiler::StaticType LLVMTypeAnalyzer ::writeValueType (LLVMInstruction *ins) const
126126{
127127 assert (ins);
128128 assert (!ins->args .empty ());
129129 const auto arg = ins->args .back ().second ; // value is always the last argument in variable/list write instructions
130130 return optimizeRegisterType (arg);
131131}
132132
133- bool LLVMLoopAnalyzer ::typesMatch (LLVMInstruction *ins, Compiler::StaticType expectedType) const
133+ bool LLVMTypeAnalyzer ::typesMatch (LLVMInstruction *ins, Compiler::StaticType expectedType) const
134134{
135135 // auto argIns = arg->instruction;
136136
0 commit comments