1
0
mirror of https://github.com/stedolan/jq.git synced 2024-05-11 05:55:39 +00:00

Make a main program that doesn't spam debugging info.

This commit is contained in:
Stephen Dolan
2012-09-10 10:23:15 +01:00
parent e258d20ba2
commit c2593dc417
3 changed files with 23 additions and 12 deletions

View File

@@ -22,7 +22,10 @@ parser.tab.h: parser.tab.c
jv_unicode.c: jv_utf8_tables.h jv_unicode.c: jv_utf8_tables.h
parsertest: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c parsertest: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
$(CC) -o $@ $^ $(CC) -DJQ_DEBUG=1 -o $@ $^
jq: parser.tab.c lexer.yy.c main.c opcode.c bytecode.c compile.c execute.c builtin.c jv.c jv_parse.c jv_print.c jv_dtoa.c jv_unicode.c
$(CC) -DJQ_DEBUG=0 -o $@ $^
jv_test: jv_test.c jv.c jv_print.c jv_dtoa.c jv_test: jv_test.c jv.c jv_print.c jv_dtoa.c
$(CC) -DNO_JANSSON -o $@ $^ $(CC) -DNO_JANSSON -o $@ $^

View File

@@ -148,10 +148,10 @@ jv jq_next() {
int backtracking = 0; int backtracking = 0;
while (1) { while (1) {
uint16_t opcode = *pc;
#if JQ_DEBUG
dump_operation(frame_current_bytecode(&frame_stk), pc); dump_operation(frame_current_bytecode(&frame_stk), pc);
uint16_t opcode = *pc++;
printf("\t"); printf("\t");
const struct opcode_description* opdesc = opcode_describe(opcode); const struct opcode_description* opdesc = opcode_describe(opcode);
data_stk_elem* param; data_stk_elem* param;
@@ -167,13 +167,15 @@ jv jq_next() {
printf("<%d>", jv_get_refcnt(param->sv.value)); printf("<%d>", jv_get_refcnt(param->sv.value));
} }
if (backtracking) printf("\t<backtracking>");
printf("\n");
#endif
if (backtracking) { if (backtracking) {
printf("\t<backtracking>");
opcode = ON_BACKTRACK(opcode); opcode = ON_BACKTRACK(opcode);
backtracking = 0; backtracking = 0;
} }
pc++;
printf("\n");
switch (opcode) { switch (opcode) {
default: assert(0 && "invalid instruction"); default: assert(0 && "invalid instruction");
@@ -235,9 +237,11 @@ jv jq_next() {
uint16_t v = *pc++; uint16_t v = *pc++;
frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level); frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level);
jv* var = frame_local_var(fp, v); jv* var = frame_local_var(fp, v);
#if JQ_DEBUG
printf("V%d = ", v); printf("V%d = ", v);
jv_dump(jv_copy(*var)); jv_dump(jv_copy(*var));
printf("\n"); printf("\n");
#endif
stack_push(stackval_replace(stack_pop(), jv_copy(*var))); stack_push(stackval_replace(stack_pop(), jv_copy(*var)));
break; break;
} }
@@ -248,9 +252,11 @@ jv jq_next() {
frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level); frame_ptr fp = frame_get_level(&frame_stk, frame_current(&frame_stk), level);
jv* var = frame_local_var(fp, v); jv* var = frame_local_var(fp, v);
stackval val = stack_pop(); stackval val = stack_pop();
#if JQ_DEBUG
printf("V%d = ", v); printf("V%d = ", v);
jv_dump(jv_copy(val.value)); jv_dump(jv_copy(val.value));
printf("\n"); printf("\n");
#endif
jv_free(*var); jv_free(*var);
*var = val.value; *var = val.value;
break; break;
@@ -368,7 +374,6 @@ jv jq_next() {
stackval top = stack_pop(); stackval top = stack_pop();
cfunc_input[0] = top.value; cfunc_input[0] = top.value;
struct cfunction* func = &frame_current_bytecode(&frame_stk)->globals->cfunctions[*pc++]; struct cfunction* func = &frame_current_bytecode(&frame_stk)->globals->cfunctions[*pc++];
printf(" call %s\n", func->name);
func->fptr(cfunc_input, cfunc_output); func->fptr(cfunc_input, cfunc_output);
top.value = cfunc_output[0]; top.value = cfunc_output[0];
stack_push(top); stack_push(top);
@@ -386,7 +391,6 @@ jv jq_next() {
cfunc_input[1] = a; cfunc_input[1] = a;
cfunc_input[2] = b; cfunc_input[2] = b;
struct cfunction* func = &frame_current_bytecode(&frame_stk)->globals->cfunctions[*pc++]; struct cfunction* func = &frame_current_bytecode(&frame_stk)->globals->cfunctions[*pc++];
printf(" call %s\n", func->name);
func->fptr(cfunc_input, cfunc_output); func->fptr(cfunc_input, cfunc_output);
top.value = cfunc_output[0]; top.value = cfunc_output[0];
stack_push(top); stack_push(top);
@@ -450,7 +454,11 @@ void jq_teardown() {
} }
void run_program(struct bytecode* bc) { void run_program(struct bytecode* bc) {
char buf[4096]; #if JQ_DEBUG
dump_disassembly(0, bc);
printf("\n");
#endif
char buf[409600];
fgets(buf, sizeof(buf), stdin); fgets(buf, sizeof(buf), stdin);
jq_init(bc, jv_parse(buf)); jq_init(bc, jv_parse(buf));
jv result; jv result;
@@ -458,6 +466,8 @@ void run_program(struct bytecode* bc) {
jv_dump(result); jv_dump(result);
printf("\n"); printf("\n");
} }
#if JQ_DEBUG
printf("end of results\n"); printf("end of results\n");
#endif
jq_teardown(); jq_teardown();
} }

View File

@@ -88,8 +88,6 @@ int main(int argc, char* argv[]) {
blk = gen_cbinding(&builtins, blk); blk = gen_cbinding(&builtins, blk);
struct bytecode* bc = block_compile(blk); struct bytecode* bc = block_compile(blk);
block_free(blk); block_free(blk);
dump_disassembly(0, bc);
printf("\n");
run_program(bc); run_program(bc);
bytecode_free(bc); bytecode_free(bc);
} }