Skip to content

Commit

Permalink
LLVMCodeBuilder: Store loop variable write instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
adazem009 committed Jan 16, 2025
1 parent a220400 commit 1b0067d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/engine/internal/llvm/llvmcodebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,11 @@ void LLVMCodeBuilder::createVariableWrite(Variable *variable, CompilerValue *val
if (m_variablePtrs.find(variable) == m_variablePtrs.cend())
m_variablePtrs[variable] = LLVMVariablePtr();

if (m_loopScope >= 0) {
auto scope = m_loopScopes[m_loopScope];
m_variablePtrs[variable].loopVariableWrites[scope].push_back(m_instructions.back());
}

m_variableInstructions.push_back(m_instructions.back());
}

Expand Down
7 changes: 7 additions & 0 deletions src/engine/internal/llvm/llvmvariableptr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <scratchcpp/compiler.h>
#include <unordered_map>

namespace llvm
{
Expand All @@ -14,13 +15,19 @@ class Value;
namespace libscratchcpp
{

class LLVMLoopScope;
class LLVMInstruction;

struct LLVMVariablePtr
{
llvm::Value *stackPtr = nullptr;
llvm::Value *heapPtr = nullptr;
Compiler::StaticType type = Compiler::StaticType::Unknown;
bool onStack = false;
bool changed = false;

// Used in build phase to check the type safety of variables in loops
std::unordered_map<std::shared_ptr<LLVMLoopScope>, std::vector<std::shared_ptr<LLVMInstruction>>> loopVariableWrites; // loop scope, write instructions
};

} // namespace libscratchcpp

0 comments on commit 1b0067d

Please sign in to comment.