Skip to content

Commit c261b56

Browse files
committed
LLVMCodeBuilder: Store loop list write instructions
1 parent 0fdcc76 commit c261b56

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/engine/internal/llvm/llvmcodebuilder.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,6 +1597,11 @@ void LLVMCodeBuilder::createListAppend(List *list, CompilerValue *item)
15971597
if (m_listPtrs.find(list) == m_listPtrs.cend())
15981598
m_listPtrs[list] = LLVMListPtr();
15991599

1600+
if (m_loopScope >= 0) {
1601+
auto scope = m_loopScopes[m_loopScope];
1602+
m_listPtrs[list].loopListWrites[scope].push_back(m_instructions.back());
1603+
}
1604+
16001605
m_listInstructions.push_back(m_instructions.back());
16011606
}
16021607

@@ -1609,6 +1614,11 @@ void LLVMCodeBuilder::createListInsert(List *list, CompilerValue *index, Compile
16091614
if (m_listPtrs.find(list) == m_listPtrs.cend())
16101615
m_listPtrs[list] = LLVMListPtr();
16111616

1617+
if (m_loopScope >= 0) {
1618+
auto scope = m_loopScopes[m_loopScope];
1619+
m_listPtrs[list].loopListWrites[scope].push_back(m_instructions.back());
1620+
}
1621+
16121622
m_listInstructions.push_back(m_instructions.back());
16131623
}
16141624

@@ -1621,6 +1631,11 @@ void LLVMCodeBuilder::createListReplace(List *list, CompilerValue *index, Compil
16211631
if (m_listPtrs.find(list) == m_listPtrs.cend())
16221632
m_listPtrs[list] = LLVMListPtr();
16231633

1634+
if (m_loopScope >= 0) {
1635+
auto scope = m_loopScopes[m_loopScope];
1636+
m_listPtrs[list].loopListWrites[scope].push_back(m_instructions.back());
1637+
}
1638+
16241639
m_listInstructions.push_back(m_instructions.back());
16251640
}
16261641

src/engine/internal/llvm/llvmlistptr.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44

55
#include <scratchcpp/compiler.h>
6+
#include <unordered_map>
67

78
namespace llvm
89
{
@@ -14,6 +15,9 @@ class Value;
1415
namespace libscratchcpp
1516
{
1617

18+
class LLVMLoopScope;
19+
class LLVMInstruction;
20+
1721
struct LLVMListPtr
1822
{
1923
llvm::Value *ptr = nullptr;
@@ -22,6 +26,9 @@ struct LLVMListPtr
2226
llvm::Value *allocatedSizePtr = nullptr;
2327
llvm::Value *dataPtrDirty = nullptr;
2428
Compiler::StaticType type = Compiler::StaticType::Unknown;
29+
30+
// Used in build phase to check the type safety of lists in loops
31+
std::unordered_map<std::shared_ptr<LLVMLoopScope>, std::vector<std::shared_ptr<LLVMInstruction>>> loopListWrites; // loop scope, write instructions
2532
};
2633

2734
} // namespace libscratchcpp

0 commit comments

Comments
 (0)