Skip to content

Commit 2d6dc53

Browse files
committed
LLVMLoopAnalyzer -> LLVMTypeAnalyzer
1 parent 33b37d6 commit 2d6dc53

File tree

5 files changed

+134
-134
lines changed

5 files changed

+134
-134
lines changed

src/engine/internal/llvm/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ target_sources(scratchcpp
1717
llvmtypes.h
1818
llvmfunctions.cpp
1919
llvmloopscope.h
20-
llvmloopanalyzer.cpp
21-
llvmloopanalyzer.h
20+
llvmtypeanalyzer.cpp
21+
llvmtypeanalyzer.h
2222
llvmcompilercontext.cpp
2323
llvmcompilercontext.h
2424
llvmexecutablecode.cpp

src/engine/internal/llvm/llvmloopanalyzer.cpp renamed to src/engine/internal/llvm/llvmtypeanalyzer.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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;
99
static 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

src/engine/internal/llvm/llvmloopanalyzer.h renamed to src/engine/internal/llvm/llvmtypeanalyzer.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ struct LLVMVariablePtr;
99
struct LLVMInstruction;
1010
struct LLVMRegister;
1111

12-
class LLVMLoopAnalyzer
12+
class LLVMTypeAnalyzer
1313
{
1414
public:
15-
bool variableTypeChanges(LLVMVariablePtr *varPtr, LLVMInstruction *loopBody, Compiler::StaticType preLoopType) const;
15+
bool variableTypeChangesInLoop(LLVMVariablePtr *varPtr, LLVMInstruction *loopBody, Compiler::StaticType preLoopType) const;
1616

1717
private:
18-
bool variableTypeChangesFromEnd(LLVMVariablePtr *varPtr, LLVMInstruction *loopEnd, Compiler::StaticType preLoopType) const;
18+
bool variableTypeChangesInLoopFromEnd(LLVMVariablePtr *varPtr, LLVMInstruction *loopEnd, Compiler::StaticType preLoopType) const;
1919
bool isLoopStart(LLVMInstruction *ins) const;
2020
bool isLoopEnd(LLVMInstruction *ins) const;
2121
bool isIfStart(LLVMInstruction *ins) const;

test/llvm/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ add_executable(
2020
llvmexecutablecode_test.cpp
2121
llvmcodebuilder_test.cpp
2222
llvminstructionlist_test.cpp
23-
loop_analyzer/variabletypechanges_test.cpp
23+
type_analyzer/variabletypechangesinloop_test.cpp
2424
)
2525

2626
target_link_libraries(

0 commit comments

Comments
 (0)