コード例 #1
0
/* llmodule -> ExecutionEngine.t */
CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleRef M) {
  LLVMExecutionEngineRef Interp;
  char *Error;
  if (LLVMCreateExecutionEngineForModule(&Interp, M, &Error))
    llvm_raise(*caml_named_value("Llvm_executionengine.Error"), Error);
  return Interp;
}
コード例 #2
0
ファイル: sum.c プロジェクト: EarlGray/language-incubator
int main(int argc, char const *argv[]) {
    LLVMModuleRef mod = LLVMModuleCreateWithName("sum");

    LLVMTypeRef param_types[] = { LLVMInt32Type(), LLVMInt32Type() };
    LLVMTypeRef ret_type = LLVMFunctionType(LLVMInt32Type(), /* ret type */
                                            param_types, /* arg types */
                                            2, /* arg count */
                                            0 /* is variadic */);
    LLVMValueRef sum = LLVMAddFunction(mod, "sum", ret_type);

    LLVMBasicBlockRef entry = LLVMAppendBasicBlock(sum, "entry");
    
    LLVMBuilderRef builder = LLVMCreateBuilder();
    LLVMPositionBuilderAtEnd(builder, entry);
    LLVMValueRef tmp = LLVMBuildAdd(builder, 
                            LLVMGetParam(sum, 0), 
                            LLVMGetParam(sum, 1), "tmp");
    LLVMBuildRet(builder, tmp);

    char *error = NULL;
    LLVMVerifyModule(mod, LLVMAbortProcessAction, &error);
    LLVMDisposeMessage(error);

    LLVMExecutionEngineRef engine;
    error = NULL;
    LLVMLinkInJIT();
    LLVMInitializeNativeTarget();
    if (LLVMCreateExecutionEngineForModule(&engine, mod, &error) != 0) {
        fprintf(stderr, "failed to create execution engine\n");
        abort();
    }
    if (error) {
        fprintf(stderr, "error: %s\n", error);
        LLVMDisposeMessage(error);
        exit(EXIT_FAILURE);
    }

    if (argc < 3) {
        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);

    LLVMGenericValueRef args[] = {
        LLVMCreateGenericValueOfInt(LLVMInt32Type(), x, 0),
        LLVMCreateGenericValueOfInt(LLVMInt32Type(), y, 0),
    };
    LLVMGenericValueRef res = LLVMRunFunction(engine, sum,  2, args);
    printf("%d\n", (int)LLVMGenericValueToInt(res, 0));

    // write bitcode to file
    if (LLVMWriteBitcodeToFile(mod, "sum.bc") != 0) {
        fprintf(stderr, "error writing bitcode to file\n");
    }

    LLVMDisposeBuilder(builder);
    LLVMDisposeExecutionEngine(engine);
}
コード例 #3
0
/* llmodule -> ExecutionEngine.t */
CAMLprim LLVMExecutionEngineRef llvm_ee_create(LLVMModuleRef M) {
  LLVMExecutionEngineRef Interp;
  char *Error;
  if (LLVMCreateExecutionEngineForModule(&Interp, M, &Error))
    llvm_raise(llvm_ee_error_exn, Error);
  return Interp;
}
コード例 #4
0
ファイル: ExecutionEngine_wrap.c プロジェクト: hardvain/jllvm
SWIGEXPORT jint JNICALL Java_org_jllvm_bindings_ExecutionEngineJNI_LLVMCreateExecutionEngineForModule(JNIEnv *jenv, jclass jcls, jlong jarg1, jlong jarg2, jlong jarg3) {
  jint jresult = 0 ;
  LLVMExecutionEngineRef *arg1 = (LLVMExecutionEngineRef *) 0 ;
  LLVMModuleRef arg2 = (LLVMModuleRef) 0 ;
  char **arg3 = (char **) 0 ;
  LLVMBool result;
  
  (void)jenv;
  (void)jcls;
  arg1 = *(LLVMExecutionEngineRef **)&jarg1; 
  arg2 = *(LLVMModuleRef *)&jarg2; 
  arg3 = *(char ***)&jarg3; 
  result = (LLVMBool)LLVMCreateExecutionEngineForModule(arg1,arg2,arg3);
  jresult = (jint)result; 
  return jresult;
}
コード例 #5
0
ファイル: jit.c プロジェクト: a4a881d4/nvc
static void jit_init_llvm(const char *path)
{
   char *error;
   LLVMMemoryBufferRef buf;
   if (LLVMCreateMemoryBufferWithContentsOfFile(path, &buf, &error))
      fatal("error reading bitcode from %s: %s", path, error);

   if (LLVMParseBitcode(buf, &module, &error))
      fatal("error parsing bitcode: %s", error);

   LLVMDisposeMemoryBuffer(buf);

   LLVMInitializeNativeTarget();
   LLVMLinkInJIT();

   if (LLVMCreateExecutionEngineForModule(&exec_engine, module, &error))
      fatal("error creating execution engine: %s", error);
}