int xmlwrap_init(lua_State *L) { // New table for the package lua_newtable(L); add_func(L, "read_file", mod_read_file); add_func(L, "read_memory", mod_read_memory); add_func(L, "new_xml_doc", new_xml_doc); // Push the package as xmlwrap (which pops it) lua_setglobal(L, "xmlwrap"); /* * Register metatables */ /* Register metatable for the xmlDoc objects */ luaL_newmetatable(L, WRAP_XMLDOC); /* create metatable to handle xmlDoc objects */ lua_pushvalue(L, -1); /* push metatable */ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ luaL_setfuncs(L, xmlwrap_doc, 0); /* add xmlDoc methods to the new metatable */ lua_pop(L, 1); /* pop new metatable */ /* Register metatable for the xmlNode objects */ luaL_newmetatable(L, WRAP_XMLNODE); /* create metatable to handle xmlNode objects */ lua_pushvalue(L, -1); /* push metatable */ lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */ luaL_setfuncs(L, xmlwrap_node, 0); /* add xmlNode methods to the new metatable */ lua_pop(L, 1); return 1; }
bool find_parse_ip(ea_t ea, bool parsecode) { char id[16]; // Attempt to identify program start from ip get_many_bytes(ea, id, 16); if (memcmp(id, "SEGA SEGASATURN ", 16) != 0) return false; make_ascii_string(ea, 16, ASCSTR_C); make_ascii_string(ea+0x10, 16, ASCSTR_C); make_ascii_string(ea+0x20, 10, ASCSTR_C); make_ascii_string(ea+0x2A, 6, ASCSTR_C); make_ascii_string(ea+0x30, 8, ASCSTR_C); make_ascii_string(ea+0x38, 8, ASCSTR_C); make_ascii_string(ea+0x40, 10, ASCSTR_C); make_ascii_string(ea+0x4A, 6, ASCSTR_C); make_ascii_string(ea+0x50, 16, ASCSTR_C); make_ascii_string(ea+0x60, 0x70, ASCSTR_C); doByte(ea+0xD0, 16); doDwrd(ea+0xE0, 4); doDwrd(ea+0xE4, 4); doDwrd(ea+0xE8, 4); doDwrd(ea+0xEC, 4); doDwrd(ea+0xF0, 4); add_func(get_long(ea+0xF0), BADADDR); doDwrd(ea+0xF4, 4); doDwrd(ea+0xF8, 4); doDwrd(ea+0xFC, 4); if (parsecode) add_func(ea+0x100, BADADDR); return true; }
/*create a function and add it into function list *the function is defined by an extdef node in syntax tree*/ struct func_descriptor* create_function(struct tree_node* specifier_node, struct tree_node* fundec_node){ char* func_name = fundec_node -> child -> unit_value; if(find_func(func_table_head, func_name) != NULL){ printf("Error type 4 at line %d: Function \'%s\'redifine\n", fundec_node -> lineno, func_name); semantic_error_flag = true; return NULL; } if(is_struct_type(specifier_node) && is_struct_definition(specifier_node -> child)){ printf("Warnning: struct defined inside return field of function \'%s\'\n", func_name); } /*handle return type*/ struct type_descriptor* return_type = create_type(specifier_node); /*create func descriptor and add into list*/ struct func_descriptor* new_func_descriptor = create_func_descriptor(func_name, return_type, 0); add_func(func_table_head, new_func_descriptor); /*handle params*/ if(fundec_node -> child -> sibling -> sibling -> unit_code == VarList){ struct tree_node* varlist_node = fundec_node -> child -> sibling -> sibling; new_func_descriptor -> param_num = init_param_list(new_func_descriptor -> param_list_head, varlist_node); } return new_func_descriptor; }
int db_avs_diff(const struct bu_attribute_value_set *left_set, const struct bu_attribute_value_set *right_set, const struct bn_tol *diff_tol, int (*add_func)(const char *attr_name, const char *attr_val, void *data), int (*del_func)(const char *attr_name, const char *attr_val, void *data), int (*chgd_func)(const char *attr_name, const char *attr_val_left, const char *attr_val_right, void *data), int (*unchgd_func)(const char *attr_name, const char *attr_val, void *data), void *client_data) { int state = DIFF_EMPTY; struct bu_attribute_value_pair *avp; for (BU_AVS_FOR(avp, left_set)) { const char *val2 = bu_avs_get(right_set, avp->name); if (!val2) { if (del_func) {state |= del_func(avp->name, avp->value, client_data);} } else { if (avpp_val_compare(avp->value, val2, diff_tol)) { if (unchgd_func) {state |= unchgd_func(avp->name, avp->value, client_data);} } else { if (chgd_func) {state |= chgd_func(avp->name, avp->value, val2, client_data);} } } } for (BU_AVS_FOR(avp, right_set)) { const char *val1 = bu_avs_get(left_set, avp->name); if (!val1) { if (add_func) {state |= add_func(avp->name, avp->value, client_data);} } } return state; }
MiracException (int error_code, const char *error_msg, const char *function = NULL) throw () { ec = error_code; msg = std::string(error_msg) + std::string(": ") + std::string(strerror(ec)); add_func(function); }
void ug_category_list_link (GList* list, GList* download_list) { UgCategoryAddFunc add_func; GPtrArray* array; UgCategory* category; GList* link; guint index; // create array from download_list array = g_ptr_array_sized_new (g_list_length (download_list)); for (link = download_list; link; link = link->next) array->pdata[array->len++] = link->data; // link tasks in category for (; list; list = list->next) { category = list->data; add_func = category->funcs->add; // get tasks from array by index for (link = category->indices; link; link = link->next) { index = GPOINTER_TO_INT (link->data); if (index < array->len) add_func (category, g_ptr_array_index (array, index)); } // free list g_list_free (category->indices); category->indices = NULL; } // free array g_ptr_array_free (array, TRUE); }
//-------------------------------------------------------------------------- static void load_imports(linput_t *li, dl_header &dl) { if ( !dl.import_list_count ) return; qlseek(li, first_text_subspace_fpos+dl.import_list_loc); ea_t ea = data_start + dl.dlt_loc; int n = dl.dlt_count; char buf[MAXSTR]; for ( int i=0; i < dl.import_list_count; i++ ) { import_entry ie; lread(li, &ie, sizeof(ie)); ie.swap(); if ( n == 0 ) ea = data_start + dl.plt_loc; n--; buf[0] = '.'; get_text_name(ie.name, &buf[1], sizeof(buf)-1); do_name_anyway(ea, buf); doDwrd(ea, 4); set_offset(ea, 0, 0); if ( n > 0 ) { ea += 4; } else { ea_t ea2 = get_long(ea); do_name_anyway(ea2, &buf[1]); add_func(ea2, BADADDR); set_func_cmt(get_func(ea2), "THUNK", false); doDwrd(ea+4, 4); ea += 8; } } }
int do_mod_add(int a, int b) { int ret = 0; if (add_func == NULL) kprintf("module mod-add not loaded.\n"); else ret = add_func(a, b); return ret; }
void make_vector(ea_t addr, char *name) { doDwrd(addr, 4); create_insn(get_long(addr)); add_func(get_long(addr), BADADDR); add_cref(addr, get_long(addr), fl_CF); if (name != NULL) set_name(addr, name); }
/** *\brief change output * *selector is not locked on entry... * */ int svtOutMod (SvcOut * o, uint16_t n_funcs, uint16_t * pnrs, uint16_t * funcs, uint16_t n_pids, uint16_t * pids) { int i; /* find funcs to add/remove add/remove them from tracker(s) fill a buffer with all pids for updated functions combine with pids parameter. modport with new pidset */ debugMsg ("svtOutMod\n"); uint16_t *f_rmv = NULL, *p_rmv = NULL, n_rmv = 0; uint16_t *f_add = NULL, *p_add = NULL, n_add = 0; uint16_t *a_funcs = NULL, *a_pnrs = NULL, a_n_funcs = 0; uint16_t n_svc = 0, *svc = NULL; uint16_t n_total = 0, *total = NULL; a_n_funcs = get_current_funcs (&a_funcs, &a_pnrs, o); n_rmv = get_funcs_to_remove (&f_rmv, &p_rmv, a_funcs, a_pnrs, a_n_funcs, funcs, pnrs, n_funcs); n_add = get_funcs_to_add (&f_add, &p_add, a_funcs, a_pnrs, a_n_funcs, funcs, pnrs, n_funcs); for (i = 0; i < n_add; i++) { add_func (o, p_add[i], f_add[i]); } for (i = 0; i < n_rmv; i++) { rmv_func (o, p_rmv[i], f_rmv[i]); } svc = get_out_pids (o, &n_svc); pidbufDump ("svtOutMod svc pids", svc, n_svc); pidbufDump ("svtOutMod hpids", pids, n_pids); total = pidbufMergeUniq (svc, n_svc, pids, n_pids, &n_total); utlFAN (f_rmv); utlFAN (p_rmv); utlFAN (f_add); utlFAN (p_add); pidbufDump ("ModPort pids", total, n_total); selectorModPort (o->output, n_total, total); utlFAN (o->hpids); o->hpids = pidbufDup (pids, n_pids); o->n_hpids = n_pids; utlFAN (svc); utlFAN (total); return 0; }
void initFunctions() { std::srand(static_cast<unsigned int>(std::time(0))); add_func({ {"sqrt",val_sqrt}, {"abs",val_abs}, {"print",val_print}, {"cos",val_cosf}, {"sin",val_sinf}, {"tan",val_tan}, {"log",val_log}, {"exit",val_exit}, {"rand",val_rand} }); }
/*find all extdef node in tree to do semantic analysis*/ bool semantic_analyze(struct tree_node *root){ assert(root -> unit_code == Program); //add read() and write() func for intercode generator struct type_descriptor* int_type = create_type_descriptor(TYPE_INT, NULL); struct func_descriptor* read_func = create_func_descriptor("read", int_type, 0); struct func_descriptor* write_func_ = create_func_descriptor("write", int_type, 1); write_func_ -> param_list_head -> next = create_var_descriptor("", int_type, NULL); add_func(func_table_head, read_func); add_func(func_table_head, write_func_); //start analyze struct tree_node* extdeflist_node = root -> child; while(extdeflist_node -> child != NULL){ analyze_extdef_node(extdeflist_node -> child); extdeflist_node = extdeflist_node -> child -> sibling; } return semantic_error_flag; }
int do_add_pltmap_funcs( void * data , void * arg ) { plt_map_t * map; func_t * func; if(!(map = data)) error_ret("no map",-1); if(!(func = func_at_addr( map->vaddr ))) { func = new_func(); OBJ_SET_ADDR(func->obj,map->vaddr); add_func( func , 1 ) ; } OBJ_SET_NAME(func->obj,map->name); return(0); }
int get_objs_from_ehdr(Elf32_Ehdr * ehdr) { func_t * func; if(!ehdr) error_ret("null arg",-1); if(!(func = func_at_addr( ehdr->e_entry ))) { func = new_func(); OBJ_SET_NAME(func->obj,"_start"); OBJ_SET_ADDR(func->obj,ehdr->e_entry); if(add_func( func , 1 )<0) error_ret("problem adding",-1); } else { if(strcmp(OBJ_GET_NAME(func->obj),"_start")) OBJ_SET_NAME(func->obj,"_start"); } return(0); }
static int noit_console_rule_configure(noit_console_closure_t ncct, int argc, char **argv, noit_console_state_t *state, void *closure) { xmlNodePtr fsnode = NULL; noit_conf_t_userdata_t *info; char xpath[1024]; info = noit_console_userdata_get(ncct, NOIT_CONF_T_USERDATA); snprintf(xpath, sizeof(xpath), "/%s", info->path); fsnode = noit_conf_get_section(NULL, xpath); if(!fsnode) { nc_printf(ncct, "internal error"); return -1; } if(closure) { int rulenum; xmlNodePtr byebye; /* removing a rule */ if(argc != 1) { nc_printf(ncct, "requires one argument\n"); return -1; } rulenum = atoi(argv[0]); snprintf(xpath, sizeof(xpath), "rule[%d]", rulenum); byebye = noit_conf_get_section(fsnode, xpath); if(!byebye) { nc_printf(ncct, "cannot find rule\n"); return -1; } xmlUnlinkNode(byebye); xmlFreeNode(byebye); nc_printf(ncct, "removed\n"); } else { xmlNodePtr (*add_func)(xmlNodePtr, xmlNodePtr); xmlNodePtr add_arg, new_rule; int i, needs_type = 1; if(argc < 1 || argc % 2) { nc_printf(ncct, "even number of arguments required\n"); return -1; } if(!strcmp(argv[0], "before") || !strcmp(argv[0], "after")) { int rulenum = atoi(argv[1]); snprintf(xpath, sizeof(xpath), "rule[%d]", rulenum); add_arg = noit_conf_get_section(fsnode, xpath); if(!add_arg) { nc_printf(ncct, "%s rule not found\n", xpath); return -1; } if(*argv[0] == 'b') add_func = xmlAddPrevSibling; else add_func = xmlAddNextSibling; argc -= 2; argv += 2; } else { add_func = xmlAddChild; add_arg = fsnode; } for(i=0;i<argc;i+=2) { if(!strcmp(argv[i], "type")) needs_type = 0; else if(strcmp(argv[i], "target") && strcmp(argv[i], "module") && strcmp(argv[i], "name") && strcmp(argv[i], "metric")) { nc_printf(ncct, "unknown attribute '%s'\n", argv[i]); return -1; } } if(needs_type) { nc_printf(ncct, "type <allow|deny> is required\n"); return -1; } new_rule = xmlNewNode(NULL, (xmlChar *)"rule"); for(i=0;i<argc;i+=2) xmlSetProp(new_rule, (xmlChar *)argv[i], (xmlChar *)argv[i+1]); add_func(add_arg, new_rule); noit_filter_compile_add((noit_conf_section_t *)fsnode); } return 0; }
int get_objs_from_entry(elf_t * elf) { char * data; func_t * func; Elf32_Ehdr * ehdr; x86_insn_t insn; addr_t dst; addr_t vma; int nread, tread = 0; if(!elf) error_ret("null arg",-1); if(!(ehdr = get_ehdr(elf))) error_ret("can't get ehdr",-1); if(get_objs_from_ehdr(ehdr)<0) error_ret("can't get _start",-1); if(!(data = data_at_addr( elf , ehdr->e_entry ))) error_ret("can't get data",-1); /* if(!(func = func_at_addr( ehdr->e_entry ))) error_ret("this is dumb",-1); */ do { nread =x86_disasm(data ,MAX_INSN_SIZE+tread, ehdr->e_entry , tread , &insn); if( nread <= 0 ) error_ret("can't get past first stage",-1); tread += nread; } while ( (tread < 512) && ( (insn.type != insn_push) || (insn.operands[op_dest].type != op_immediate ) )); /* this should be libc_csu_fini */ dst = insn.operands[op_dest].data.dword; if(dst <= 0 ) error_ret("bad operand",-1); if(!(func = func_at_addr(dst))){ func = new_func(); OBJ_SET_NAME(func->obj,"__libc_csu_fini"); OBJ_SET_ADDR(func->obj,dst); add_func(func,0); } nread =x86_disasm(data ,MAX_INSN_SIZE+tread , ehdr->e_entry , tread , &insn); if( nread <= 0 ) error_ret("can't get past first stage",-1); tread += nread; if( (insn.type != insn_push) || (insn.operands[op_dest].type != op_immediate) ) error_ret("second push not ok",-1); dst = insn.operands[op_dest].data.dword; if(dst <= 0 ) error_ret("bad operand",-1); if(!(func = func_at_addr(dst))){ func = new_func(); OBJ_SET_NAME(func->obj,"__libc_csu_init"); OBJ_SET_ADDR(func->obj,dst); add_func( func,0 ); } do { nread =x86_disasm(data ,MAX_INSN_SIZE+tread , ehdr->e_entry , tread , &insn); if( nread <= 0 ) error_ret("problem getting main",-1); tread += nread; } while ( (tread < 512) && ((insn.type != insn_push) || (insn.operands[op_dest].type != op_immediate ) )); if( (insn.type != insn_push) || (insn.operands[op_dest].type != op_immediate) ) error_ret("second push not ok",-1); dst = insn.operands[op_dest].data.dword; if(dst <= 0 ) error_ret("bad operand",-1); if(!(func = func_at_addr(dst))){ func = new_func(); OBJ_SET_NAME(func->obj,"main"); OBJ_SET_ADDR(func->obj,dst); add_func( func ,0); } return(tread); }
tree_node* alex_parsing(token_list* t_lt) { token* tk_p = NULL; tree_node* r_tn = NULL; if(t_lt == NULL) return NULL; while(tk_p=at_token(t_lt)) { switch(tk_p->token_type) { case token_type_var: // 定义变量 { r_tn = syn_var_def(t_lt); if(r_tn) add_main(r_tn); else return NULL; } break; case token_type_ide: { r_tn = syn_exp_stmt(t_lt); if(r_tn) add_main(r_tn); else return NULL; } break; case token_type_using: // 引入dll { r_tn = syn_using(t_lt); if(r_tn) add_main(r_tn); else return NULL; } break; case token_type_func: // 定义函数 { r_tn = syn_func_def(t_lt); if(r_tn) { if(look_table(global_table, r_tn->b_v.name.s_ptr)==NULL) { add_g_table(new_func_st(r_tn->b_v.name.s_ptr)); add_func(r_tn); } else { print("parsing[erro line %d]: the function %s is redef!\n", tk_p->token_line, r_tn->b_v.name.s_ptr); free_tree(r_tn); return NULL; } } else return NULL; } break; default: { print("parsing[error line %d]: not allow token \"%s\" at globle code seg!\n", tk_p->token_line, tk_p->token_name); next_token(t_lt); } free_tree(r_tn); return NULL; } } return r_tn; }
void loadDataSheet(XMLNode table_node, std::map<string, int> &map, int (*add_func)(TupleParser&)) { vector<XMLNode> rows; vector<StringRef> col_names; XMLNode row_node = table_node.child("table:table-row"); while(row_node) { rows.emplace_back(row_node); row_node = row_node.sibling("table:table-row"); } { ASSERT(!rows.empty()); XMLNode first_row = rows.front(); XMLNode cell_node = first_row.child("table:table-cell"); while(cell_node) { col_names.push_back(getText(cell_node)); cell_node = cell_node.sibling("table:table-cell"); } } std::map<StringRef, int> column_map; for(int n = 0; n < (int)col_names.size(); n++) if(!col_names[n].isEmpty()) { if(column_map.find(col_names[n]) != column_map.end()) THROW("Duplicate argument: %s", col_names[n]); column_map.emplace(col_names[n], n); } vector<const char*> columns; columns.reserve(col_names.size()); bool errors = false; int id_column = 0; { auto it = column_map.find("id"); if(it == column_map.end()) THROW("Id column must be defined"); id_column = it->second; } for(int r = 1; r < (int)rows.size(); r++) { XMLNode row = rows[r]; int cell_idx = 0; XMLNode cell = row.child("table:table-cell"); columns.clear(); while(cell && cell_idx < (int)col_names.size()) { const char *value = getText(cell); const char *repeat_attrib = cell.hasAttrib("table:number-columns-repeated"); int num_repeat = repeat_attrib? toInt(repeat_attrib) : 1; for(int i = 0; i < num_repeat; i++) columns.push_back(value); cell_idx += num_repeat; cell = cell.sibling("table:table-cell"); } int num_columns = (int)min(col_names.size(), columns.size()); bool is_empty = true; for(int n = 0; n < num_columns; n++) if(columns[n][0]) { is_empty = false; break; } if(is_empty) continue; TupleParser parser(columns.data(), num_columns, column_map); try { string id = columns[id_column]; if(id.empty()) THROW("ID undefined"); if(map.find(id) != map.end()) THROW("Duplicated ID: %s", id.c_str()); int index = add_func(parser); map.emplace(std::move(id), index); } catch(const Exception &ex) { errors = true; printf("Error while parsing row: %d (id: %s):\n%s\n", r, columns[id_column], ex.what()); } } if(errors) THROW("Errors while parsing sheet: %s\n", table_node.attrib("table:name")); }
MiracException (int error_code, const char *function = NULL) throw () { ec = error_code; msg = strerror(ec); add_func(function); }
MiracException (const char *error_msg, const char *function = NULL) throw () { msg = error_msg; add_func(function); }
/* * flag = 0 : add * flag = 1 : replace */ int SHash::sh_sys_add(const void *key, const void *value, int flag, void **ret) { void *tmp, *used, *find; int *hash, n; unsigned int crc32; struct shm_hash_head *head; n = sh_sys_find(key, &tmp, &crc32, &used, &find); if (n == _SHASH_SYS_ERROR) return -1; head = sh_get_head(); void *rec = sh_get_rec(head); if (head->curr >= head->data) { if (sh_extern_shm() == -1) { return _SHASH_SYS_ERROR; } return sh_sys_add(key, value, flag, ret); } switch (n) { case _SHASH_FOUND: if (flag) { if (value_len > 0) memcpy(sh_get_value(find), value, value_len); if (ret) *ret = sh_get_value(find); return 0; } else { while (sh_get_next(find) > 0) { find = sh_get_pos(rec, sh_get_next(find)); } } case _SHASH_NOT_FOUND_NEXT: head->hash_total++; if (used == NULL) { head->curr++; sh_set_next(find, head->curr); find = sh_get_pos(rec, sh_get_next(find)); sh_set_next(find, 0); } else find = used; _sh_get_next(find) |= _RECORD_USED_FLAG; add_func(func_type, sh_get_key(find), key, key_len); if (value_len > 0) memcpy(sh_get_value(find), value, value_len); if (ret) *ret = sh_get_value(find); break; case _SHASH_NOT_FOUND: head->hash_total++; head->curr++; head->hash_used++; hash = sh_get_hash(head); hash[crc32] = head->curr; find = sh_get_pos(rec, hash[crc32]); sh_set_next(find, 0); _sh_get_next(find) |= _RECORD_USED_FLAG; add_func(func_type, sh_get_key(find), key, key_len); if (value_len > 0) memcpy(sh_get_value(find), value, value_len); if (ret) *ret = sh_get_value(find); break; default: return -1; break; } return 0; }
void xxx_add(UDF_INIT* initid, UDF_ARGS* args,float(*interpolate_func)(float,float,float),float(*add_func)(float,float,float),float default_val) { /*Create Default variables*/ int i=0; struct array_data* data = (struct array_data*)initid->ptr; float default_value=100.0; /* Pull out Arguments */ float *arr = ((float *)args->args[0]); int array_size=0; int data_start_freq=0; int data_stop_freq=0; int result_len=0; int result_start_freq=0; int result_stop_freq=0; float *interpolated_data; int *interpolated_bitarray; if ( args->arg_type[1]== INT_RESULT) { array_size = (int)*((longlong *)args->args[1]); } else { array_size = (int) *((double *)(args->args[1])); } if ( args->arg_type[2]== INT_RESULT) { data_start_freq = (int)*((longlong *)args->args[2]); } else { data_start_freq = (int) *((double *)args->args[2]); } if ( args->arg_type[3]== INT_RESULT) { data_stop_freq = (int)*((longlong *)args->args[3]); } else { data_stop_freq = (int) *((double *)args->args[3]); } if ( args->arg_type[4]== INT_RESULT) { result_len = (int)*((longlong *)args->args[4]); } else { result_len = (float) *((double *)args->args[4]); } if ( args->arg_type[5]== INT_RESULT) { result_start_freq = (int)*((longlong *)args->args[5]); } else { result_start_freq = (int) *((double *)args->args[5]); } if ( args->arg_type[6]== INT_RESULT) { result_stop_freq = (int)*((longlong *)args->args[6]); } else { result_stop_freq = (int) *((double *)args->args[6]); } /*Translate data into common range*/ fprintf(stderr,"interpolate(arr, %%? , %d , %d , %d , %d , %d , func,%d)\n" ,data_start_freq,data_stop_freq,result_len,result_start_freq,result_stop_freq,default_val); interpolated_data=malloc(sizeof(float)*MAXARRAY); /*Interpolated_data will be freed at the end of this function */ interpolated_bitarray=malloc(sizeof(int)*MAXARRAY); /*Interpolated_data will be freed at the end of this function */ interpolate(arr,array_size,data_start_freq,data_stop_freq,result_len,result_start_freq,result_stop_freq,interpolate_func,default_val, interpolated_data,interpolated_bitarray); /*Increment count. Useful for averaging */ for (i=0;i<array_size;i++) { if (interpolated_bitarray[i] == 1) { data->arr[i]=add_func(interpolated_data[i],data->arr[i],0); data->datacount[i]+=1; } } if (array_size > data->array_size) { data->array_size =array_size; } free(interpolated_data); free(interpolated_bitarray); }
void find_bios_funcs() { ea_t i; make_ascii_string(0x06000200, 16, ASCSTR_C); doByte(0x06000210, 36); make_vector(0x06000234, NULL); make_vector(0x06000238, NULL); make_vector(0x0600023C, NULL); make_ascii_string(0x06000240, 4, ASCSTR_C); make_ascii_string(0x06000244, 4, ASCSTR_C); doDwrd(0x06000248, 4); doDwrd(0x0600024C, 4); make_vector(0x06000250, NULL); doDwrd(0x06000264, 4); make_vector(0x06000268, NULL); make_vector(0x0600026C, "bios_run_cd_player"); make_vector(0x06000270, NULL); make_vector(0x06000274, "bios_is_mpeg_card_present"); doDwrd(0x06000278, 4); doDwrd(0x0600027C, 4); make_vector(0x06000280, NULL); make_vector(0x06000284, NULL); make_vector(0x06000288, NULL); make_vector(0x0600028C, NULL); doDwrd(0x06000290, 4); doDwrd(0x06000294, 4); make_vector(0x06000298, "bios_get_mpeg_rom"); make_vector(0x0600029C, NULL); doDwrd(0x060002A0, 4); doDwrd(0x060002A4, 4); doDwrd(0x060002A8, 4); doDwrd(0x060002AC, 4); make_vector(0x060002B0, NULL); doDwrd(0x060002B4, 4); doDwrd(0x060002B8, 4); doDwrd(0x060002BC, 4); doDwrd(0x060002C0, 4); for (i = 0x060002C4; i < 0x06000324; i+=4) make_vector(i, NULL); set_name(0x06000300, "bios_set_scu_interrupt"); set_name(0x06000304, "bios_get_scu_interrupt"); set_name(0x06000310, "bios_set_sh2_interrupt"); set_name(0x06000314, "bios_get_sh2_interrupt"); set_name(0x06000320, "bios_set_clock_speed"); doDwrd(0x06000324, 4); set_name(0x06000324, "bios_get_clock_speed"); for (i = 0x06000328; i < 0x06000348; i+=4) make_vector(i, NULL); set_name(0x06000340, "bios_set_scu_interrupt_mask"); set_name(0x06000344, "bios_change_scu_interrupt_mask"); doDwrd(0x06000348, 4); set_name(0x06000348, "bios_get_scu_interrupt_mask"); make_vector(0x0600034C, NULL); doDwrd(0x06000350, 4); doDwrd(0x06000354, 4); doDwrd(0x06000358, 4); doDwrd(0x0600035C, 4); for (i = 0x06000360; i < 0x06000380; i+=4) make_vector(i, NULL); doByte(0x06000380, 16); doWord(0x06000390, 16); doDwrd(0x060003A0, 32); make_ascii_string(0x060003C0, 0x40, ASCSTR_C); add_func(0x06000600, BADADDR); add_func(0x06000646, BADADDR); make_ascii_string(0x0600065C, 0x4, ASCSTR_C); add_func(0x06000678, BADADDR); add_func(0x0600067C, BADADDR); add_func(0x06000690, BADADDR); doDwrd(0x06000A80, 0x80); }
void func1() { add_func(func2); }
static int F() { // function declaration Tdata_type ftype; switch (token.type) { case TT_INT: case TT_DOUBLE: case TT_STRING: // rule: type idf ( AL ) FD ftype = get_type(); tmp_ftype = ftype; next(); check(TT_ID); try(add_func(ftype, token.p_string)); next(); term(TT_L_BRACKET); call(AL); term(TT_R_BRACKET); return(FD); default: return ERR_PARSER; } } static int AL() { // first function argument switch (token.type) { case TT_INT: case TT_DOUBLE: case TT_STRING: // rule: AL -> AD AL2 call(AD); return(AL2); default: // rule: AL -> eps return OK; } } static int AL2() { // remaining function arguments switch (token.type) { case TT_COMMA: // rule: AL2 -> , AD AL2 next(); call(AD); return(AL2); default: // rule: AL2 -> eps return OK; } } static int AD() { // argument Tdata_type atype; switch (token.type) { case TT_INT: case TT_DOUBLE: case TT_STRING: // rule: AD -> type id atype = get_type(); next(); check(TT_ID); try(add_param(atype, token.p_string)); next(); return OK; default: return ERR_PARSER; } } static int FD() { // function definition unsigned i; switch (token.type) { case TT_SEMICOLON: // rule: FD -> ; try(func_declaration()); next(); return OK; case TT_OPEN_BRACKET: // rule: FD -> { STL } i = get_line(); try(func_definition(i)); // instruction pointer next(); call(STL); term(TT_CLOSE_BRACKET); remove_block(); generate(I_ERR, NULL, NULL, NULL); // no return => runtime error return OK; default: return ERR_PARSER; } } static int STL() { // stat list switch (token.type) { case TT_CLOSE_BRACKET: // rule: STL -> eps return OK; default: // rule: STL -> S STL call(S); return(STL); } } static int S() { // stat unsigned i; Tlocal_sym_tab_node *conv; switch (token.type) { case TT_AUTO: case TT_INT: case TT_DOUBLE: case TT_STRING: // rule: S -> D ; call(D); term(TT_SEMICOLON); return OK; case TT_OPEN_BRACKET: // rule: S -> { STL } next(); try(add_block()); call(STL); term(TT_CLOSE_BRACKET); remove_block(); return OK; case TT_IF: // rule: S -> if ( E ) S else S next(); term(TT_L_BRACKET); call(E); try(type_compare(tmp_psitem.type, TYPE_INT)); if (tmp_psitem.type != TYPE_INT) { try(tmp_var(TYPE_INT, &conv)); generate(I_CONVERT, tmp_psitem.value.ptr, NULL, conv); } else { conv = tmp_psitem.value.ptr; } Tlocal_sym_tab_node *label; try(tmp_var(TYPE_INT, &label)); generate(I_JUMPIFN, conv, label, NULL); term(TT_R_BRACKET); call(S); Tlocal_sym_tab_node *endif; try(tmp_var(TYPE_INT, &endif)); generate(I_JUMP, NULL, endif, NULL); i = get_line(); set_var_value_int(label->name, i); call(ELSE); i = get_line(); set_var_value_int(endif->name, i); return OK; case TT_FOR: // rule: S -> for ( D ; E ; E ) S try(add_block()); next(); term(TT_L_BRACKET); call(D); term(TT_SEMICOLON); Tlocal_sym_tab_node *cond; try(tmp_var(TYPE_INT, &cond)); i = get_line(); set_var_value_int(cond->name, i); call(E); try(type_compare(tmp_psitem.type, TYPE_INT)); if (tmp_psitem.type != TYPE_INT) { try(tmp_var(TYPE_INT, &conv)); generate(I_CONVERT, tmp_psitem.value.ptr, NULL, conv); } else { conv = tmp_psitem.value.ptr; } Tlocal_sym_tab_node *endfor; try(tmp_var(TYPE_INT, &endfor)); generate(I_JUMPIFN, conv, endfor, NULL); Tlocal_sym_tab_node *statlist; try(tmp_var(TYPE_INT, &statlist)); generate(I_JUMP, NULL, statlist, NULL); Tlocal_sym_tab_node *assign; try(tmp_var(TYPE_INT, &assign)); i = get_line(); set_var_value_int(assign->name, i); term(TT_SEMICOLON); call(E); generate(I_JUMP, NULL, cond, NULL); i = get_line(); set_var_value_int(statlist->name, i); term(TT_R_BRACKET); call(S); generate(I_JUMP, NULL, assign, NULL); i = get_line(); set_var_value_int(endfor->name, i); remove_block(); return OK; case TT_WHILE: // rule: S -> while ( E ) S next(); term(TT_L_BRACKET); Tlocal_sym_tab_node *wcond; try(tmp_var(TYPE_INT, &wcond)); i = get_line(); set_var_value_int(wcond->name, i); call(E); try(type_compare(tmp_psitem.type, TYPE_INT)); if (tmp_psitem.type != TYPE_INT) { try(tmp_var(TYPE_INT, &conv)); generate(I_CONVERT, tmp_psitem.value.ptr, NULL, conv); } else { conv = tmp_psitem.value.ptr; } Tlocal_sym_tab_node *endwhile; try(tmp_var(TYPE_INT, &endwhile)); generate(I_JUMPIFN, conv, endwhile, NULL); term (TT_R_BRACKET); call(S); generate(I_JUMP, NULL, wcond, NULL); i = get_line(); set_var_value_int(endwhile->name, i); return OK; case TT_DO: // rule: S -> do S while ( E ) ; next(); Tlocal_sym_tab_node *dwbody; try(tmp_var(TYPE_INT, &dwbody)); i = get_line(); set_var_value_int(dwbody->name, i); call(S); term(TT_WHILE); term(TT_L_BRACKET); call(E); try(type_compare(tmp_psitem.type, TYPE_INT)); if (tmp_psitem.type != TYPE_INT) { try(tmp_var(TYPE_INT, &conv)); generate(I_CONVERT, tmp_psitem.value.ptr, NULL, conv); } else { conv = tmp_psitem.value.ptr; } generate(I_JUMPIF, conv, dwbody, NULL); term(TT_R_BRACKET); term(TT_SEMICOLON); return OK; case TT_RETURN: // rule: S -> return E ; next(); call(E); try(type_compare(tmp_ftype, tmp_psitem.type)); if (tmp_psitem.type != tmp_ftype) { try(tmp_var(tmp_ftype, &conv)); generate(I_CONVERT, tmp_psitem.value.ptr, NULL, conv); } else { conv = tmp_psitem.value.ptr; } generate(I_RETURN, conv, NULL, NULL); term(TT_SEMICOLON); return OK; case TT_CIN: // rule: S -> cin >> id IN ; next(); term(TT_IN); check(TT_ID); if (!var_exists(token.p_string)) return ERR_UNDEF; Tlocal_sym_tab_node *var = get_var(token.p_string); generate(I_CIN, NULL, NULL, var); next(); call(IN); term(TT_SEMICOLON); return OK; case TT_COUT: // rule: S -> cout << E OUT ; next(); term(TT_OUT); call(E); generate(I_COUT, tmp_psitem.value.ptr, NULL, NULL); call(OUT); term(TT_SEMICOLON); return OK; default: // rule: S -> E ; call(E); term(TT_SEMICOLON); return OK; } } static int D() { // variable declaration Tdata_type vtype; switch (token.type) { case TT_AUTO: case TT_INT: case TT_DOUBLE: case TT_STRING: // rule: D -> type id I vtype = get_type(); tmp_type = vtype; next(); check(TT_ID); try(add_var(vtype, token.p_string)); try(tmpstr(token.p_string)); next(); return(I); default: return ERR_PARSER; } } static int I() { // variable definition switch (token.type) { case TT_ASSIGN: // rule: I -> = E next(); call(E); try(assign_type_compare(tmp_buffer.str, tmp_psitem.type)); Tlocal_sym_tab_node *var = get_var(tmp_buffer.str); Tlocal_sym_tab_node *conv; if (tmp_psitem.type != var->data_type) { try(tmp_var(var->data_type, &conv)); generate(I_CONVERT, tmp_psitem.value.ptr, NULL, conv); } else { conv = tmp_psitem.value.ptr; } generate(I_ASSIGN, conv, NULL, var); return OK; default: // rule: I -> eps if (tmp_type == TYPE_AUTO) return ERR_AUTO; return OK; } } static int ELSE() { // else switch (token.type) { case TT_ELSE: // rule: ELSE -> else S next(); return(S); default: // rule: ELSE -> eps return OK; } } static int IN() { // input variables switch (token.type) { case TT_IN: // rule: IN -> >> id IN next(); check(TT_ID); if (!var_exists(token.p_string)) return ERR_UNDEF; Tlocal_sym_tab_node *var = get_var(token.p_string); generate(I_CIN, NULL, NULL, var); next(); return(IN); default: // rule: IN -> eps return OK; } } static int OUT() { // output expressions switch (token.type) { case TT_OUT: // rule: OUT -> << E OUT next(); call(E); generate(I_COUT, tmp_psitem.value.ptr, NULL, NULL); return(OUT); default: // rule: OUT -> eps return OK; } } static int E() { // expression Tpsa_stack *psa_stack = ps_init(); ps_push(psa_stack, OP_END); if (get_prec(OP_END) == ' ') { fprintf(stderr, "Syntax error: 'expression' expected, but '%s' given.\n", token_[token.type]); return ERR_PARSER; } int err; do { Tps_item *ps_item = ps_first_term(psa_stack); switch (get_prec(ps_item->op)) { case '=': err = ps_push_token(psa_stack); if (err != OK) { ps_destroy(psa_stack); return err; } next(); break; case '<': err = ps_ins_after(psa_stack, ps_item, OP_EXPR); if (err != OK) { ps_destroy(psa_stack); return err; } err = ps_push_token(psa_stack); if (err != OK) { ps_destroy(psa_stack); return err; } next(); break; case '>': err = psa(psa_stack); if (err != OK) { ps_destroy(psa_stack); return err; } break; } } while (get_prec(ps_first_term(psa_stack)->op) != ' '); Tps_item *top = ps_top(psa_stack); if (top->op != OP_NTERM || ps_prev(psa_stack)->op != OP_END) { fprintf(stderr, "Syntax error: unexpected '%s'\n", token_[token.type]); return ERR_PARSER; } tmp_psitem.type = top->type; tmp_psitem.value = top->value; ps_destroy(psa_stack); return OK; } int parse() { next(); strInit(&tmp_buffer); int err = P(); strFree(&tmp_buffer); return err; }