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; }
int main(void) { init_environment(); MACHINE *mach = make_machine(); for (int i = 0; i < 23; i++) printf("ins %d: %08x\n", i, factorial_ins[i]); printf("\n"); init_machine(mach); load_memory(factorial_ins, 100, mach, 0); run_machine(mach); free_machine(mach); return 0; }
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; }