| 237 | } |
| 238 | |
| 239 | void LlvmCodeGenCacheTest::AddLlvmCodegenDouble( |
| 240 | LlvmCodeGen* codegen, string* module_id = nullptr, bool doFinalizeModule = true) { |
| 241 | ASSERT_TRUE(codegen != nullptr); |
| 242 | LlvmCodeGen::FnPrototype prototype(codegen, "Double", codegen->i32_type()); |
| 243 | prototype.AddArgument(LlvmCodeGen::NamedVariable("n", codegen->i32_type())); |
| 244 | LlvmBuilder builder(codegen->context()); |
| 245 | llvm::Value* args[1]; |
| 246 | llvm::Function* fn = prototype.GeneratePrototype(&builder, args); |
| 247 | llvm::Value* mul = codegen->GetI32Constant(2); |
| 248 | args[0] = builder.CreateMul(args[0], mul); |
| 249 | builder.CreateRet(args[0]); |
| 250 | fn = codegen->FinalizeFunction(fn); |
| 251 | ASSERT_TRUE(fn != nullptr); |
| 252 | CodegenFnPtr<TestDouble> jitted_fn; |
| 253 | AddFunctionToJit(codegen, fn, &jitted_fn); |
| 254 | if (doFinalizeModule) { |
| 255 | ASSERT_OK(FinalizeModule(codegen, module_id)); |
| 256 | ASSERT_TRUE(jitted_fn.load() != nullptr); |
| 257 | TestEcho test_fn = jitted_fn.load(); |
| 258 | ASSERT_EQ(test_fn(1), 2); |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | /// Test the basic function of a codegen cache. |
| 263 | void LlvmCodeGenCacheTest::TestBasicFunction(TCodeGenCacheMode::type mode) { |
nothing calls this directly
no test coverage detected