void ac_dump_module(LLVMModuleRef module) { char *str = LLVMPrintModuleToString(module); fprintf(stderr, "%s", str); LLVMDisposeMessage(str); }
static void handle_line(char **tokens, int ntokens) { char *name = tokens[0]; LLVMValueRef param; LLVMValueRef res; LLVMModuleRef M = LLVMModuleCreateWithName(name); LLVMTypeRef I64ty = LLVMInt64Type(); LLVMTypeRef I64Ptrty = LLVMPointerType(I64ty, 0); LLVMTypeRef Fty = LLVMFunctionType(I64ty, &I64Ptrty, 1, 0); LLVMValueRef F = LLVMAddFunction(M, name, Fty); LLVMBuilderRef builder = LLVMCreateBuilder(); LLVMPositionBuilderAtEnd(builder, LLVMAppendBasicBlock(F, "entry")); LLVMGetParams(F, ¶m); LLVMSetValueName(param, "in"); res = build_from_tokens(tokens + 1, ntokens - 1, builder, param); if (res) { char *irstr = LLVMPrintModuleToString(M); puts(irstr); LLVMDisposeMessage(irstr); } LLVMDisposeBuilder(builder); LLVMDisposeModule(M); }
int module_dump(bool Lazy, bool New) { LLVMModuleRef M = load_module(Lazy, New); char *irstr = LLVMPrintModuleToString(M); puts(irstr); LLVMDisposeMessage(irstr); LLVMDisposeModule(M); return 0; }
int main(int argc, char **argv) { int n = argc > 1 ? atol(argv[1]) : 24; LLVMInitializeNativeTarget(); LLVMLinkInInterpreter(); LLVMContextRef Context = LLVMContextCreate(); // Create some module to put our function into it. LLVMModuleRef M = LLVMModuleCreateWithNameInContext("test", Context); // We are about to create the "fib" function: LLVMValueRef FibF = CreateFibFunction(M, Context); // Now we going to create JIT LLVMExecutionEngineRef EE; char * outError; if (LLVMCreateInterpreterForModule(&EE, M, &outError) != 0) { printf("%s\n", outError); return 1; } printf("verifying...\n"); if (LLVMVerifyModule(M, LLVMReturnStatusAction, &outError) != 0) { printf("%s\n", outError); return 1; } printf("OK\n"); printf("We just constructed this LLVM module:\n\n---------\n"); printf("%s\n", LLVMPrintModuleToString(M)); LLVMGenericValueRef Args = LLVMCreateGenericValueOfInt(LLVMInt32TypeInContext(Context), n, 0); LLVMGenericValueRef Result = LLVMRunFunction(EE, FibF, 1, &Args); printf("Result: %llu\n", LLVMGenericValueToInt(Result, 0)); return 0; }