11#include < scratchcpp/target.h>
22#include < scratchcpp/value_functions.h>
3+ #include < scratchcpp/variable.h>
4+ #include < scratchcpp/list.h>
35#include < dev/engine/internal/llvm/llvmexecutablecode.h>
46#include < dev/engine/internal/llvm/llvmexecutioncontext.h>
57#include < llvm/Support/TargetSelect.h>
@@ -18,7 +20,7 @@ class LLVMExecutableCodeTest : public testing::Test
1820 {
1921 m_module = std::make_unique<llvm::Module>(" test" , m_ctx);
2022 m_builder = std::make_unique<llvm::IRBuilder<>>(m_ctx);
21- test_function (nullptr , nullptr ); // force dependency
23+ test_function (nullptr , nullptr , nullptr , nullptr ); // force dependency
2224
2325 llvm::InitializeNativeTarget ();
2426 llvm::InitializeNativeTargetAsmPrinter ();
@@ -29,7 +31,7 @@ class LLVMExecutableCodeTest : public testing::Test
2931
3032 llvm::Function *beginMainFunction ()
3133 {
32- // void *f(Target *, ValueData **, ValueData **)
34+ // void *f(Target *, ValueData **, List **)
3335 llvm::Type *pointerType = llvm::PointerType::get (llvm::Type::getInt8Ty (m_ctx), 0 );
3436 llvm::FunctionType *funcType = llvm::FunctionType::get (pointerType, { pointerType, pointerType, pointerType }, false );
3537 llvm::Function *func = llvm::Function::Create (funcType, llvm::Function::ExternalLinkage, " f" , m_module.get ());
@@ -55,12 +57,12 @@ class LLVMExecutableCodeTest : public testing::Test
5557 void addTestFunction (llvm::Function *mainFunc)
5658 {
5759 auto ptrType = llvm::PointerType::get (llvm::Type::getInt8Ty (m_ctx), 0 );
58- auto func = m_module->getOrInsertFunction (" test_function" , llvm::FunctionType::get (m_builder->getVoidTy (), { ptrType, ptrType }, false ));
60+ auto func = m_module->getOrInsertFunction (" test_function" , llvm::FunctionType::get (m_builder->getVoidTy (), { ptrType, ptrType, ptrType, ptrType }, false ));
5961
6062 llvm::Constant *mockInt = llvm::ConstantInt::get (llvm::Type::getInt64Ty (m_ctx), (uintptr_t )&m_mock, false );
6163 llvm::Constant *mockPtr = llvm::ConstantExpr::getIntToPtr (mockInt, ptrType);
6264
63- m_builder->CreateCall (func, { mockPtr, mainFunc->getArg (0 ) });
65+ m_builder->CreateCall (func, { mockPtr, mainFunc->getArg (0 ), mainFunc-> getArg ( 1 ), mainFunc-> getArg ( 2 ) });
6466 }
6567
6668 void addTestPrintFunction (llvm::Value *arg1, llvm::Value *arg2)
@@ -94,6 +96,9 @@ TEST_F(LLVMExecutableCodeTest, CreateExecutionContext)
9496
9597TEST_F (LLVMExecutableCodeTest, MainFunction)
9698{
99+ m_target.addVariable (std::make_shared<Variable>(" " , " " ));
100+ m_target.addList (std::make_shared<List>(" " , " " ));
101+
97102 auto f = beginMainFunction ();
98103 addTestFunction (f);
99104 endFunction (nullPointer ());
@@ -105,7 +110,7 @@ TEST_F(LLVMExecutableCodeTest, MainFunction)
105110 auto ctx = code.createExecutionContext (&m_target);
106111 ASSERT_FALSE (code.isFinished (ctx.get ()));
107112
108- EXPECT_CALL (m_mock, f (&m_target));
113+ EXPECT_CALL (m_mock, f (&m_target, m_target. variableData (), m_target. listData () ));
109114 code.run (ctx.get ());
110115 ASSERT_TRUE (code.isFinished (ctx.get ()));
111116
@@ -124,11 +129,13 @@ TEST_F(LLVMExecutableCodeTest, MainFunction)
124129
125130 // Test with another context
126131 Target anotherTarget;
132+ anotherTarget.addVariable (std::make_shared<Variable>(" " , " " ));
133+ anotherTarget.addList (std::make_shared<List>(" " , " " ));
127134 auto anotherCtx = code.createExecutionContext (&anotherTarget);
128135 ASSERT_FALSE (code.isFinished (anotherCtx.get ()));
129136 ASSERT_TRUE (code.isFinished (ctx.get ()));
130137
131- EXPECT_CALL (m_mock, f (&anotherTarget));
138+ EXPECT_CALL (m_mock, f (&anotherTarget, anotherTarget. variableData (), anotherTarget. listData () ));
132139 code.run (anotherCtx.get ());
133140 ASSERT_TRUE (code.isFinished (anotherCtx.get ()));
134141 ASSERT_TRUE (code.isFinished (ctx.get ()));
0 commit comments