Skip to content

Commit ea97a92

Browse files
committed
LLVMCodeBuilder: Store loop list write instructions
1 parent 693c464 commit ea97a92

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
@@ -1599,6 +1599,11 @@ void LLVMCodeBuilder::createListAppend(List *list, CompilerValue *item)
15991599
if (m_listPtrs.find(list) == m_listPtrs.cend())
16001600
m_listPtrs[list] = LLVMListPtr();
16011601

1602+
if (m_loopScope >= 0) {
1603+
auto scope = m_loopScopes[m_loopScope];
1604+
m_listPtrs[list].loopListWrites[scope].push_back(m_instructions.back());
1605+
}
1606+
16021607
m_listInstructions.push_back(m_instructions.back());
16031608
}
16041609

@@ -1611,6 +1616,11 @@ void LLVMCodeBuilder::createListInsert(List *list, CompilerValue *index, Compile
16111616
if (m_listPtrs.find(list) == m_listPtrs.cend())
16121617
m_listPtrs[list] = LLVMListPtr();
16131618

1619+
if (m_loopScope >= 0) {
1620+
auto scope = m_loopScopes[m_loopScope];
1621+
m_listPtrs[list].loopListWrites[scope].push_back(m_instructions.back());
1622+
}
1623+
16141624
m_listInstructions.push_back(m_instructions.back());
16151625
}
16161626

@@ -1623,6 +1633,11 @@ void LLVMCodeBuilder::createListReplace(List *list, CompilerValue *index, Compil
16231633
if (m_listPtrs.find(list) == m_listPtrs.cend())
16241634
m_listPtrs[list] = LLVMListPtr();
16251635

1636+
if (m_loopScope >= 0) {
1637+
auto scope = m_loopScopes[m_loopScope];
1638+
m_listPtrs[list].loopListWrites[scope].push_back(m_instructions.back());
1639+
}
1640+
16261641
m_listInstructions.push_back(m_instructions.back());
16271642
}
16281643

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)