int main(int argc, char** argv) { // Should ParseCommandLineOptions be able to accept a const argv? llvm::cl::ParseCommandLineOptions(argc, argv, "ploy compiler\n"); const char* file_location = InputFile.c_str(); symbol_table* tbl = sym_tbl = init_symbol_table(); init_symbols(tbl); pointer ret = parse_file_to_tree(file_location, tbl); if(!ret) return 1; materialize_includes(&ret, tbl); ploy_do_compile(ret, tbl); type_map type_define_map; transform_tree_gen_typedef(ret, tbl, &type_define_map); transform_tree_gen_typeinfo(ret, tbl, &type_define_map); compiler* compile = init_compiler(tbl); compiler_compile_expression(compile, ret, EntryFunc.c_str()); compiler_print_module(compile); compiler_write_asm_file(compile, OutputFile.c_str()); destroy_compiler(compile); destroy_symbol_table(tbl); return 0; }
/********************************************//** * * This is the main method which will start the compiler. * 1) Check if the file name contains .ps, if not it will exit. * 2) Do the first Transition. * 3) Do the second transition. * 4) Check for errors, if errors exist it will print them and exit the program * before writing the files. * 5) Generate the required files. * ***********************************************/ int main(int argc, char *argv[]) { Compiler *compiler = NULL; int curFileIdx = 1; if (argc == 1) { printf("No input files to compile!\n"); exit(0); } else { while (--argc) { if (is_valid_filename(argv[curFileIdx]) == FALSE) exit(0); init_compiler(&compiler, BASE_OFFSET, argv[curFileIdx]); first_transition(compiler); second_transition(compiler); if (check_errors(compiler)) { //printf("errors\n"); print_errors(compiler); exit(0); } else generate_files(compiler); free(compiler); curFileIdx++; } } printf("Compilation finished successfully.\n"); return 0; }
HRESULT compile_subscript_stat(parser_ctx_t *parser, statement_t *stat, BOOL from_eval, unsigned *ret_off) { unsigned off; HRESULT hres; TRACE("\n"); hres = init_compiler(parser); if(FAILED(hres)) return hres; off = parser->compiler->code_off; if(stat->next) hres = compile_block_statement(parser->compiler, stat); else hres = compile_statement(parser->compiler, NULL, stat); if(FAILED(hres)) return hres; resolve_labels(parser->compiler, off); if(!from_eval && !push_instr(parser->compiler, OP_pop)) return E_OUTOFMEMORY; if(!push_instr(parser->compiler, OP_ret)) return E_OUTOFMEMORY; if(TRACE_ON(jscript_disas)) dump_code(parser->compiler, off); *ret_off = off; return S_OK; }
int main(int argc, char* argv[]) { init_symbol_table(); init_builtin_types(); init_global_env(); init_singleton_objects(); init_primitive_procs(); struct vm_context *global_ctx = make_vm_context(NULL, NULL, global_env); INC_REF(&global_ctx->obj); struct vm_context **pctx = &global_ctx; struct object *value; value = load("prelude.scm", pctx); YIELD_OBJ(value); init_compiler(); value = load("stage2.scm", pctx); YIELD_OBJ(value); struct vm_context *repl_ctx; repl_ctx = make_vm_context(NULL, make_stack(1024), make_environment(global_env)); INC_REF(&repl_ctx->obj); pctx = &repl_ctx; struct object *ret = env_lookup(global_env, "initial-repl"); assert(ret->type->code == PROCEDURE_TYPE); struct procedure *repl = container_of(ret, struct procedure, obj); apply_and_run(repl, NIL, pctx); return 0; }
cell * prepare_dictionary(int *argcp, char *(*argvp[])) { u_char *origin; u_char *here; u_char *xlimit; int dict_size; u_char *extension; char *dictionary_file = ""; // Allocate space for the Forth dictionary and read its initial contents origin = aln_alloc(MAXDICT, variables); xlimit = &origin[MAXDICT]; if(*argcp < 2 || (extension = strrchr((*argvp)[1],'.')) == NULL || strcmp(extension, ".dic") != 0 ) { dictionary_file = is_readable("app.dic") ? "app.dic" : DEFAULT_EXE; } else { dictionary_file = (*argvp)[1]; *argcp -= 1; *argvp += 1; } dict_size = read_dictionary(dictionary_file, origin, variables); here = &origin[dict_size]; init_compiler(origin, xlimit, 0xfffe, here, xlimit, variables); return variables; }
// dictmax is ignored because the dictionary is defined statically cell * prepare_builtin_dictionary(int dictmax) { u_char *here; here = dictionary + builtin_hdr.dsize; init_compiler(dictionary, dictionary+MAXDICT, 0xfffe, here, dictionary + MAXDICT, (cell *)variables); return (cell *)variables; }
ZEND_API void zend_activate(void) /* {{{ */ { #ifdef ZTS virtual_cwd_activate(); #endif gc_reset(); init_compiler(); init_executor(); startup_scanner(); }
static void tex_1d_swizzle(struct test_result *result) { struct r300_fragment_program_compiler c; memset(&c, 0, sizeof(c)); init_compiler(&c.Base, RC_FRAGMENT_PROGRAM, 0, 0); c.AllocateHwInputs = dummy_allocate_hw_inputs; test_runner_rc_regalloc(result, &c.Base, "regalloc_tex_1d_swizzle.test"); }
int main(int argc, char *argv[]) { FILE *fp; yyscan_t yyscanner; M1_compiler comp; if (argc <= 1) { fprintf(stderr, "Usage: m1 <file>\n"); exit(EXIT_FAILURE); } fp = fopen(argv[1], "r"); if (fp == NULL) { fprintf(stderr, "Could not open file\n"); exit(EXIT_FAILURE); } /* set up compiler */ init_compiler(&comp); /* set up lexer and parser */ yylex_init(&yyscanner); yyset_extra(&comp, yyscanner); yyset_in(fp, yyscanner); comp.yyscanner = yyscanner; /* yyscanner has a pointer to comp, and vice versa. */ yyparse(yyscanner, &comp); fprintf(stderr, "parsing done\n"); if (comp.errors == 0) { assert(intstack_isempty(comp.breakstack) != 0); assert(intstack_isempty(comp.continuestack) != 0); check(&comp, comp.ast); /* need to finish */ //if (comp.errors == 0) { fprintf(stderr, "generating code...\n"); gencode(&comp, comp.ast); } } fclose(fp); fprintf(stderr, "compilation done\n"); return 0; }
int main(int argc, char **argv) { extern void init_dictionary(cell *up); u_char *origin; if (argc != 3) { fprintf(stderr, "usage: meta input-file-name output-file-name\n"); exit(1); } infile = argv[1]; outfile = argv[2]; origin = aln_alloc(MAXDICT, variables); *(token_t *)origin = 0; init_compiler(origin, origin+MAXDICT, 0xfffe, origin, origin+MAXDICT, variables); init_dictionary(variables); return 0; }
int main(int argc, char *argv[]) { Cell* expr = NULL; char* in_line = malloc(BUFSZ); char* in_buffer = malloc(64*BUFSZ); char* out_buf = malloc(BUFSZ); char* res; int in_offset = 0; int parens = 0; size_t len = 0; int i; int in_fd = 0; FILE* in_f; init_compiler(); filesystems_init(); #ifdef DEV_SDL2 void dev_sdl2_init(); dev_sdl2_init(); #endif #ifdef DEV_SDL void dev_sdl_init(); dev_sdl_init(); #endif #ifdef DEV_LINUXFB void mount_linux_fbfs(); mount_linux_fbfs(); #endif #ifdef DEV_POSIXFS void mount_posixfs(); mount_posixfs(); #endif #ifdef DEV_BIOS void mount_bios(); mount_bios(); #endif #ifdef DEV_CONSOLEKEYS void mount_consolekeys(); mount_consolekeys(); #endif #ifdef __AMIGA mount_amiga(); #endif if (argc==2) { in_fd = open(argv[1],O_RDONLY); in_f = fdopen(in_fd,"r"); if (!in_f) in_f = stdin; } else { in_f = stdin; } while (1) { if (in_f == stdin) printf("sledge> "); expr = NULL; len = 0; res = fgets(in_line, BUFSZ, in_f); if (res) { len = strlen(in_line); } //printf("line: (%d) |%s|\r\n",len,in_line); if (len>0) { // recognize parens for (i=0; i<len; i++) { if (in_line[i] == ';') break; if (in_line[i] == '(') { parens++; } else if (in_line[i] == ')') { parens--; } } strncpy(in_buffer+in_offset, in_line, i); in_buffer[in_offset+i]='\n'; in_buffer[in_offset+i+1]=0; if (parens>0) { if (in_f == stdin) printf("...\r\n"); in_offset+=i; } else { in_offset=0; if (len>1) { expr = (Cell*)read_string(in_buffer); } else { //printf("\r\n"); } } } if (feof(in_f) || len==0) { if (in_f!=stdin) close(in_fd); in_f = stdin; in_fd = 0; in_offset=0; if (feof(stdin)) { exit(0); } } if (expr) { Cell* res; int success = compile_for_platform(expr, &res); if (success) { if (in_f == stdin) { if (!res) { printf("invalid cell (%p)\r\n",res); } else { lisp_write(res, out_buf, 1024); printf("%s\r\n",out_buf); } } } else { printf("<compilation failed>\n"); res = NULL; } } } return 0; }
/** \brief Load all the initial dictionary words. */ void init_dictionary(int dictsize) { init_compiler(dictsize); memory_words(); compile_primitives(); compile_core_constants(); core_words(); core_extension_words(); compile_dictionary_words(); controlflow_words(); more_core_words(); compile_double(); string_words(); exception_words(); file_words(); format_words(); compile_stack_words(); implementation_words(); vocabulary_words(); interpreter_words(); platform_words(); /* FIX - NEED TO DO THESE */ // Primitive( "d<", &lesser ); /* ( d1 d2 -- f ) */ // Primitive( "d>", &lesser ); /* ( d1 d2 -- f ) */ // Primitive( "u*", &um_star ); /* ( x y -- x*y ) */ // Primitive( "du*", &um_star ); /* ( x y -- x*y ) */ // Primitive( "du/mod", &um_star ); /* ( x y -- x*y ) */ // Primitive( "du<", &um_star ); /* ( x y -- x*y ) */ // Primitive( "m+", &um_star ); /* ( x y -- x*y ) */ // Primitive( "m-", &um_star ); /* ( x y -- x*y ) */ // Primitive( "m*", &um_star ); /* ( x y -- x*y ) */ // Primitive( "m*/", &um_star ); /* ( x y -- x*y ) */ // Primitive( "m/", &um_star ); /* ( x y -- x*y ) */ // Primitive( "m/mod", &um_star ); /* ( x y -- x*y ) */ /* FIX - NEED TO DO THESE */ /* FIX - these two words are no longer used - why are they here ?? */ // Primitive( "um*", &um_star ); /* ( x y -- x*y ) */ // Colon( "udm*" ); /* ( d.lo d.hi n -- d.lo' d.hi' ) */ // c("tuck"); c("um*"); c("drop"); c("-rot"); c("um*"); // c("rot"); c("+"); End(); Colon( ".version" ); DotQuote("Portable ANS Forth - [email protected]"); c("cr"); End(); Colon( "rstrace" ); DotQuote("( R: "); c("rp@"); c("rp0"); c("@"); Do(); c("i"); c("."); c("space"); c("/cell"); PlusLoop(); DotQuote(" )"); c("cr"); End(); Variable( "argument-hook" ); /* To( Tick("ndrop"), "argument-hook" ); */ ACF x = find("unnest"); To( (Cell)x, "argument-hook" ); Colon( "cold" ); c(".version"); c("cold-chain"); /* included may be replaced with path-included which reads FORTH_PATH environment variable to look in selected directories */ c("debug"); c("@"); If(); DotQuote("Loading Forth files..."); Then(); /* StringLiteral("base.fth"); c("included"); */ DotQuote("loading base.fth"); c("cr"); StringLiteral("base.fth"); Tick("included"); c("catch"); c("?aborted"); If(); DotQuote("Failed to load."); c("cr"); Then(); c("debug"); c("@"); If(); DotQuote("done."); c("cr"); Then(); c("hex"); #if 0 c("argument-hook"); c("@"); Tick("execute"); c("catch"); c("?aborted"); If(); DotQuote("argument-hook failed"); c("cr"); Then(); #endif c("read-eval-loop"); End(); Colon( "warm" ); DotQuote( "Warm Started." ); c("cr"); c("rstrace"); c("quit"); End(); /* header */ Colon( "name," ); c("dup"); c("1+"); c("talign"); c("allot"); c("dup"); c("here"); c("1-"); c("c!"); c("here"); c("1-"); c("over"); c("-"); c("swap"); c("cmove"); End(); Colon( "header" ); c("name,"); c("link"); c("do-create"); c(","); End(); Colon( "create" ); c("parse-word"); c("header"); End(); Colon( "codefield" ); /* ( codefield -- ) */ c("lastacf"); c("!"); End(); Colon( ":" ); c("create"); c("hide"); c("do-colon"); c("codefield"); c("]"); End(); Colon( ";" ); c("compile"); c("unnest"); c("["); c("reveal"); End(); immediate(); }
int main (int argc, char *argv[]) # endif { int column_num; long field_len; int line_num; char *msg_name; int save_statement_number = 0; # if (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) double end_time; double start_time; /* char time[20]; */ double total_cpu_time; struct rusage ru; # else # if !defined(_HOST_OS_UNICOS) long end_clock; # endif float end_time; float start_time; float total_cpu_time; # endif # if defined(_HOST_OS_UNICOS) && defined(_DEBUG) lowmem_check(); # endif # if defined(_TARGET32) && defined(_DEBUG) setbuf(stdout, NULL); setbuf(stderr, NULL); # endif # if defined(_HOST_OS_UNICOS) /* Lots of start up - ignore first call. See the comment block that */ /* precedes procedure cif_summary_rec in fecif.c for a discussion of the */ /* timing methods used by the different platforms. */ SECOND(&start_time); /* M_LOWFIT will eventually be in malloc.h. */ /* When it is remove this definition. */ # define M_LOWFIT 0107 /* Use lowest-fit algorithm for allocation. */ mallopt(M_LOWFIT, 1); # elif defined(_HOST_OS_MAX) /* Use clock() on MPP's (in particular T3E's) because at the time this */ /* change was made, neither SECOND() nor SECONDR() worked on T3E's. */ /* LRR 4 Mar 1997 */ clock(); start_time = 0; /* M_LOWFIT will eventually be in malloc.h. */ /* When it is remove this definition. */ # define M_LOWFIT 0107 /* Use lowest-fit algorithm for allocation. */ mallopt(M_LOWFIT, 1); # elif defined(_HOST_OS_SOLARIS) /* clock() is only semi-useful on a Sun because it rolls over in just over */ /* 2147 seconds (about 36 minutes). So on a Sun, we use clock() and */ /* time() both. If elapsed time <= 2147 seconds, the accounting info will */ /* show milliseconds (from clock()), else it will show seconds (because */ /* that is the accuracy of time()). This resolution should be good enough */ /* for a compilation exceeding 36 minutes. */ start_time = (float) time(NULL); clock(); # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) getrusage (RUSAGE_SELF, &ru); start_time = (double) ru.ru_utime.tv_sec + (double) ru.ru_utime.tv_usec * 1e-6 + (double) ru.ru_stime.tv_sec + (double) ru.ru_stime.tv_usec * 1e-6; # else start_time = 0; # endif comp_phase = Pass1_Parsing; stmt_start_line = 1; /* Set in case mem problems */ init_compiler(argc, argv); /* init and process cmd line */ if (on_off_flags.preprocess_only) { goto PREPROCESS_ONLY_SKIP; } stmt_start_line = 0; while (LA_CH_CLASS != Ch_Class_EOF) { comp_phase = Pass1_Parsing; num_prog_unit_errors = 0; /* Accum errs for pgm unit */ OUTPUT_PASS_HEADER(Syntax_Pass); if (save_statement_number != 0) { statement_number = save_statement_number; } parse_prog_unit(); save_statement_number = statement_number; if (LA_CH_CLASS == Ch_Class_EOF) { issue_deferred_msgs(); } /* get current field length and save largest value */ field_len = (long) sbrk(0); # if defined(_HOST_OS_MAX) field_len &= (1 << 32) - 1; # endif if (field_len > max_field_len) { /* Max set in init_compiler */ max_field_len = field_len; /* Track max usage */ } PRINT_IR_TBL; /* If -u ir and DEBUG compiler, print ir. */ OUTPUT_PASS_HEADER(Semantics_Pass); semantics_pass_driver(); /* PASS 2 */ if (SCP_IN_ERR(curr_scp_idx)) { some_scp_in_err = TRUE; } PRINT_ALL_SYM_TBLS; /* If debug print -u options */ PRINT_FORTRAN_OUT; /* Print ir in a fortran format */ line_num = SH_GLB_LINE(SCP_LAST_SH_IDX(curr_scp_idx)); column_num = SH_COL_NUM(SCP_LAST_SH_IDX(curr_scp_idx)); if (num_prog_unit_errors == 0) { if (opt_flags.inline_lvl > Inline_Lvl_0) { comp_phase = Inlining; inline_processing(SCP_FIRST_SH_IDX(curr_scp_idx)); PRINT_IR_TBL3; } } insert_global_directives = TRUE; comp_phase = Pdg_Conversion; if (dump_flags.preinline) { /* Do not do a full compile */ if (ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Module || ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Function || ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Subroutine) { curr_scp_idx = MAIN_SCP_IDX; #ifdef KEY /* Bug 3477 */ if (create_mod_info_file()) { /* Creates a name for the file. */ create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ } #else create_mod_info_file(); /* Creates a name for the file. */ create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ #endif /* KEY Bug 3477 */ free_tables(); /* Frees the tables. */ } } else { #ifdef KEY /* Bug 3477 */ int do_output_file = FALSE; #endif /* KEY Bug 3477 */ if (ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Module) { #ifdef KEY /* Bug 3477 */ do_output_file = create_mod_info_file(); /* Creates a name for the file. */ #else create_mod_info_file(); /* Creates a name for the file. */ #endif /* KEY Bug 3477 */ } if (num_prog_unit_errors == 0 && (binary_output || assembly_output)) { cvrt_to_pdg(compiler_gen_date); } else if (ATP_PGM_UNIT(SCP_ATTR_IDX(MAIN_SCP_IDX)) == Module) { if (!SCP_IN_ERR(MAIN_SCP_IDX)) { curr_scp_idx = MAIN_SCP_IDX; #ifdef KEY /* Bug 3477 */ if (do_output_file) { create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ } #else create_mod_info_tbl(); /* Creates the table. */ output_mod_info_file(); /* Writes the table. */ #endif /* KEY Bug 3477 */ } free_tables(); /* Frees the tables. */ } else { free_tables(); /* Frees the tables. */ } } /* ALERT - At this point, the symbol tables are invalid. */ /* Spit out the End Unit for the current program unit. The End Unit */ /* is needed if the Compiler Information File (CIF) is being produced */ /* and for the buffered message file. */ stmt_start_line = line_num; stmt_start_col = column_num; if (scp_tbl == NULL_IDX) { /* Table has been freed. */ cif_end_unit_rec(program_unit_name); } else { cif_end_unit_rec(AT_OBJ_NAME_PTR(SCP_ATTR_IDX(curr_scp_idx))); } } /* while */ clean_up_module_files(); # ifdef _NAME_SUBSTITUTION_INLINING if (!dump_flags.preinline) # endif terminate_PDGCS(); PRINT_GL_TBL; /* Prints to debug_file ifdef _DEBUG and -u gl */ PRINT_GN_TBL; /* Prints to debug_file ifdef _DEBUG and -u gn */ PREPROCESS_ONLY_SKIP: # if defined(_HOST_OS_UNICOS) SECOND(&end_time); # elif defined(_HOST_OS_MAX) end_clock = clock(); end_time = 0; # elif defined(_HOST_OS_SOLARIS) end_time = (float) time(NULL); end_clock = clock(); # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) getrusage(RUSAGE_SELF, &ru); end_time = (double) ru.ru_utime.tv_sec + (double) ru.ru_utime.tv_usec * 1e-6 + (double) ru.ru_stime.tv_sec + (double) ru.ru_stime.tv_usec * 1e-6; # else end_time = 0; # endif total_cpu_time = end_time - start_time; if (cif_need_unit_rec && cif_first_pgm_unit) { /* Catastrophic errors, like a free source form program was compiled */ /* in fixed source form mode, so no Unit record was output. Output */ /* enough records to keep libcif tools happy. This routine needs to be */ /* called whether or not a CIF is being written because the buffered */ /* message file also must have the correct format. */ cif_fake_a_unit(); } /* CAUTION: The following code assumes that non-Cray platforms measure */ /* memory usage in terms of bytes and that there are 4 bytes per word. */ cif_summary_rec(release_level, compiler_gen_date, compiler_gen_time, total_cpu_time, # if defined(_HOST_OS_UNICOS) (long) 0, (some_scp_in_err) ? -3 : max_field_len); # elif defined(_HOST_OS_MAX) end_clock, (some_scp_in_err) ? -3 : max_field_len); # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) (long) 0, (some_scp_in_err) ? -3 : max_field_len/4); # else /* defined(_HOST_OS_SOLARIS) */ end_clock, (some_scp_in_err) ? -3 : max_field_len/4); # endif /* Output compilation summary info if the -V option was specified on the */ /* command line. Also, issue the summary information if any messages were */ /* actually issued. */ if (cmd_line_flags.verify_option || num_errors > 0 || num_warnings > 0 || num_cautions > 0 || num_notes > 0 || num_comments > 0 || num_ansi > 0 || (num_optz_msgs > 0 && opt_flags.msgs)) { print_buffered_messages(); print_id_line(); /* Output the summary lines. The compilation time is in seconds. */ /* CAUTION: The following non-Cray code assumes a 32-bit word. */ # if defined(_HOST_OS_UNICOS) PRINTMSG (0, 104, Log_Summary, 0, (double) total_cpu_time); msg_name = "cf90"; # elif defined(_HOST_OS_MAX) PRINTMSG (0, 104, Log_Summary, 0, (double) end_clock/1000000.0); msg_name = "cf90"; # elif defined(_HOST_OS_LINUX) msg_name = PSC_NAME_PREFIX "f95"; # elif (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) /* IRIX cannot handle the int to float change necessary to get the */ /* time printed correctly, so we'll convert it to a character string */ /* and use a different message. */ /* */ /* LRR 4/28/97 In an email message from Rich Shapiro to me, he stated */ /* he did not want this line in the summary lines. */ /* sprintf(time, "%-1.2f", (double) total_cpu_time); PRINTMSG (0, 1310, Log_Summary, 0, time); */ msg_name = "cf90"; # elif defined(_HOST_OS_SOLARIS) PRINTMSG (0, 104, Log_Summary, 0, (total_cpu_time <= 2147.0) ? (float) end_clock/1000000.0 : (float) total_cpu_time); msg_name = "cf90"; # endif /* Maximum field length (maximum amount of memory used) in words */ /* (decimal). */ /* CAUTION: Non-Cray platforms are assumed to measure memory usage in */ /* bytes and we assume 4 bytes per word. */ # if defined(_HOST_OS_UNICOS) PRINTMSG (0, 105, Log_Summary, 0, max_field_len); # elif ! (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) /* LRR 4/28/97 In an email message from Rich Shapiro to me, he stated */ /* he did not want this line in the summary lines. */ PRINTMSG (0, 105, Log_Summary, 0, max_field_len/4); # endif /* Number of source lines compiled. */ # if (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) && !defined(_TARGET_SV2) PRINTMSG (0, 1401, Log_Summary, 0, --curr_glb_line); # else PRINTMSG (0, 106, Log_Summary, 0, --curr_glb_line); # endif /* Number of messages issued. */ # if (defined(_HOST_OS_IRIX) || defined(_HOST_OS_LINUX)) && !defined(_TARGET_SV2) PRINTMSG (0, 1403, Log_Summary, 0, num_errors, num_warnings, (opt_flags.msgs == 0) ? (num_cautions + num_notes + num_comments) : (num_cautions + num_notes + num_comments + num_optz_msgs), num_ansi); # else PRINTMSG (0, 107, Log_Summary, 0, num_errors, num_warnings, (opt_flags.msgs == 0) ? (num_cautions + num_notes + num_comments) : (num_cautions + num_notes + num_comments + num_optz_msgs), num_ansi); /* Code: in words; data: in words. */ /* LRR 4/28/97 In an email message from Rich Shapiro to me, he stated */ /* he did not want this line in the summary lines. */ # if !defined(_TARGET_SV2) /* Prints blank for sv2 right now. */ PRINTMSG (0, 108, Log_Summary, 0, code_size, data_size); # endif # endif if (num_errors > 0 || num_warnings > 0 || num_cautions > 0 || num_notes > 0 || num_comments > 0 || num_ansi > 0 || (num_optz_msgs > 0 && opt_flags.msgs)) { PRINTMSG (0, 1636, Log_Summary, 0, msg_name, msg_name); } } /* End of summary printing. */ # ifdef _DEBUG /* Get memory usage reports for these global tables. */ final_src_input(); MEM_REPORT(file_path_tbl); MEM_REPORT(global_attr_tbl); MEM_REPORT(global_bounds_tbl); MEM_REPORT(global_line_tbl); MEM_REPORT(global_name_tbl); MEM_REPORT(global_type_tbl); MEM_REPORT(str_pool); # endif exit_compiler ((num_errors == 0) ? RC_OKAY : RC_USER_ERROR); } /* main */
void uart_repl() { uart_puts("~~ trying to malloc repl buffers\r\n"); char* out_buf = malloc(1024*10); char* in_line = malloc(1024*2); char* in_buf = malloc(1024*10); uart_puts("\r\n\r\n++ welcome to EvaEvangelion arm/32 (c)2019 mntmn.\r\n"); init_compiler(); uart_puts("\r\n~~ compiler initialized.\r\n"); memset(out_buf,0,1024*10); memset(in_line,0,1024*2); memset(in_buf,0,1024*10); long count = 0; int fullscreen = 0; int in_offset = 0; int parens = 0; int linec = 0; Cell* expr; char c = 0; //13; //strcpy(in_line,"(eval (load \"/sd/boot.l\"))\n"); while (1) { expr = NULL; uart_puts("evangelion> "); int i = 0; while (c!=13) { c = uart_getc(); uart_putc(c); in_line[i++] = c; in_line[i] = 0; } c = 0; int len = strlen(in_line); // recognize parens for (i=0; i<len; i++) { if (in_line[i] == '(') { parens++; } else if (in_line[i] == ')') { parens--; } } //printf("parens: %d in_offset: %d\n",parens,in_offset); if (len>1) { strncpy(in_buf+in_offset, in_line, len-1); in_buf[in_offset+len-1] = 0; //printf("line: '%s' (%d)\n",in_buf,strlen(in_buf)); linec++; //if (linec>10) while (1) {}; } printf("\r\n[%s]\r\n",in_buf); if (parens>0) { printf("\r\n...\r\n"); in_offset+=len-1; } else { if (len>1) { expr = read_string(in_buf); in_offset=0; } } //printf("parens: %d offset: %d\n",parens,in_offset); //funcptr compiled; if (expr) { //jit_prolog(); int success = 0; //compile_arg(JIT_R0, expr, TAG_ANY); if (success) { funcptr compiled = NULL; //jit_emit(); //jit_disassemble(); //start_clock(); /*uint32_t compiled[] = { 0xe3a03005, // mov r3, #5 0xe1a00003, // mov r0, r3 0xe12fff1e // bx lr };*/ printf("-- compiled: %p\r\n",compiled); memdump(compiled,200,1); printf("-- jumping to code…"); //Cell* res = expr; Cell* res = (Cell*)((funcptr)compiled)(); printf("-- res at: %p\r\n",res); // TODO: move to write op if (!res || res<(Cell*)heap_end) { uart_puts("null\n"); } else { lisp_write(res, out_buf, 1024*10); uart_puts(out_buf); } } uart_puts("\r\n"); } } }
SLJIT_API_FUNC_ATTRIBUTE struct sljit_compiler* sljit_create_compiler(void) { struct sljit_compiler *compiler = (struct sljit_compiler*)SLJIT_MALLOC(sizeof(struct sljit_compiler)); if (!compiler) return NULL; SLJIT_ZEROMEM(compiler, sizeof(struct sljit_compiler)); SLJIT_COMPILE_ASSERT( sizeof(sljit_b) == 1 && sizeof(sljit_ub) == 1 && sizeof(sljit_h) == 2 && sizeof(sljit_uh) == 2 && sizeof(sljit_i) == 4 && sizeof(sljit_ui) == 4 && ((sizeof(sljit_w) == 4 && sizeof(sljit_uw) == 4) || (sizeof(sljit_w) == 8 && sizeof(sljit_uw) == 8)), invalid_integer_types); /* Only the non-zero members must be set. */ compiler->error = SLJIT_SUCCESS; compiler->buf = (struct sljit_memory_fragment*)SLJIT_MALLOC(BUF_SIZE); compiler->abuf = (struct sljit_memory_fragment*)SLJIT_MALLOC(ABUF_SIZE); if (!compiler->buf || !compiler->abuf) { if (compiler->buf) SLJIT_FREE(compiler->buf); if (compiler->abuf) SLJIT_FREE(compiler->abuf); SLJIT_FREE(compiler); return NULL; } compiler->buf->next = NULL; compiler->buf->used_size = 0; compiler->abuf->next = NULL; compiler->abuf->used_size = 0; compiler->temporaries = -1; compiler->saveds = -1; #if (defined SLJIT_CONFIG_X86_32 && SLJIT_CONFIG_X86_32) compiler->args = -1; #endif #if (defined SLJIT_CONFIG_ARM_V5 && SLJIT_CONFIG_ARM_V5) compiler->cpool = (sljit_uw*)SLJIT_MALLOC(CPOOL_SIZE * sizeof(sljit_uw) + CPOOL_SIZE * sizeof(sljit_ub)); if (!compiler->cpool) { SLJIT_FREE(compiler->buf); SLJIT_FREE(compiler->abuf); SLJIT_FREE(compiler); return NULL; } compiler->cpool_unique = (sljit_ub*)(compiler->cpool + CPOOL_SIZE); compiler->cpool_diff = 0xffffffff; #endif #if (defined SLJIT_CONFIG_MIPS_32 && SLJIT_CONFIG_MIPS_32) compiler->delay_slot = UNMOVABLE_INS; #endif #if (defined SLJIT_NEEDS_COMPILER_INIT && SLJIT_NEEDS_COMPILER_INIT) if (!compiler_initialized) { init_compiler(); compiler_initialized = 1; } #endif return compiler; }
int cmdline_main (int argc, char *argv[]) { guchar *output; int num_frames = 1; #ifdef MOVIES int generate_movie = 0; quicktime_t *output_movie; guchar **rows; #endif int antialiasing = 0, supersampling = 0; int img_width, img_height; char *generator = 0; userval_info_t *userval_info; int num_input_drawables = 0; gboolean size_is_set = FALSE; char *script = NULL; char *output_filename; gboolean htmldoc = FALSE; define_t *defines = NULL; int bench_render_count = 1; int render_num; gboolean bench_no_output = FALSE; gboolean bench_no_backend = FALSE; int compile_time_limit = DEFAULT_OPTIMIZATION_TIMEOUT; for (;;) { static struct option long_options[] = { { "version", no_argument, 0, OPTION_VERSION }, { "help", no_argument, 0, OPTION_HELP }, { "intersampling", no_argument, 0, 'i' }, { "oversampling", no_argument, 0, 'o' }, { "cache", required_argument, 0, 'c' }, { "generator", required_argument, 0, 'g' }, { "size", required_argument, 0, 's' }, { "script-file", required_argument, 0, 'f' }, { "htmldoc", no_argument, 0, OPTION_HTMLDOC }, { "bench-no-output", no_argument, 0, OPTION_BENCH_NO_OUTPUT }, { "bench-only-compile", no_argument, 0, OPTION_BENCH_ONLY_COMPILE }, { "bench-no-compile-time-limit", no_argument, 0, OPTION_BENCH_NO_COMPILE_TIME_LIMIT }, { "bench-no-backend", no_argument, 0, OPTION_BENCH_NO_BACKEND }, { "bench-render-count", required_argument, 0, OPTION_BENCH_RENDER_COUNT }, #ifdef MOVIES { "frames", required_argument, 0, 'F' }, { "movie", required_argument, 0, 'M' }, #endif { 0, 0, 0, 0 } }; int option, option_index; option = getopt_long(argc, argv, #ifdef MOVIES "f:ioF:D:M:c:g:s:", #else "f:ioD:c:g:s:", #endif long_options, &option_index); if (option == -1) break; switch (option) { case OPTION_VERSION : printf("MathMap " MATHMAP_VERSION "\n" "\n" "Copyright (C) 1997-2009 Mark Probst\n" "\n" "This program is free software; you can redistribute it and/or modify\n" "it under the terms of the GNU General Public License as published by\n" "the Free Software Foundation; either version 2 of the License, or\n" "(at your option) any later version.\n" "\n" "This program is distributed in the hope that it will be useful,\n" "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" "GNU General Public License for more details.\n" "\n" "You should have received a copy of the GNU General Public License\n" "along with this program; if not, write to the Free Software\n" "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"); return 0; case OPTION_HELP : usage(); return 0; case OPTION_HTMLDOC : htmldoc = TRUE; break; case 'f' : if (!g_file_get_contents(optarg, &script, NULL, NULL)) { fprintf(stderr, _("Error: The script file `%s' could not be read.\n"), optarg); return 1; } break; case 'i' : antialiasing = 1; break; case 'o' : supersampling = 1; break; case 'c' : cache_size = atoi(optarg); assert(cache_size > 0); break; case 'D' : append_define(optarg, &defines); break; case 'I' : alloc_cmdline_image_input_drawable(optarg); break; case 'g' : generator = optarg; break; case 's' : if (!parse_image_size(optarg, &img_width, &img_height)) { fprintf(stderr, _("Error: Invalid image size. Syntax is <width>x<height>. Example: 1024x768.\n")); exit(1); } size_is_set = 1; break; case OPTION_BENCH_RENDER_COUNT : bench_render_count = atoi(optarg); break; case OPTION_BENCH_ONLY_COMPILE : bench_render_count = 0; break; case OPTION_BENCH_NO_OUTPUT : bench_no_output = TRUE; break; case OPTION_BENCH_NO_COMPILE_TIME_LIMIT : compile_time_limit = -1; break; case OPTION_BENCH_NO_BACKEND : bench_no_backend = TRUE; break; #ifdef MOVIES case 'F' : generate_movie = 1; num_frames = atoi(optarg); assert(num_frames > 0); break; case 'M' : alloc_cmdline_movie_input_drawable(optarg); break; #endif } } if (script != NULL) { if (argc - optind != 1) { usage(); return 1; } output_filename = argv[optind]; } else { if (argc - optind != 2) { usage(); return 1; } script = argv[optind]; output_filename = argv[optind + 1]; } init_tags(); init_builtins(); init_macros(); init_compiler(); if (htmldoc) { mathmap_t *mathmap = parse_mathmap(script); filter_t *filter; FILE *out; if (mathmap == NULL) { fprintf(stderr, _("Error: Could not read MathMap script: %s\n"), error_string); return 1; } out = fopen(output_filename, "w"); if (out == NULL) { fprintf(stderr, _("Error: Cannot open file `%s' for writing: %s\n"), output_filename, strerror(errno)); return 1; } for (filter = mathmap->filters; filter != NULL; filter = filter->next) { if (filter->kind != FILTER_MATHMAP) continue; if (!write_filter_html_doc(out, filter->v.mathmap.decl)) return 1; } fclose(out); } else if (generator == 0) { char *support_paths[4]; mathmap_t *mathmap; mathmap_invocation_t *invocation; int current_frame; support_paths[0] = g_strdup_printf("%s/mathmap", GIMPDATADIR); support_paths[1] = g_strdup_printf("%s/.gimp-2.6/mathmap", getenv("HOME")); support_paths[2] = g_strdup_printf("%s/.gimp-2.4/mathmap", getenv("HOME")); support_paths[3] = NULL; mathmap = compile_mathmap(script, support_paths, compile_time_limit, bench_no_backend); if (bench_no_backend) return 0; if (mathmap == 0) { fprintf(stderr, _("Error: %s\n"), error_string); exit(1); } if (bench_render_count == 0) return 0; if (!size_is_set) for (userval_info = mathmap->main_filter->userval_infos; userval_info != NULL; userval_info = userval_info->next) { define_t *define; unsigned char *image; if (userval_info->type != USERVAL_IMAGE) continue; define = lookup_define(defines, userval_info->name); if (define == NULL) { fprintf(stderr, _("Error: No value defined for input image `%s'.\n"), userval_info->name); return 1; } image = read_image(define->value, &img_width, &img_height); if (image == NULL) { fprintf(stderr, _("Error: Could not read input image `%s'.\n"), define->value); return 1; } free(image); size_is_set = TRUE; break; } if (!size_is_set) { fprintf(stderr, _("Error: Image size not set and no input images given.\n")); exit(1); } invocation = invoke_mathmap(mathmap, NULL, img_width, img_height, TRUE); for (userval_info = mathmap->main_filter->userval_infos; userval_info != NULL; userval_info = userval_info->next) { userval_t *userval = &invocation->uservals[userval_info->index]; define_t *define = lookup_define(defines, userval_info->name); if (define == NULL) { if (userval_info->type == USERVAL_IMAGE) { fprintf(stderr, _("Error: No value defined for input image `%s'.\n"), userval_info->name); return 1; } } else switch (userval_info->type) { case USERVAL_INT_CONST : userval->v.int_const = atoi(define->value); break; case USERVAL_FLOAT_CONST : userval->v.float_const = g_ascii_strtod(define->value, NULL); break; case USERVAL_BOOL_CONST : userval->v.bool_const = (float)atoi(define->value); break; case USERVAL_IMAGE : assign_image_userval_drawable(userval_info, userval, alloc_cmdline_image_input_drawable(define->value)); ++num_input_drawables; break; default : fprintf(stderr, _("Error: Can only define user values for types int, float, bool and image.\n")); return 1; } } for (render_num = 0; render_num < bench_render_count; ++render_num) { #ifdef MOVIES for (i = 0; i < num_input_drawables; ++i) if (input_drawables[i].type == DRAWABLE_MOVIE) { assert(quicktime_video_width(input_drawables[i].v.movie, 0) == img_width); assert(quicktime_video_height(input_drawables[i].v.movie, 0) == img_height); } #endif invocation_set_antialiasing(invocation, antialiasing); invocation->supersampling = supersampling; invocation->output_bpp = 4; output = (guchar*)malloc((long)invocation->output_bpp * (long)img_width * (long)img_height); assert(output != 0); #ifdef MOVIES if (generate_movie) { output_movie = quicktime_open(output_filename, 0, 1); assert(output_movie != 0); quicktime_set_video(output_movie, 1, img_width, img_height, 25, QUICKTIME_JPEG); assert(quicktime_supported_video(output_movie, 0)); quicktime_seek_start(output_movie); rows = (guchar**)malloc(sizeof(guchar*) * img_height); for (i = 0; i < img_height; ++i) rows[i] = output + img_width * invocation->output_bpp * i; } #endif for (current_frame = 0; current_frame < num_frames; ++current_frame) { float current_t = (float)current_frame / (float)num_frames; image_t *closure = closure_image_alloc(&invocation->mathfuncs, NULL, invocation->mathmap->main_filter->num_uservals, invocation->uservals, img_width, img_height); mathmap_frame_t *frame = invocation_new_frame(invocation, closure, current_frame, current_t); call_invocation_parallel_and_join(frame, closure, 0, 0, img_width, img_height, output, 1); invocation_free_frame(frame); #ifdef MOVIES if (generate_movie && !bench_no_output) { fprintf(stderr, _("writing frame %d\n"), current_frame); assert(quicktime_encode_video(output_movie, rows, 0) == 0); } #endif closure_image_free(closure); } if (!bench_no_output) { #ifdef MOVIES if (generate_movie) quicktime_close(output_movie); else #endif write_image(output_filename, img_width, img_height, output, invocation->output_bpp, img_width * invocation->output_bpp, IMAGE_FORMAT_PNG); } free(output); } } else { if (strcmp(generator, "blender") == 0) { if (!blender_generate_plug_in(script, output_filename)) return 1; } /* else if (strcmp(generator, "pixeltree") == 0) { if (!pixeltree_generate_plug_in(argv[optind], argv[optind + 1])) return 1; } */ else { fprintf(stderr, _("Unknown generator `%s'\n"), generator); return 1; } } return 0; }