Skip to content

Commit 35b6ca5

Browse files
committed
Add stop without sync instruction
1 parent 8e43154 commit 35b6ca5

File tree

8 files changed

+23
-1
lines changed

8 files changed

+23
-1
lines changed

src/engine/internal/icodebuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ICodeBuilder
9999
virtual void yield() = 0;
100100

101101
virtual void createStop() = 0;
102+
virtual void createStopWithoutSync() = 0;
102103

103104
virtual void createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args) = 0;
104105
};

src/engine/internal/llvm/instructions/control.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,12 @@ LLVMInstruction *Control::buildEndLoop(LLVMInstruction *ins)
336336
}
337337

338338
LLVMInstruction *Control::buildStop(LLVMInstruction *ins)
339+
{
340+
m_utils.syncVariables();
341+
return buildStopWithoutSync(ins);
342+
}
343+
344+
LLVMInstruction *Control::buildStopWithoutSync(LLVMInstruction *ins)
339345
{
340346
m_utils.freeScopeHeap();
341347
m_builder.CreateBr(m_utils.endBranch());

src/engine/internal/llvm/instructions/control.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Control : public InstructionGroup
2727
LLVMInstruction *buildBeginLoopCondition(LLVMInstruction *ins);
2828
LLVMInstruction *buildEndLoop(LLVMInstruction *ins);
2929
LLVMInstruction *buildStop(LLVMInstruction *ins);
30+
LLVMInstruction *buildStopWithoutSync(LLVMInstruction *ins);
3031
};
3132

3233
} // namespace libscratchcpp::llvmins

src/engine/internal/llvm/llvmbuildutils.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,15 @@ void LLVMBuildUtils::end(LLVMInstruction *lastInstruction, LLVMRegister *lastCon
108108
assert(m_stringHeap.size() == 1);
109109
freeScopeHeap();
110110

111+
// Sync
112+
llvm::BasicBlock *syncBranch = llvm::BasicBlock::Create(m_llvmCtx, "sync", m_function);
113+
m_builder.CreateBr(syncBranch);
114+
115+
m_builder.SetInsertPoint(syncBranch);
116+
syncVariables();
111117
m_builder.CreateBr(m_endBranch);
112118

113119
m_builder.SetInsertPoint(m_endBranch);
114-
syncVariables();
115120

116121
// End the script function
117122
llvm::PointerType *pointerType = llvm::PointerType::get(llvm::Type::getInt8Ty(m_llvmCtx), 0);

src/engine/internal/llvm/llvmcodebuilder.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,12 @@ void LLVMCodeBuilder::createStop()
552552
m_instructions.addInstruction(ins);
553553
}
554554

555+
void LLVMCodeBuilder::createStopWithoutSync()
556+
{
557+
auto ins = std::make_shared<LLVMInstruction>(LLVMInstruction::Type::StopWithoutSync, m_loopCondition);
558+
m_instructions.addInstruction(ins);
559+
}
560+
555561
void LLVMCodeBuilder::createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args)
556562
{
557563
assert(prototype);

src/engine/internal/llvm/llvmcodebuilder.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class LLVMCodeBuilder : public ICodeBuilder
112112
void yield() override;
113113

114114
void createStop() override;
115+
void createStopWithoutSync() override;
115116

116117
void createProcedureCall(BlockPrototype *prototype, const Compiler::Args &args) override;
117118

src/engine/internal/llvm/llvminstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ struct LLVMInstruction
7676
BeginLoopCondition,
7777
EndLoop,
7878
Stop,
79+
StopWithoutSync,
7980
CallProcedure,
8081
ProcedureArg
8182
};

test/mocks/codebuildermock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class CodeBuilderMock : public ICodeBuilder
8888
MOCK_METHOD(void, yield, (), (override));
8989

9090
MOCK_METHOD(void, createStop, (), (override));
91+
MOCK_METHOD(void, createStopWithoutSync, (), (override));
9192

9293
MOCK_METHOD(void, createProcedureCall, (BlockPrototype *, const Compiler::Args &), (override));
9394
};

0 commit comments

Comments
 (0)