diff --git a/Makefile b/Makefile index 90af0dd..9f15a6d 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ CC=clang CFLAGS=-g `llvm-config --cflags` LD=clang++ -LDFLAGS=`llvm-config --cxxflags --ldflags --libs core executionengine jit interpreter analysis native bitwriter --system-libs` +LDFLAGS=`llvm-config --cxxflags --ldflags --libs core executionengine mcjit interpreter analysis native bitwriter --system-libs` all: sum diff --git a/sum.c b/sum.c index 7fce959..1f8a2c6 100644 --- a/sum.c +++ b/sum.c @@ -36,8 +36,10 @@ int main(int argc, char const *argv[]) { LLVMExecutionEngineRef engine; error = NULL; - LLVMLinkInJIT(); + LLVMLinkInMCJIT(); LLVMInitializeNativeTarget(); + LLVMInitializeNativeAsmPrinter(); + LLVMInitializeNativeAsmParser(); if (LLVMCreateExecutionEngineForModule(&engine, mod, &error) != 0) { fprintf(stderr, "failed to create execution engine\n"); abort(); @@ -52,15 +54,14 @@ int main(int argc, char const *argv[]) { fprintf(stderr, "usage: %s x y\n", argv[0]); exit(EXIT_FAILURE); } - long long x = strtoll(argv[1], NULL, 10); - long long y = strtoll(argv[2], NULL, 10); + int32_t x = strtoll(argv[1], NULL, 10); + int32_t y = strtoll(argv[2], NULL, 10); - LLVMGenericValueRef args[] = { - LLVMCreateGenericValueOfInt(LLVMInt32Type(), x, 0), - LLVMCreateGenericValueOfInt(LLVMInt32Type(), y, 0) - }; - LLVMGenericValueRef res = LLVMRunFunction(engine, sum, 2, args); - printf("%d\n", (int)LLVMGenericValueToInt(res, 0)); + { + int32_t (*funcPtr) (int32_t, int32_t) + = LLVMGetPointerToGlobal(engine, sum); + printf("%d\n", funcPtr(x,y)); + } // Write out bitcode to file if (LLVMWriteBitcodeToFile(mod, "sum.bc") != 0) {