- void *code;
-
- module = LLVMModuleCreateWithName("test");
-
- test = add_printf_test(module);
-
- if(LLVMVerifyModule(module, LLVMPrintMessageAction, &error)) {
- LLVMDumpModule(module);
- abort();
- }
- LLVMDisposeMessage(error);
-
- provider = LLVMCreateModuleProviderForExistingModule(module);
-#if 0
- if (LLVMCreateJITCompiler(&engine, provider, 1, &error)) {
- fprintf(stderr, "%s\n", error);
- LLVMDisposeMessage(error);
- abort();
- }
-#else
- (void) provider;
- engine = lp_build_engine;
-#endif
-
-#if 0
- pass = LLVMCreatePassManager();
- LLVMAddTargetData(LLVMGetExecutionEngineTargetData(engine), pass);
- /* These are the passes currently listed in llvm-c/Transforms/Scalar.h,
- * but there are more on SVN. */
- LLVMAddConstantPropagationPass(pass);
- LLVMAddInstructionCombiningPass(pass);
- LLVMAddPromoteMemoryToRegisterPass(pass);
- LLVMAddGVNPass(pass);
- LLVMAddCFGSimplificationPass(pass);
- LLVMRunPassManager(pass, module);
-#else
- (void)pass;
-#endif
-
- code = LLVMGetPointerToGlobal(engine, test);
- test_printf = (test_printf_t)pointer_to_func(code);
-
- memset(unpacked, 0, sizeof unpacked);
- packed = 0;
-
-
- // LLVMDumpModule(module);
-
- test_printf(0);
-
- LLVMFreeMachineCodeForFunction(engine, test);
-
- LLVMDisposeExecutionEngine(engine);
- if(pass)
- LLVMDisposePassManager(pass);
+
+ gallivm = gallivm_create("test_module", LLVMGetGlobalContext());
+
+ test = add_printf_test(gallivm);
+
+ gallivm_compile_module(gallivm);
+
+ test_printf_func = (test_printf_t) gallivm_jit_function(gallivm, test);
+
+ gallivm_free_ir(gallivm);
+
+ test_printf_func(0);
+
+ gallivm_destroy(gallivm);