Initial import/sketch of opcode analyzer (
bug 3279).
Uses single static assignment to recover expression trees from straight-line byte code.
5 #include "decompiler.h"
6 #include "platform_util.h"
8 sp_decomp_t *Sp_InitDecomp(const char *file, int *err)
13 if ((plugin = Sp_ReadPlugin(file, err)) == NULL)
19 memset(dc, 0, sizeof(sp_decomp_t));
21 dc->pcode_map = (cell_t *)malloc(dc->plugin->pcode_size);
22 memset(dc->pcode_map, 0, dc->plugin->pcode_size);
24 #define OPDEF(num,enm,str,prms) \
25 dc->opdef[num].name = str; \
26 dc->opdef[num].params = prms;
27 #include "opcodes.tbl"
33 void Sp_FreeDecomp(sp_decomp_t *decomp)
35 FunctionInfo *info, *info_temp;
40 info_temp = info->next;
45 Sp_FreePlugin(decomp->plugin);
46 free(decomp->pcode_map);
50 PrintBuffer::PrintBuffer() : printbuf(NULL), printbuf_alloc(0), printbuf_pos(0)
54 PrintBuffer::~PrintBuffer()
59 void PrintBuffer::Grow(size_t len)
61 if (printbuf_pos + len > printbuf_alloc)
63 if (printbuf_alloc == 0)
65 printbuf_alloc = len * 8;
69 printbuf_alloc += len;
73 printbuf = (char *)realloc(printbuf, printbuf_alloc);
77 void PrintBuffer::Append(const char *fmt, ...)
84 len = Sp_FormatArgs(buffer, sizeof(buffer), fmt, ap);
89 printbuf = (char *)realloc(printbuf, printbuf_alloc);
90 strcpy(&printbuf[printbuf_pos], buffer);
94 void PrintBuffer::Set(const char *fmt, ...)
101 len = Sp_FormatArgs(buffer, sizeof(buffer), fmt, ap);
107 printbuf = (char *)realloc(printbuf, printbuf_alloc);
108 strcpy(&printbuf[printbuf_pos], buffer);
112 void PrintBuffer::Prepend(const char *fmt, ...)
119 len = Sp_FormatArgs(buffer, sizeof(buffer), fmt, ap);
124 /* Move old data forward. Move one extra byte for the null terminator. */
125 memmove(&printbuf[len], printbuf, printbuf_pos + 1);
127 /* Move the new data in. */
128 memcpy(printbuf, buffer, len);
131 void PrintBuffer::Reset()
136 void PrintBuffer::Dump(FILE *fp)
138 fprintf(fp, "%s", printbuf);