From: kramm Date: Tue, 6 Jan 2009 21:31:26 +0000 (+0000) Subject: renamed code_dump() to code_dump2(), code_dump() only takes one argument X-Git-Tag: release-0-9-0~396 X-Git-Url: http://git.asbjorn.biz/?p=swftools.git;a=commitdiff_plain;h=27378541c501be2529a0af42ad25cba39ae9d083 renamed code_dump() to code_dump2(), code_dump() only takes one argument --- diff --git a/lib/as3/abc.c b/lib/as3/abc.c index 73b03d7..623dc7c 100644 --- a/lib/as3/abc.c +++ b/lib/as3/abc.c @@ -395,7 +395,7 @@ static void dump_method(FILE*fo, const char*prefix, if(c->traits) traits_dump(fo, prefix, c->traits, file, methods_seen); fprintf(fo, "%s{\n", prefix); - code_dump(c->code, c->exceptions, file, prefix2, fo); + code_dump2(c->code, c->exceptions, file, prefix2, fo); fprintf(fo, "%s}\n\n", prefix); } diff --git a/lib/as3/code.c b/lib/as3/code.c index bdf6daa..67c0d4e 100644 --- a/lib/as3/code.c +++ b/lib/as3/code.c @@ -201,6 +201,7 @@ opcode_t opcodes[]={ {0x53, "applytype", "n", -1, 1, 0, OP_STACK_ARGS}, /* dummy instructions. Warning: these are not actually supported by flash */ +{0xfc, "__rethrow__", "", 0, 0, 0, OP_THROW|OP_INTERNAL}, {0xfd, "__fallthrough__", "s", 0, 0, 0, OP_INTERNAL}, {0xfe, "__continue__", "s", 0, 0, 0, OP_RETURN|OP_INTERNAL}, {0xff, "__break__", "s", 0, 0, 0, OP_RETURN|OP_INTERNAL}, @@ -415,16 +416,9 @@ void codelookup_free(codelookup_t*codelookup) free(codelookup); } -code_t*code_find_start(code_t*c) -{ - while(c && c->prev) - c=c->prev; - return c; -} - void code_free(code_t*c) { - c = code_find_start(c); + c = code_start(c); while(c) { code_t*next = c->next; opcode_t*op = opcode_get(c->opcode); @@ -544,7 +538,7 @@ static int opcode_write(TAG*tag, code_t*c, pool_t*pool, abc_file_t*file, int len void code_write(TAG*tag, code_t*code, pool_t*pool, abc_file_t*file) { - code = code_find_start(code); + code = code_start(code); int pos = 0; int length = 0; code_t*c = code; @@ -787,7 +781,7 @@ static char callcode(currentstats_t*stats, int pos, int stack, int scope) static currentstats_t* code_get_stats(code_t*code, abc_exception_list_t*exceptions) { - code = code_find_start(code); + code = code_start(code); int num = 0; code_t*c = code; while(c) { @@ -852,10 +846,14 @@ void stats_free(currentstats_t*stats) } } -int code_dump(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo) +int code_dump(code_t*c) +{ + return code_dump2(c, 0, 0, "", stdout); +} +int code_dump2(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo) { abc_exception_list_t*e = exceptions; - c = code_find_start(c); + c = code_start(c); currentstats_t*stats = code_get_stats(c, exceptions); int pos = 0; @@ -931,8 +929,8 @@ int code_dump(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*p int n = (ptroff_t)data; fprintf(fo, "r%d", n); } else if(*p == 'b') { - int b = (ptroff_t)data; - fprintf(fo, "%02x", b); + int b = (signed char)(ptroff_t)data; + fprintf(fo, "%d", b); } else if(*p == 'j') { if(c->branch) fprintf(fo, "->%d", c->branch->pos); @@ -950,7 +948,7 @@ int code_dump(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*p if(l->def) fprintf(fo, "default->%d", l->def->pos); else - fprintf(fo, "default->00000000", l->def->pos); + fprintf(fo, "default->00000000"); code_list_t*t = l->targets; while(t) { if(t->code) @@ -1013,13 +1011,15 @@ code_t* add_opcode(code_t*atag, U8 op) { code_t*tmp = (code_t*)rfx_calloc(sizeof(code_t)); tmp->opcode = op; - tmp->next = 0; if(atag) { tmp->prev = atag; tmp->next = atag->next; + if(tmp->next) + tmp->next->prev = tmp; atag->next = tmp; } else { tmp->prev = 0; + tmp->next = 0; } return tmp; } @@ -1088,7 +1088,7 @@ code_t*code_dup(code_t*c) memcpy(n, c, sizeof(code_t)); opcode_t*op = opcode_get(c->opcode); - if(c->branch) { + if(c->branch || c->opcode == OPCODE_LABEL) { fprintf(stderr, "Error: Can't duplicate branching code\n"); return 0; } @@ -1145,6 +1145,7 @@ code_t*code_cutlast(code_t*c) code_t* cut_last_push(code_t*c) { + assert(!c->next); while(c) { if(!c) break; opcode_t*op = opcode_get(c->opcode); diff --git a/lib/as3/code.h b/lib/as3/code.h index 6ef515e..4dcd096 100644 --- a/lib/as3/code.h +++ b/lib/as3/code.h @@ -82,7 +82,8 @@ code_t*code_dup(code_t*c); code_t*add_opcode(code_t*atag, U8 op); code_t*code_parse(TAG*tag, int len, abc_file_t*file, pool_t*pool, codelookup_t**codelookup); -int code_dump(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo); +int code_dump(code_t*c); +int code_dump2(code_t*c, abc_exception_list_t*exceptions, abc_file_t*file, char*prefix, FILE*fo); void code_write(TAG*tag, code_t*code, pool_t*pool, abc_file_t*file); void code_free(code_t*c); code_t* code_atposition(codelookup_t*l, int pos);