int assemble(void) { char *pc; struct symbol_table *cmd_defines; /* store the command line defines to restore on second pass */ cmd_defines = state.stDefines; state.c_memory = state.i_memory = i_memory_create(); if(state.basefilename[0] == '\0') { strcpy(state.basefilename, state.srcfilename); pc = strrchr(state.basefilename, '.'); if (pc) *pc = 0; } /* Builtins are always case insensitive */ state.stBuiltin = push_symbol_table(NULL, 1); state.stDirective = state.stBuiltin; state.stMacros = push_symbol_table(NULL, state.case_insensitive); state.stTop = state.stGlobal = push_symbol_table(NULL, state.case_insensitive); state.stTopDefines = state.stDefines = push_symbol_table(cmd_defines, state.case_insensitive); opcode_init(0); /* the tables are built, select the processor if -p was used */ if (cmd_processor) { select_processor(processor_name); state.cmd_line.processor = 1; } state.pass = 1; open_src(state.srcfilename, 0); yyparse(); state.pass++; state.org = 0; state.cblock = 0; /* clean out defines for second pass */ state.stTopDefines = state.stDefines = push_symbol_table(cmd_defines, state.case_insensitive); if (state.cmd_line.radix != 1) state.radix = 16; state.obj.symbol_num = 0; state.obj.section_num = 0; state.obj.org_num = 0; state.found_config = 0; state.found_devid = 0; state.found_idlocs = 0; coff_init(); cod_init(); lst_init(); open_src(state.srcfilename, 0); yyparse(); assert(state.pass == 2); pop_symbol_table(state.stBuiltin); hex_init(); if(state.memory_dump) print_i_memory(state.i_memory, state.device.class == PROC_CLASS_PIC16E ? 1 : 0); /* Maybe produce a symbol table */ if (state.lst.symboltable) { lst_throw(); /* Start symbol table on a fresh page */ lst_symbol_table(state.stGlobal); lst_defines_table(state.stDefines); } /* Maybe produce a memory map */ if ((state.mode == absolute) && (state.lst.memorymap)) { lst_memory_map(state.i_memory); } /* Finish off the object, listing, and symbol files*/ coff_close_file(); lst_close(); if (state.processor_info) cod_close_file(); free_files(); if ((state.num.errors > 0) || (gp_num_errors > 0)) return EXIT_FAILURE; else return EXIT_SUCCESS; }
int main( int argc, char *argv[] ) { extern char *optarg; extern int optind; int c; int usage = 0; int memory_dump = 0; int dos_newlines = 0; char *pc; int cmd_processor = 0; char *processor_name = NULL; state.i_memory = i_memory_create(); state.pass = 0; state.quiet = 0; #ifdef PARSE_DEBUG { extern int yydebug; yydebug = 1; /* enable parse debug */ } #endif #ifdef USE_GPASM_HEADER_PATH /* add the header path to the include paths list */ #ifndef __MSDOS__ include_paths[n_include_paths++] = GPASM_HEADER_PATH; #else include_paths[n_include_paths++] = "c:\\gputils\\header"; #endif #endif while ((c = GETOPT_FUNC) != EOF) { switch (c) { case '?': case 'h': usage = 1; break; case 'a': select_hexformat(optarg); state.cmd_line.hex_format = 1; break; case 'c': state.case_insensitive = 1; if (state.stDefines != NULL) { printf("Warning: The -c option must be called before the -d option.\n"); } break; case 'D': case 'd': if ((optarg != NULL) && (strlen(optarg) > 0)) { struct symbol *sym; char *lhs, *rhs; /* the Defines symbol table is not yet defined*/ if (state.stDefines == NULL) { state.stDefines = push_symbol_table(NULL, state.case_insensitive); } lhs = strdup(optarg); rhs = strchr(lhs, '='); if (rhs != NULL) { *rhs = '\0'; /* Terminate the left-hand side */ rhs++; /* right-hand side begins after the '=' */ } sym = get_symbol(state.stDefines, lhs); if (sym == NULL) sym = add_symbol(state.stDefines, lhs); if (rhs) annotate_symbol(sym, rhs); } break; case 'e': select_expand(optarg); state.cmd_line.macro_expand = 1; break; case 'I': if(n_include_paths < MAX_INCLUDE_PATHS) { include_paths[n_include_paths++] = optarg; } else { fprintf(stderr, "too many -I paths\n"); exit(1); } break; case 'l': dump_processor_list(); exit(0); break; case 'm': memory_dump = 1; break; case 'n': #ifndef __MSDOS__ dos_newlines = 1; #endif break; case 'o': strcpy(state.hexfilename, optarg); strcpy(state.basefilename, optarg); pc = strrchr(state.basefilename, '.'); if (pc) *pc = 0; break; case 'p': cmd_processor = 1; processor_name = optarg; break; case 'q': state.quiet = 1; break; case 'r': select_radix(optarg); state.cmd_line.radix = 1; break; case 'w': select_errorlevel(atoi(optarg)); state.cmd_line.error_level = 1; break; case 'v': fprintf(stderr, "%s\n", GPASM_VERSION_STRING); exit(0); } if (usage) break; } if (optind < argc) state.srcfilename = argv[optind]; else usage = 1; if (usage) { show_usage(); } if(state.basefilename[0] == '\0') { strcpy(state.basefilename, state.srcfilename); pc = strrchr(state.basefilename, '.'); if (pc) *pc = 0; } /* the Defines symbol table is not yet defined*/ if (state.stDefines == NULL) { state.stDefines = push_symbol_table(NULL, state.case_insensitive); } /* Builtins are always case insensitive */ state.stBuiltin = push_symbol_table(NULL, 1); state.stDirective = state.stBuiltin; state.stMacros = push_symbol_table(NULL, state.case_insensitive); state.stTop = state.stGlobal = push_symbol_table(NULL, state.case_insensitive); opcode_init(0); /* the tables are built, select the processor if -p was used */ if (cmd_processor) { select_processor(processor_name); state.cmd_line.processor = 1; } state.maxram = (MAX_RAM - 1); open_src(state.srcfilename, 0); state.pass = 1; yyparse(); open_src(state.srcfilename, 0); state.pass++; state.org = 0; state.cblock = 0; if (state.cmd_line.radix != 1) state.radix = 16; cod_init(); lst_init(); yyparse(); assert(state.pass == 2); pop_symbol_table(state.stBuiltin); if (check_writehex(state.i_memory, state.hex_format)) { gperror(GPE_IHEX,NULL); } else { int byte_words; if (state.device.core_size > 0xff) { byte_words = 0; } else { byte_words = 1; if (state.hex_format != inhx8m) { gpwarning(GPW_UNKNOWN,"Must use inhx8m format for EEPROM8"); state.hex_format = inhx8m; } } if (writehex(state.basefilename, state.i_memory, state.hex_format, state.num.errors, byte_words, dos_newlines)) { gperror(GPE_UNKNOWN,"Error generating hex file"); } } if(memory_dump) print_i_memory(state.i_memory); /* Maybe produce a symbol table */ if (state.lst.symboltable) { lst_throw(); /* Start symbol table on a fresh page */ lst_symbol_table(state.stGlobal); lst_defines_table(state.stDefines); } /* Maybe produce a memory map */ if (state.lst.memorymap) { lst_memory_map(state.i_memory); } /* Finish off the listing and symbol files*/ lst_close(); if (state.processor_info) cod_close_file(); free_files(); if (state.num.errors > 0) return 1; else return 0; }
/* * ======== api_init ======== * Purpose: * Module initialization used by Bridge API. */ bool api_init(void) { bool ret = true; bool fdrv, fdev, fcod, fchnl, fmsg, fio; bool fmgr, fproc, fnode, fdisp, fstrm, frmm; if (api_c_refs == 0) { /* initialize driver and other modules */ fdrv = drv_init(); fmgr = mgr_init(); fproc = proc_init(); fnode = node_init(); fdisp = disp_init(); fstrm = strm_init(); frmm = rmm_init(); fchnl = chnl_init(); fmsg = msg_mod_init(); fio = io_init(); fdev = dev_init(); fcod = cod_init(); ret = fdrv && fdev && fchnl && fcod && fmsg && fio; ret = ret && fmgr && fproc && frmm; if (!ret) { if (fdrv) drv_exit(); if (fmgr) mgr_exit(); if (fstrm) strm_exit(); if (fproc) proc_exit(); if (fnode) node_exit(); if (fdisp) disp_exit(); if (fchnl) chnl_exit(); if (fmsg) msg_exit(); if (fio) io_exit(); if (fdev) dev_exit(); if (fcod) cod_exit(); if (frmm) rmm_exit(); } } if (ret) api_c_refs++; return ret; }