if(c) {
opcode_t*op = opcode_get(c->opcode);
if(op->flags & (OP_JUMP|OP_BRANCH)) {
- printf("%5d) %02x %s %d\n", t, tag->data[start+t], op->name, c->data[0]);
+ printf("%50d) %02x %s %d\n", t, tag->data[start+t], op->name, c->data[0]);
} else {
- printf("%5d) %02x %s\n", t, tag->data[start+t], op->name);
+ printf("%50d) %02x %s\n", t, tag->data[start+t], op->name);
}
} else {
- printf("%5d) %02x\n", t, tag->data[start+t]);
+ printf("%50d) %02x\n", t, tag->data[start+t]);
}
}
- //printf("%5d) %02x\n", t, tag->data[start+t]);
+ //printf("%05d) %02x\n", t, tag->data[start+t]);
#endif
code_t*c = head;
for(t=0;t<stats->num;t++) {
code_t*c = stats->stack[t].code;
opcode_t*op = opcode_get(c->opcode);
- printf("%5d) %c %d:%d %s", t, (stats->stack[t].flags&FLAG_SEEN)?'x':'|',
+ printf("%05d) %c %d:%d %s", t, (stats->stack[t].flags&FLAG_SEEN)?'x':'|',
stats->stack[t].stackpos,
stats->stack[t].scopepos,
op->name);
for(t=0;t<num;t++) {
opcode_t*op = opcode_get(c->opcode);
if(op->flags & (OP_JUMP|OP_BRANCH)) {
- printf("%5d) %s %08x\n", t, op->name, c->branch);
+ printf("%05d) %s %08x\n", t, op->name, c->branch);
} else if(op->params[0]=='2') {
- printf("%5d) %s %s\n", t, op->name, multiname_tostring(c->data[0]));
+ printf("%05d) %s %s\n", t, op->name, multiname_tostring(c->data[0]));
} else if(op->params[0]=='N') {
- printf("%5d) %s %s\n", t, op->name, namespace_tostring(c->data[0]));
+ printf("%05d) %s %s\n", t, op->name, namespace_tostring(c->data[0]));
} else {
- printf("%5d) %s\n", t, op->name);
+ printf("%05d) %s\n", t, op->name);
}
c = c->next;
}
- //printf("%5d) %02x\n", t, tag->data[start+t]);
+ //printf("%05d) %02x\n", t, tag->data[start+t]);
#endif
num = 0;
if(stats) {
int f = stats->stack[c->pos].flags;
- fprintf(fo, "%s%5d) %c %d:%d %s ", prefix, c->pos,
+ fprintf(fo, "%s%05d) %c %d:%d %s ", prefix, c->pos,
(f&FLAG_ERROR)?'E':((f&FLAG_SEEN)?'+':'|'),
stats->stack[c->pos].stackpos,
stats->stack[c->pos].scopepos,
op->name);
} else {
- fprintf(fo, "%s%5d) ? ?:? %s ", prefix, c->pos, op->name);
+ fprintf(fo, "%s%05d) ? ?:? %s ", prefix, c->pos, op->name);
}
while(*p) {
{
if(!c) return 0;
- while(c->prev) c = c->prev;
+ dict_t*pos2pos = dict_new2(&ptr_type);
code_t*last = 0;
+ c = code_start(c);
+ code_t*start = 0;
+ char does_branch = 0;
while(c) {
NEW(code_t, n);
memcpy(n, c, sizeof(code_t));
+ if(!start)
+ start=n;
- opcode_t*op = opcode_get(c->opcode);
- if(c->branch || c->opcode == OPCODE_LABEL) {
- fprintf(stderr, "Error: Can't duplicate branching code\n");
- return 0;
+ if(c->opcode == OPCODE_LABEL || c->opcode == OPCODE_NOP) {
+ dict_put(pos2pos, c, n);
}
+ if(c->branch) {
+ does_branch = 1;
+ }
+
+ opcode_t*op = opcode_get(c->opcode);
+
char*p = op?op->params:"";
int pos=0;
while(*p) {
last = n;
c = c->next;
}
+
+ if(does_branch) {
+ c = start;
+ while(c) {
+ if(c->branch) {
+ code_t*target = dict_lookup(pos2pos, c->branch);
+ if(!target) {
+ fprintf(stderr, "Error: Can't find branch target in code_dup\n");
+ return 0;
+ }
+ c->branch = target;
+ }
+ c = c->next;
+ }
+ }
+ dict_destroy(pos2pos);
return last;
}