*/
typedef union {
void *enter;
- qcint_t leave;
+ qcint_t leave;
} code_hash_entry_t;
/* Some sanity macros */
}
}
+
if (OPTS_FLAG(SORT_OPERANDS)) {
+ uint16_t pair;
+
switch (stmt.opcode) {
-#define SINGLE(a) \
- case INSTR_##a: \
- if (stmt.o1.u1 < stmt.o2.u1) { \
- uint16_t x = stmt.o1.u1; stmt.o1.u1 = stmt.o2.u1; stmt.o2.u1 = x; \
- } \
- break
-#define PAIR(a,b) \
- case INSTR_##a: \
- if (stmt.o1.u1 < stmt.o2.u1) { \
- uint16_t x = stmt.o1.u1; stmt.o1.u1 = stmt.o2.u1; stmt.o2.u1 = x; \
- stmt.opcode = INSTR_##b; \
- } \
- break; \
- case INSTR_##b: \
- if (stmt.o1.u1 < stmt.o2.u1) { \
- uint16_t x = stmt.o1.u1; stmt.o1.u1 = stmt.o2.u1; stmt.o2.u1 = x; \
- stmt.opcode = INSTR_##a; \
- } \
- break
- PAIR(MUL_VF, MUL_FV);
- PAIR(LT, GT);
- PAIR(LE, GE);
- SINGLE(MUL_F);
- SINGLE(MUL_V);
- SINGLE(ADD_F);
- SINGLE(ADD_V);
- SINGLE(EQ_F);
- SINGLE(EQ_V);
- SINGLE(EQ_S);
- SINGLE(EQ_E);
- SINGLE(EQ_FNC);
- SINGLE(NE_F);
- SINGLE(NE_V);
- SINGLE(NE_S);
- SINGLE(NE_E);
- SINGLE(NE_FNC);
- SINGLE(AND);
- SINGLE(OR);
- SINGLE(BITAND);
- SINGLE(BITOR);
-#undef PAIR
-#undef SINGLE
+ case INSTR_MUL_F:
+ case INSTR_MUL_V:
+ case INSTR_ADD_F:
+ case INSTR_EQ_F:
+ case INSTR_EQ_S:
+ case INSTR_EQ_E:
+ case INSTR_EQ_FNC:
+ case INSTR_NE_F:
+ case INSTR_NE_V:
+ case INSTR_NE_S:
+ case INSTR_NE_E:
+ case INSTR_NE_FNC:
+ case INSTR_AND:
+ case INSTR_OR:
+ case INSTR_BITAND:
+ case INSTR_BITOR:
+ if (stmt.o1.u1 < stmt.o2.u1) {
+ uint16_t a = stmt.o2.u1;
+ stmt.o1.u1 = stmt.o2.u1;
+ stmt.o2.u1 = a;
+ }
+ break;
+
+ case INSTR_MUL_VF: pair = INSTR_MUL_FV; goto case_pair_gen;
+ case INSTR_MUL_FV: pair = INSTR_MUL_VF; goto case_pair_gen;
+ case INSTR_LT: pair = INSTR_GT; goto case_pair_gen;
+ case INSTR_GT: pair = INSTR_LT; goto case_pair_gen;
+ case INSTR_LE: pair = INSTR_GT; goto case_pair_gen;
+ case INSTR_GE: pair = INSTR_LE;
+
+ case_pair_gen:
+ if (stmt.o1.u1 < stmt.o2.u1) {
+ uint16_t x = stmt.o1.u1;
+ stmt.o1.u1 = stmt.o2.u1;
+ stmt.o2.u1 = x;
+ stmt.opcode = pair;
+ }
+ break;
}
}
code_header->entfield = code->entfields;
if (OPTS_FLAG(DARKPLACES_STRING_TABLE_BUG)) {
- util_debug("GEN", "Patching stringtable for -fdarkplaces-stringtablebug\n");
-
/* >= + P */
vec_push(code->chars, '\0'); /* > */
vec_push(code->chars, '\0'); /* = */
bool code_write(code_t *code, const char *filename, const char *lnofile) {
prog_header_t code_header;
- FILE *fp = NULL;
- size_t it = 2;
+ fs_file_t *fp = NULL;
code_create_header(code, &code_header, filename, lnofile);
return false;
}
- util_debug("GEN","HEADER:\n");
- util_debug("GEN"," version: = %d\n", code_header.version );
- util_debug("GEN"," crc16: = %d\n", code_header.crc16 );
- util_debug("GEN"," entfield: = %d\n", code_header.entfield);
- util_debug("GEN"," statements = {.offset = % 8d, .length = % 8d}\n", code_header.statements.offset, code_header.statements.length);
- util_debug("GEN"," defs = {.offset = % 8d, .length = % 8d}\n", code_header.defs .offset, code_header.defs .length);
- util_debug("GEN"," fields = {.offset = % 8d, .length = % 8d}\n", code_header.fields .offset, code_header.fields .length);
- util_debug("GEN"," functions = {.offset = % 8d, .length = % 8d}\n", code_header.functions .offset, code_header.functions .length);
- util_debug("GEN"," globals = {.offset = % 8d, .length = % 8d}\n", code_header.globals .offset, code_header.globals .length);
- util_debug("GEN"," strings = {.offset = % 8d, .length = % 8d}\n", code_header.strings .offset, code_header.strings .length);
-
- /* FUNCTIONS */
- util_debug("GEN", "FUNCTIONS:\n");
- for (; it < vec_size(code->functions); it++) {
- size_t j = code->functions[it].entry;
- util_debug("GEN", " {.entry =% 5d, .firstlocal =% 5d, .locals =% 5d, .profile =% 5d, .name =% 5d, .file =% 5d, .nargs =% 5d, .argsize ={%d,%d,%d,%d,%d,%d,%d,%d} }\n",
- code->functions[it].entry,
- code->functions[it].firstlocal,
- code->functions[it].locals,
- code->functions[it].profile,
- code->functions[it].name,
- code->functions[it].file,
- code->functions[it].nargs,
- code->functions[it].argsize[0],
- code->functions[it].argsize[1],
- code->functions[it].argsize[2],
- code->functions[it].argsize[3],
- code->functions[it].argsize[4],
- code->functions[it].argsize[5],
- code->functions[it].argsize[6],
- code->functions[it].argsize[7]
-
- );
- util_debug("GEN", " NAME: %s\n", &code->chars[code->functions[it].name]);
- /* Internal functions have no code */
- if (code->functions[it].entry >= 0) {
- util_debug("GEN", " CODE:\n");
- for (;;) {
- if (code->statements[j].opcode != INSTR_DONE)
- util_debug("GEN", " %-12s {% 5i,% 5i,% 5i}\n",
- util_instr_str[code->statements[j].opcode],
- code->statements[j].o1.s1,
- code->statements[j].o2.s1,
- code->statements[j].o3.s1
- );
- else {
- util_debug("GEN", " DONE {0x00000,0x00000,0x00000}\n");
- break;
- }
- j++;
- }
- }
- }
-
fs_file_close(fp);
code_stats(filename, lnofile, code, &code_header);
return true;