static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt) { c->opt = opt; // Get the first package and the builtin package. ast_t* package = ast_child(program); ast_t* builtin = ast_sibling(package); // If we have only one package, we are compiling builtin itself. if(builtin == NULL) builtin = package; c->reach = reach_new(); // The name of the first package is the name of the program. c->filename = package_filename(package); // LLVM context and machine settings. if(c->opt->library || target_is_ilp32(opt->triple)) c->callconv = LLVMCCallConv; else c->callconv = LLVMFastCallConv; if(!c->opt->release || c->opt->library || c->opt->extfun) c->linkage = LLVMExternalLinkage; else c->linkage = LLVMPrivateLinkage; c->context = LLVMContextCreate(); c->machine = make_machine(opt); c->target_data = LLVMGetTargetMachineData(c->machine); // Create a module. c->module = LLVMModuleCreateWithNameInContext(c->filename, c->context); // Set the target triple. LLVMSetTarget(c->module, opt->triple); // Set the data layout. char* layout = LLVMCopyStringRepOfTargetData(c->target_data); LLVMSetDataLayout(c->module, layout); LLVMDisposeMessage(layout); // IR builder. c->builder = LLVMCreateBuilderInContext(c->context); c->di = LLVMNewDIBuilder(c->module); // TODO: what LANG id should be used? c->di_unit = LLVMDIBuilderCreateCompileUnit(c->di, 0x0004, package_filename(package), package_path(package), "ponyc-" PONY_VERSION, c->opt->release); // Empty frame stack. c->frame = NULL; }
/* TargetMachine.t -> DataLayout.t */ CAMLprim value llvm_targetmachine_data_layout(value Machine) { CAMLparam1(Machine); CAMLlocal1(DataLayout); /* LLVMGetTargetMachineData returns a pointer owned by the TargetMachine, so it is impossible to wrap it with llvm_alloc_target_data, which assumes that OCaml owns the pointer. */ LLVMTargetDataRef OrigDataLayout; OrigDataLayout = LLVMGetTargetMachineData(TargetMachine_val(Machine)); char* TargetDataCStr; TargetDataCStr = LLVMCopyStringRepOfTargetData(OrigDataLayout); DataLayout = llvm_alloc_data_layout(LLVMCreateTargetData(TargetDataCStr)); LLVMDisposeMessage(TargetDataCStr); CAMLreturn(DataLayout); }
static void init_module(compile_t* c, ast_t* program, pass_opt_t* opt) { c->opt = opt; // Get the first package and the builtin package. ast_t* package = ast_child(program); ast_t* builtin = ast_sibling(package); // If we have only one package, we are compiling builtin itself. if(builtin == NULL) builtin = package; c->reachable = reach_new(); reach_primitives(c->reachable, opt, builtin); // The name of the first package is the name of the program. c->filename = package_filename(package); // LLVM context and machine settings. c->context = LLVMContextCreate(); c->machine = make_machine(opt); c->target_data = LLVMGetTargetMachineData(c->machine); // Create a module. c->module = LLVMModuleCreateWithNameInContext(c->filename, c->context); // Set the target triple. LLVMSetTarget(c->module, opt->triple); // Set the data layout. char* layout = LLVMCopyStringRepOfTargetData(c->target_data); LLVMSetDataLayout(c->module, layout); LLVMDisposeMessage(layout); // IR builder. c->builder = LLVMCreateBuilderInContext(c->context); // Empty frame stack. c->frame = NULL; }