Skip to content

Commit 359afc1

Browse files
committed
Add target to LLVMCodeBuilder
1 parent d884813 commit 359afc1

File tree

9 files changed

+13
-10
lines changed

9 files changed

+13
-10
lines changed

src/dev/engine/compiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::shared_ptr<libscratchcpp::Block> Compiler::block() const
3838
/*! Compiles the script starting with the given block. */
3939
std::shared_ptr<ExecutableCode> Compiler::compile(std::shared_ptr<Block> startBlock)
4040
{
41-
impl->builder = impl->builderFactory->create(startBlock->id(), false);
41+
impl->builder = impl->builderFactory->create(impl->target, startBlock->id(), false);
4242
impl->substackTree.clear();
4343
impl->substackHit = false;
4444
impl->warp = false;

src/dev/engine/internal/codebuilderfactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ std::shared_ptr<CodeBuilderFactory> CodeBuilderFactory::instance()
1212
return m_instance;
1313
}
1414

15-
std::shared_ptr<ICodeBuilder> CodeBuilderFactory::create(const std::string &id, bool warp) const
15+
std::shared_ptr<ICodeBuilder> CodeBuilderFactory::create(Target *target, const std::string &id, bool warp) const
1616
{
17-
return std::make_shared<LLVMCodeBuilder>(id, warp);
17+
return std::make_shared<LLVMCodeBuilder>(target, id, warp);
1818
}

src/dev/engine/internal/codebuilderfactory.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class CodeBuilderFactory : public ICodeBuilderFactory
1111
{
1212
public:
1313
static std::shared_ptr<CodeBuilderFactory> instance();
14-
std::shared_ptr<ICodeBuilder> create(const std::string &id, bool warp) const override;
14+
std::shared_ptr<ICodeBuilder> create(Target *target, const std::string &id, bool warp) const override;
1515

1616
private:
1717
static std::shared_ptr<CodeBuilderFactory> m_instance;

src/dev/engine/internal/icodebuilderfactory.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ namespace libscratchcpp
88
{
99

1010
class ICodeBuilder;
11+
class Target;
1112

1213
class ICodeBuilderFactory
1314
{
1415
public:
1516
virtual ~ICodeBuilderFactory() { }
1617

17-
virtual std::shared_ptr<ICodeBuilder> create(const std::string &id, bool warp) const = 0;
18+
virtual std::shared_ptr<ICodeBuilder> create(Target *target, const std::string &id, bool warp) const = 0;
1819
};
1920

2021
} // namespace libscratchcpp

src/dev/engine/internal/llvmcodebuilder.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ using namespace libscratchcpp;
1313
static std::unordered_map<ValueType, Compiler::StaticType>
1414
TYPE_MAP = { { ValueType::Number, Compiler::StaticType::Number }, { ValueType::Bool, Compiler::StaticType::Bool }, { ValueType::String, Compiler::StaticType::String } };
1515

16-
LLVMCodeBuilder::LLVMCodeBuilder(const std::string &id, bool warp) :
16+
LLVMCodeBuilder::LLVMCodeBuilder(Target *target, const std::string &id, bool warp) :
17+
m_target(target),
1718
m_id(id),
1819
m_module(std::make_unique<llvm::Module>(id, m_ctx)),
1920
m_builder(m_ctx),

src/dev/engine/internal/llvmcodebuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Target;
1717
class LLVMCodeBuilder : public ICodeBuilder
1818
{
1919
public:
20-
LLVMCodeBuilder(const std::string &id, bool warp);
20+
LLVMCodeBuilder(Target *target, const std::string &id, bool warp);
2121

2222
std::shared_ptr<ExecutableCode> finalize() override;
2323

test/dev/compiler/compiler_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class CompilerTest : public testing::Test
4141
{
4242
ASSERT_EQ(compiler.block(), nullptr);
4343
// TODO: Test warp
44-
EXPECT_CALL(m_builderFactory, create(block->id(), false)).WillOnce(Return(m_builder));
44+
EXPECT_CALL(m_builderFactory, create(compiler.target(), block->id(), false)).WillOnce(Return(m_builder));
4545
EXPECT_CALL(*m_builder, finalize()).WillOnce(Return(m_code));
4646
ASSERT_EQ(compiler.compile(block), m_code);
4747
ASSERT_EQ(compiler.block(), nullptr);

test/dev/llvm/llvmcodebuilder_test.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class LLVMCodeBuilderTest : public testing::Test
1919
test_function(nullptr, nullptr); // force dependency
2020
}
2121

22-
void createBuilder(bool warp) { m_builder = std::make_unique<LLVMCodeBuilder>("test", warp); }
22+
void createBuilder(Target *target, bool warp) { m_builder = std::make_unique<LLVMCodeBuilder>(target, "test", warp); }
23+
void createBuilder(bool warp) { createBuilder(nullptr, warp); }
2324

2425
void callConstFuncForType(ValueType type)
2526
{

test/mocks/codebuilderfactorymock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ using namespace libscratchcpp;
88
class CodeBuilderFactoryMock : public ICodeBuilderFactory
99
{
1010
public:
11-
MOCK_METHOD(std::shared_ptr<ICodeBuilder>, create, (const std::string &, bool), (const, override));
11+
MOCK_METHOD(std::shared_ptr<ICodeBuilder>, create, (Target *, const std::string &, bool), (const, override));
1212
};

0 commit comments

Comments
 (0)