X-Git-Url: https://git.xonotic.org/?a=blobdiff_plain;f=code.c;h=42a55959ff131282d48ab71250087970cecb78ae;hb=c9e3c29a259eeb8e1684993a30d2a06a153f5265;hp=ca6c3ad655db3b3d8be74e78c52d8bd34c2d181e;hpb=f9b1d057b5247f2ecbaa7259ed1b7bcb56e45922;p=xonotic%2Fgmqcc.git diff --git a/code.c b/code.c index ca6c3ad..42a5595 100644 --- a/code.c +++ b/code.c @@ -39,6 +39,12 @@ void code_push_statement(prog_section_statement *stmt, int linenum) vec_push(code_linenums, linenum); } +void code_pop_statement() +{ + vec_pop(code_statements); + vec_pop(code_linenums); +} + void code_init() { prog_section_function empty_function = {0,0,0,0,0,0,0,{0}}; prog_section_statement empty_statement = {0,{0},{0},{0}}; @@ -128,6 +134,22 @@ bool code_write(const char *filename, const char *lnofile) { vec_push(code_chars, '\0'); /* P */ } + /* ensure all data is in LE format */ + util_endianswap(&code_header.version, 1, sizeof(code_header.version)); + util_endianswap(&code_header.crc16, 1, sizeof(code_header.crc16)); + util_endianswap(&code_header.statements, 2, sizeof(code_header.statements.offset)); + util_endianswap(&code_header.defs, 2, sizeof(code_header.statements.offset)); + util_endianswap(&code_header.fields, 2, sizeof(code_header.statements.offset)); + util_endianswap(&code_header.functions, 2, sizeof(code_header.statements.offset)); + util_endianswap(&code_header.strings, 2, sizeof(code_header.statements.offset)); + util_endianswap(&code_header.globals, 2, sizeof(code_header.statements.offset)); + util_endianswap(&code_header.entfield, 1, sizeof(code_header.entfield)); + util_endianswap(code_statements, vec_size(code_statements), sizeof(prog_section_statement)); + util_endianswap(code_defs, vec_size(code_defs), sizeof(prog_section_def)); + util_endianswap(code_fields, vec_size(code_fields), sizeof(prog_section_field)); + util_endianswap(code_functions, vec_size(code_functions), sizeof(prog_section_function)); + util_endianswap(code_globals, vec_size(code_globals), sizeof(int32_t)); + if (lnofile) { uint32_t lnotype = *(unsigned int*)"LNOF"; uint32_t version = 1; @@ -136,6 +158,9 @@ bool code_write(const char *filename, const char *lnofile) { if (!fp) return false; + util_endianswap(&version, 1, sizeof(version)); + util_endianswap(code_linenums, vec_size(code_linenums), sizeof(code_linenums[0])); + if (fwrite(&lnotype, sizeof(lnotype), 1, fp) != 1 || fwrite(&version, sizeof(version), 1, fp) != 1 || fwrite(&code_header.defs.length, sizeof(code_header.defs.length), 1, fp) != 1 || @@ -151,14 +176,6 @@ bool code_write(const char *filename, const char *lnofile) { fp = NULL; } - /* ensure all data is in LE format */ - util_endianswap(&code_header, 1, sizeof(prog_header)); - util_endianswap(code_statements, vec_size(code_statements), sizeof(prog_section_statement)); - util_endianswap(code_defs, vec_size(code_defs), sizeof(prog_section_def)); - util_endianswap(code_fields, vec_size(code_fields), sizeof(prog_section_field)); - util_endianswap(code_functions, vec_size(code_functions), sizeof(prog_section_function)); - util_endianswap(code_globals, vec_size(code_globals), sizeof(int32_t)); - fp = util_fopen(filename, "wb"); if (!fp) return false; @@ -213,7 +230,7 @@ bool code_write(const char *filename, const char *lnofile) { if (code_functions[it].entry >= 0) { util_debug("GEN", " CODE:\n"); for (;;) { - if (code_statements[j].opcode != AINSTR_END) + if (code_statements[j].opcode != INSTR_DONE) util_debug("GEN", " %-12s {% 5i,% 5i,% 5i}\n", asm_instr[code_statements[j].opcode].m, code_statements[j].o1.s1, @@ -230,6 +247,7 @@ bool code_write(const char *filename, const char *lnofile) { } vec_free(code_statements); + vec_free(code_linenums); vec_free(code_defs); vec_free(code_fields); vec_free(code_functions);