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)
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;
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;
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);
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,