From: notaz Date: Mon, 24 Feb 2014 03:01:43 +0000 (+0200) Subject: translate: check offset assigns if func is used X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=27ebfaed5dcb3fa037438d8a13404c6b957c6c11;p=ia32rtools.git translate: check offset assigns if func is used --- diff --git a/tools/cvt_data.c b/tools/cvt_data.c index 2decf33..6aaf52c 100644 --- a/tools/cvt_data.c +++ b/tools/cvt_data.c @@ -240,7 +240,6 @@ static const struct parsed_proto *check_var(FILE *fhdr, { const struct parsed_proto *pp, *pp_sym; char fp_sym[256], fp_var[256]; - int i, bad = 0; pp = proto_parse(fhdr, varname, 1); if (pp == NULL) { @@ -287,24 +286,7 @@ check_sym: return pp; } - if (pp->argc != pp_sym->argc || pp->argc_reg != pp_sym->argc_reg) - bad = 1; - else { - for (i = 0; i < pp->argc; i++) { - if ((pp->arg[i].reg != NULL) != (pp_sym->arg[i].reg != NULL)) { - bad = 1; - break; - } - if ((pp->arg[i].reg != NULL) - && !IS(pp->arg[i].reg, pp_sym->arg[i].reg)) - { - bad = 1; - break; - } - } - } - - if (bad) { + if (pp_cmp_func(pp, pp_sym)) { pp_print(fp_sym, sizeof(fp_sym), pp_sym); anote("var: %s\n", fp_var); anote("sym: %s\n", fp_sym); diff --git a/tools/protoparse.h b/tools/protoparse.h index 26b0e00..037c3f4 100644 --- a/tools/protoparse.h +++ b/tools/protoparse.h @@ -742,6 +742,30 @@ struct parsed_proto *proto_clone(const struct parsed_proto *pp_c) return pp; } + +static inline int pp_cmp_func(const struct parsed_proto *pp1, + const struct parsed_proto *pp2) +{ + int i; + + if (pp1->argc != pp2->argc || pp1->argc_reg != pp2->argc_reg) + return 1; + else { + for (i = 0; i < pp1->argc; i++) { + if ((pp1->arg[i].reg != NULL) != (pp2->arg[i].reg != NULL)) + return 1; + + if ((pp1->arg[i].reg != NULL) + && !IS(pp1->arg[i].reg, pp2->arg[i].reg)) + { + return 1; + } + } + } + + return 0; +} + static inline void pp_print(char *buf, size_t buf_size, const struct parsed_proto *pp) { diff --git a/tools/translate.c b/tools/translate.c index cb036c1..3d3014c 100644 --- a/tools/translate.c +++ b/tools/translate.c @@ -625,8 +625,10 @@ static int parse_operand(struct parsed_opr *opr, if (wordc_in == 2) { if (IS(words[w], "offset")) { opr->type = OPT_OFFSET; + opr->lmod = OPLM_DWORD; strcpy(opr->name, words[w + 1]); - return wordc; + pp = proto_parse(g_fhdr, opr->name, 1); + goto do_label; } if (IS(words[w], "(offset")) { p = strchr(words[w + 1], ')'); @@ -3476,6 +3478,25 @@ tailcall: } } } + else if (po->op == OP_MOV && po->operand[0].pp != NULL + && po->operand[1].pp != NULL) + { + // = offset + if ((po->operand[1].pp->is_func || po->operand[1].pp->is_fptr) + && !IS_START(po->operand[1].name, "off_")) + { + if (!po->operand[0].pp->is_fptr) + ferr(po, "%s not declared as fptr when it should be\n", + po->operand[0].name); + if (pp_cmp_func(po->operand[0].pp, po->operand[1].pp)) { + pp_print(buf1, sizeof(buf1), po->operand[0].pp); + pp_print(buf2, sizeof(buf2), po->operand[1].pp); + fnote(po, "var: %s\n", buf1); + fnote(po, "func: %s\n", buf2); + ferr(po, "^ mismatch\n"); + } + } + } else if (po->op == OP_RET && !IS(g_func_pp->ret_type.name, "void")) regmask |= 1 << xAX; else if (po->op == OP_DIV || po->op == OP_IDIV) {