Skip to content

Commit 5289781

Browse files
committed
LLVMCodeBuilder: Store source instruction in registers
1 parent fabf176 commit 5289781

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

src/engine/internal/llvm/llvmcodebuilder.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ CompilerValue *LLVMCodeBuilder::addFunctionCall(const std::string &functionName,
12181218
reg->isRawValue = true;
12191219
ins->functionReturnReg = reg.get();
12201220
m_instructions.push_back(ins);
1221-
return addReg(reg);
1221+
return addReg(reg, ins);
12221222
}
12231223

12241224
m_instructions.push_back(ins);
@@ -1243,7 +1243,7 @@ CompilerConstant *LLVMCodeBuilder::addConstValue(const Value &value)
12431243
{
12441244
auto constReg = std::make_shared<LLVMConstantRegister>(TYPE_MAP[value.type()], value);
12451245
auto reg = std::reinterpret_pointer_cast<LLVMRegister>(constReg);
1246-
return static_cast<CompilerConstant *>(static_cast<CompilerValue *>(addReg(reg)));
1246+
return static_cast<CompilerConstant *>(static_cast<CompilerValue *>(addReg(reg, nullptr)));
12471247
}
12481248

12491249
CompilerValue *LLVMCodeBuilder::addLoopIndex()
@@ -1269,7 +1269,7 @@ CompilerValue *LLVMCodeBuilder::addVariableValue(Variable *variable)
12691269
ins->functionReturnReg = ret.get();
12701270

12711271
m_instructions.push_back(ins);
1272-
return addReg(ret);
1272+
return addReg(ret, ins);
12731273
}
12741274

12751275
CompilerValue *LLVMCodeBuilder::addListContents(List *list)
@@ -1298,7 +1298,7 @@ CompilerValue *LLVMCodeBuilder::addListItem(List *list, CompilerValue *index)
12981298
ins->functionReturnReg = ret.get();
12991299

13001300
m_instructions.push_back(ins);
1301-
return addReg(ret);
1301+
return addReg(ret, ins);
13021302
}
13031303

13041304
CompilerValue *LLVMCodeBuilder::addListItemIndex(List *list, CompilerValue *item)
@@ -1356,7 +1356,7 @@ CompilerValue *LLVMCodeBuilder::addProcedureArgument(const std::string &name)
13561356
ins->procedureArgIndex = index;
13571357

13581358
m_instructions.push_back(ins);
1359-
return addReg(ret);
1359+
return addReg(ret, ins);
13601360
}
13611361

13621362
CompilerValue *LLVMCodeBuilder::createAdd(CompilerValue *operand1, CompilerValue *operand2)
@@ -2227,7 +2227,7 @@ LLVMRegister *LLVMCodeBuilder::createOp(const LLVMInstruction &ins, Compiler::St
22272227
auto ret = std::make_shared<LLVMRegister>(retType);
22282228
ret->isRawValue = true;
22292229
createdIns->functionReturnReg = ret.get();
2230-
return addReg(ret);
2230+
return addReg(ret, createdIns);
22312231
}
22322232

22332233
return nullptr;

src/engine/internal/llvm/llvmcodebuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class LLVMCodeBuilder : public ICodeBuilder
129129
llvm::Function *getOrCreateFunction(const std::string &name, llvm::FunctionType *type);
130130
void verifyFunction(llvm::Function *func);
131131

132-
LLVMRegister *addReg(std::shared_ptr<LLVMRegister> reg);
132+
LLVMRegister *addReg(std::shared_ptr<LLVMRegister> reg, std::shared_ptr<LLVMInstruction> ins);
133133

134134
llvm::Value *addAlloca(llvm::Type *type);
135135
void freeLater(llvm::Value *value);

src/engine/internal/llvm/llvmregisterbase.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,15 @@ class Value;
1515
namespace libscratchcpp
1616
{
1717

18+
class LLVMInstruction;
19+
1820
struct LLVMRegisterBase
1921
{
2022
virtual const Value &constValue() const = 0;
2123

2224
llvm::Value *value = nullptr;
2325
bool isRawValue = false;
26+
std::shared_ptr<LLVMInstruction> instruction;
2427
};
2528

2629
} // namespace libscratchcpp

0 commit comments

Comments
 (0)