option: -force-crc=number, added -info to executor to just show some file info like the crc, and -printfields to print a list of fields along with their type and position

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-22 14:00:57 +02:00
parent 330a801ae9
commit 93e13c3cb1
4 changed files with 66 additions and 5 deletions

5
code.c
View file

@ -183,7 +183,10 @@ bool code_write(const char *filename) {
code_header.strings.offset = code_header.globals.offset + (sizeof(int32_t) * code_globals_elements);
code_header.strings.length = code_chars_elements;
code_header.version = 6;
code_header.crc16 = 0; /* TODO: */
if (opts_forcecrc)
code_header.crc16 = opts_forced_crc;
else
code_header.crc16 = 0; /* TODO: */
code_header.entfield = code_entfields;
if (OPTS_FLAG(DARKPLACES_STRING_TABLE_BUG)) {

53
exec.c
View file

@ -80,6 +80,7 @@ qc_program* prog_load(const char *filename)
memset(prog, 0, sizeof(*prog));
prog->entityfields = header.entfield;
prog->crc16 = header.crc16;
prog->filename = util_strdup(filename);
if (!prog->filename) {
@ -606,6 +607,21 @@ cleanup:
*/
#if defined(QCVM_EXECUTOR)
const char *type_name[TYPE_COUNT] = {
"void",
"string",
"float",
"vector",
"entity",
"field",
"function",
"pointer",
#if 0
"integer",
#endif
"variant"
};
bool opts_debug = false;
bool opts_memchk = false;
@ -686,6 +702,8 @@ int main(int argc, char **argv)
qcint fnmain = -1;
qc_program *prog;
size_t xflags = VMXF_DEFAULT;
bool opts_printfields = false;
bool opts_info = false;
arg0 = argv[0];
@ -703,6 +721,16 @@ int main(int argc, char **argv)
++argv;
xflags |= VMXF_PROFILE;
}
else if (!strcmp(argv[1], "-info")) {
--argc;
++argv;
opts_info = true;
}
else if (!strcmp(argv[1], "-printfields")) {
--argc;
++argv;
opts_printfields = true;
}
else
usage();
}
@ -718,6 +746,8 @@ int main(int argc, char **argv)
prog->builtins_count = qc_builtins_count;
prog->builtins_alloc = 0;
printf("Program's system-checksum = 0x%04x\n", (int)prog->crc16);
for (i = 1; i < prog->functions_count; ++i) {
const char *name = prog_getstring(prog, prog->functions[i].name);
/* printf("Found function: %s\n", name); */
@ -725,12 +755,27 @@ int main(int argc, char **argv)
fnmain = (qcint)i;
}
printf("Entity field space: %i\n", (int)prog->entityfields);
if (fnmain > 0)
{
prog_exec(prog, &prog->functions[fnmain], xflags, VM_JUMPS_DEFAULT);
if (opts_info) {
prog_delete(prog);
return 0;
}
if (opts_printfields) {
for (i = 0; i < prog->fields_count; ++i) {
printf("Field: %8s %-16s at %u\n",
type_name[prog->fields[i].type],
prog_getstring(prog, prog->fields[i].name),
(unsigned int)prog->fields[i].offset);
}
}
else
printf("No main function found\n");
{
if (fnmain > 0)
{
prog_exec(prog, &prog->functions[fnmain], xflags, VM_JUMPS_DEFAULT);
}
else
printf("No main function found\n");
}
prog_delete(prog);
return 0;

View file

@ -860,6 +860,8 @@ typedef struct qc_program_s {
MEM_VECTOR_MAKE(qcint, entitydata);
MEM_VECTOR_MAKE(bool, entitypool);
uint16_t crc16;
size_t tempstring_start;
size_t tempstring_at;
@ -994,6 +996,8 @@ extern bool opts_debug;
extern bool opts_memchk;
extern bool opts_dump;
extern bool opts_werror;
extern bool opts_forcecrc;
extern uint16_t opts_forced_crc;
/*===================================================================*/
#define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32))))

9
main.c
View file

@ -33,6 +33,9 @@ bool opts_debug = false;
bool opts_memchk = false;
bool opts_dump = false;
bool opts_werror = false;
bool opts_forcecrc = false;
uint16_t opts_forced_crc;
static bool opts_output_wasset = false;
@ -63,6 +66,7 @@ static int usage() {
printf(" -W<warning> enable a warning\n"
" -Wno-<warning> disable a warning\n"
" -Wall enable all warnings\n");
printf(" -force-crc=num force a specific checksum into the header\n");
printf("\n");
printf("flags:\n"
" -fdarkplaces-string-table-bug\n"
@ -180,6 +184,11 @@ static bool options_parse(int argc, char **argv) {
}
continue;
}
if (options_long_gcc("force-crc", &argc, &argv, &argarg)) {
opts_forcecrc = true;
opts_forced_crc = strtol(argarg, NULL, 0);
continue;
}
if (!strcmp(argv[0]+1, "debug")) {
opts_debug = true;
continue;