Skip to content

Commit b9e57e4

Browse files
committed
Add LLVMExecutionContext class
1 parent 4fda69d commit b9e57e4

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

src/dev/engine/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ target_sources(scratchcpp
33
executioncontext.cpp
44
executioncontext_p.cpp
55
executioncontext_p.h
6+
internal/llvmexecutioncontext.cpp
7+
internal/llvmexecutioncontext.h
68
)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#include "llvmexecutioncontext.h"
4+
5+
using namespace libscratchcpp;
6+
7+
LLVMExecutionContext::LLVMExecutionContext(Target *target) :
8+
ExecutionContext(target)
9+
{
10+
}
11+
12+
size_t LLVMExecutionContext::pos() const
13+
{
14+
return m_pos;
15+
}
16+
17+
void LLVMExecutionContext::setPos(size_t newPos)
18+
{
19+
m_pos = newPos;
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
3+
#pragma once
4+
5+
#include <scratchcpp/dev/executioncontext.h>
6+
7+
namespace libscratchcpp
8+
{
9+
10+
class LLVMExecutionContext : public ExecutionContext
11+
{
12+
public:
13+
LLVMExecutionContext(Target *target);
14+
15+
size_t pos() const;
16+
void setPos(size_t newPos);
17+
18+
private:
19+
size_t m_pos = 0;
20+
};
21+
22+
} // namespace libscratchcpp

test/dev/llvm/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
add_executable(
2+
llvm_test
3+
llvmexecutioncontext_test.cpp
4+
)
5+
6+
target_link_libraries(
7+
llvm_test
8+
GTest::gtest_main
9+
GTest::gmock_main
10+
scratchcpp
11+
scratchcpp_mocks
12+
)
13+
14+
gtest_discover_tests(llvm_test)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <scratchcpp/target.h>
2+
#include <dev/engine/internal/llvmexecutioncontext.h>
3+
4+
#include "../../common.h"
5+
6+
using namespace libscratchcpp;
7+
8+
TEST(LLVMExecutionContextTest, Constructor)
9+
{
10+
Target target;
11+
LLVMExecutionContext ctx(&target);
12+
ASSERT_EQ(ctx.target(), &target);
13+
}
14+
15+
TEST(LLVMExecutionContextTest, Pos)
16+
{
17+
LLVMExecutionContext ctx(nullptr);
18+
ASSERT_EQ(ctx.pos(), 0);
19+
20+
ctx.setPos(1);
21+
ASSERT_EQ(ctx.pos(), 1);
22+
23+
ctx.setPos(356);
24+
ASSERT_EQ(ctx.pos(), 356);
25+
}

0 commit comments

Comments
 (0)