mem_d(parser);
}
-extern const uint16_t util_crc16_table[];
-static uint16_t stream_crc16(uint16_t old, const char *str)
+static uint16_t progdefs_crc_sum(uint16_t old, const char *str)
{
- printf("%s", str);
- while (*str) {
- old = (old<<8) ^ util_crc16_table[(old >> 8) ^ ((unsigned char)*str)];
- ++str;
- }
+ return util_crc16(old, str, strlen(str));
+}
+
+static void progdefs_crc_file(const char *str)
+{
+ /* write to progdefs.h here */
+}
+
+static uint16_t progdefs_crc_both(uint16_t old, const char *str)
+{
+ old = progdefs_crc_sum(old, str);
+ progdefs_crc_file(str);
return old;
}
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 = progdefs_crc_both(crc, "\n/* file generated by qcc, do not modify */\n\ntypedef struct\n{");
+ crc = progdefs_crc_sum(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");
+ progdefs_crc_file("\tint\tpad;\n");
+ progdefs_crc_file("\tint\tofs_return[3];\n");
+ progdefs_crc_file("\tint\tofs_parm0[3];\n");
+ progdefs_crc_file("\tint\tofs_parm1[3];\n");
+ progdefs_crc_file("\tint\tofs_parm2[3];\n");
+ progdefs_crc_file("\tint\tofs_parm3[3];\n");
+ progdefs_crc_file("\tint\tofs_parm4[3];\n");
+ progdefs_crc_file("\tint\tofs_parm5[3];\n");
+ progdefs_crc_file("\tint\tofs_parm6[3];\n");
+ progdefs_crc_file("\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;
+ case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
+ case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
+ case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
+ case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
default:
- crc = stream_crc16(crc, "\tint\t");
+ crc = progdefs_crc_both(crc, "\tint\t");
break;
}
- crc = stream_crc16(crc, parser->globals[i].name);
- crc = stream_crc16(crc, ";\n");
+ crc = progdefs_crc_both(crc, parser->globals[i].name);
+ crc = progdefs_crc_both(crc, ";\n");
}
- crc = stream_crc16(crc, "} globalvars_t;\n\ntypedef struct\n{\n");
+ crc = progdefs_crc_both(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;
+ case TYPE_FLOAT: crc = progdefs_crc_both(crc, "\tfloat\t"); break;
+ case TYPE_VECTOR: crc = progdefs_crc_both(crc, "\tvec3_t\t"); break;
+ case TYPE_STRING: crc = progdefs_crc_both(crc, "\tstring_t\t"); break;
+ case TYPE_FUNCTION: crc = progdefs_crc_both(crc, "\tfunc_t\t"); break;
default:
- crc = stream_crc16(crc, "\tint\t");
+ crc = progdefs_crc_both(crc, "\tint\t");
break;
}
- crc = stream_crc16(crc, parser->fields[i].name);
- crc = stream_crc16(crc, ";\n");
+ crc = progdefs_crc_both(crc, parser->fields[i].name);
+ crc = progdefs_crc_both(crc, ";\n");
}
- crc = stream_crc16(crc, "} entvars_t;\n\n");
+ crc = progdefs_crc_both(crc, "} entvars_t;\n\n");
-printf("GOT CRC %u\n", crc);
code_crc = crc;
}
0x54DE5729, 0x23D967BF, 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
};
-const uint16_t util_crc16_table[] = {
+static const uint16_t util_crc16_table[] = {
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5,
0x60C6, 0x70E7, 0x8108, 0x9129, 0xA14A, 0xB16B,
0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, 0x1231, 0x0210,
/*
* Implements a CRC function for X worth bits using (uint[X]_t)
* as type. and util_crc[X]_table.
+ * Streamable QCC compatible CRC functions.
*/
#define CRC(X) \
-uint##X##_t util_crc##X(const char *k, int len, const short clamp) { \
- register uint##X##_t h= (uint##X##_t)0xFFFFFFFF; \
+uint##X##_t util_crc##X(uint##X##_t current, const char *k, size_t len) { \
+ register uint##X##_t h= current; \
for (; len; --len, ++k) \
- h = util_crc##X##_table[(h^((unsigned char)*k))&0xFF]^(h>>8); \
- return (~h)%clamp; \
+ h = util_crc##X##_table[(h>>8)^((unsigned char)*k)]^(h<<8); \
+ return h; \
}
CRC(32)
CRC(16)