From: Wolfgang (Blub) Bumiller Date: Tue, 2 Oct 2012 15:09:49 +0000 (+0200) Subject: Generating checksums X-Git-Tag: 0.1-rc1~28 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=354dd94b95b764124598d399dbbab140d8e545f6;p=xonotic%2Fgmqcc.git Generating checksums --- diff --git a/code.c b/code.c index bf46cc0..e828ccc 100644 --- a/code.c +++ b/code.c @@ -72,7 +72,6 @@ void code_init() { prog_section_def empty_def = {0, 0, 0}; int i = 0; - code_crc = 0; code_entfields = 0; /* omit creation of null code */ diff --git a/gmqcc.h b/gmqcc.h index 1584633..40f8de0 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -210,7 +210,8 @@ void util_endianswap (void *, int, int); size_t util_strtocmd (const char *, char *, size_t); size_t util_strtononcmd (const char *, char *, size_t); -uint32_t util_crc32(const char *, int, register const short); +uint16_t util_crc16(const char *, int, const short); +uint32_t util_crc32(const char *, int, const short); #ifdef NOTRACK # define mem_a(x) malloc(x) @@ -512,6 +513,7 @@ VECTOR_PROT(prog_section_field, code_fields ); VECTOR_PROT(prog_section_function, code_functions ); VECTOR_PROT(int, code_globals ); VECTOR_PROT(char, code_chars ); +extern uint16_t code_crc; typedef float qcfloat; typedef int32_t qcint; diff --git a/parser.c b/parser.c index 2d13537..9740932 100644 --- a/parser.c +++ b/parser.c @@ -2899,6 +2899,73 @@ void parser_cleanup() mem_d(parser); } +extern const uint16_t util_crc16_table[]; +static uint16_t stream_crc16(uint16_t old, const char *str) +{ + printf("%s", str); + while (*str) { + old = (old<<8) ^ util_crc16_table[(old >> 8) ^ ((unsigned char)*str)]; + ++str; + } + return old; +} + +static void generate_checksum(parser_t *parser) +{ + uint16_t crc = 0xFFFF; + size_t i; + + crc = stream_crc16(crc, "\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{"); + crc = stream_crc16(crc, "\tint\tpad[28];\n"); + /* + crc = stream_crc16(crc, "\tint\tpad;\n"); + crc = stream_crc16(crc, "\tint\tofs_return[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm0[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm1[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm2[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm3[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm4[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm5[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm6[3];\n"); + crc = stream_crc16(crc, "\tint\tofs_parm7[3];\n"); + */ + for (i = 0; i < parser->crc_globals; ++i) { + if (!ast_istype(parser->globals[i].var, ast_value)) + continue; + switch (parser->globals[i].var->expression.vtype) { + case TYPE_FLOAT: crc = stream_crc16(crc, "\tfloat\t"); break; + case TYPE_VECTOR: crc = stream_crc16(crc, "\tvec3_t\t"); break; + case TYPE_STRING: crc = stream_crc16(crc, "\tstring_t\t"); break; + case TYPE_FUNCTION: crc = stream_crc16(crc, "\tfunc_t\t"); break; + default: + crc = stream_crc16(crc, "\tint\t"); + break; + } + crc = stream_crc16(crc, parser->globals[i].name); + crc = stream_crc16(crc, ";\n"); + } + crc = stream_crc16(crc, "} globalvars_t;\n\ntypedef struct\n{\n"); + for (i = 0; i < parser->crc_fields; ++i) { + if (!ast_istype(parser->fields[i].var, ast_value)) + continue; + switch (parser->fields[i].var->expression.next->expression.vtype) { + case TYPE_FLOAT: crc = stream_crc16(crc, "\tfloat\t"); break; + case TYPE_VECTOR: crc = stream_crc16(crc, "\tvec3_t\t"); break; + case TYPE_STRING: crc = stream_crc16(crc, "\tstring_t\t"); break; + case TYPE_FUNCTION: crc = stream_crc16(crc, "\tfunc_t\t"); break; + default: + crc = stream_crc16(crc, "\tint\t"); + break; + } + crc = stream_crc16(crc, parser->fields[i].name); + crc = stream_crc16(crc, ";\n"); + } + crc = stream_crc16(crc, "} entvars_t;\n\n"); + +printf("GOT CRC %u\n", crc); + code_crc = crc; +} + bool parser_finish(const char *output) { size_t i; @@ -2996,6 +3063,8 @@ bool parser_finish(const char *output) if (opts_dump) ir_builder_dump(ir, printf); + generate_checksum(parser); + if (!ir_builder_generate(ir, output)) { printf("*** failed to generate output file\n"); ir_builder_delete(ir); diff --git a/util.c b/util.c index 0456060..3186595 100644 --- a/util.c +++ b/util.c @@ -285,7 +285,7 @@ static const uint32_t util_crc32_table[] = { 0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D }; -static const uint16_t util_crc16_table[] = { +const uint16_t util_crc16_table[] = { 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210,