This patch makes trace a little more useful. It prints the constant
referred to, as well as the value of the register being accessed.
This string reverse program
trace 1
set S0,"Hello world"
set S1,""
set S2,""
length I0,S0
dec I0
$loop: substr S2,S0,I0,1
concat S1,S2
dec I0
ge I0,0,$loop
set S0,S1
end
produces this output (I removed some spaces on PC=16 to stop the word
wrap in my mailer):
PC=2; OP=9 (set_s_sc); ARGS=(S0=(null), "Hello world")
PC=5; OP=9 (set_s_sc); ARGS=(S1=(null), "")
PC=8; OP=9 (set_s_sc); ARGS=(S2=(null), "")
PC=11; OP=115 (length_i_s); ARGS=(I0=0, S0="Hello world")
PC=14; OP=66 (dec_i); ARGS=(I0=11)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="", S0="Hello world", I0=10,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="", S2="d")
PC=24; OP=66 (dec_i); ARGS=(I0=10)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=9, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="d", S0="Hello world", I0=9,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="d", S2="l")
PC=24; OP=66 (dec_i); ARGS=(I0=9)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=8, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="l", S0="Hello world", I0=8,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dl", S2="r")
PC=24; OP=66 (dec_i); ARGS=(I0=8)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=7, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="r", S0="Hello world", I0=7,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlr", S2="o")
PC=24; OP=66 (dec_i); ARGS=(I0=7)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=6, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="o", S0="Hello world", I0=6,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlro", S2="w")
PC=24; OP=66 (dec_i); ARGS=(I0=6)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=5, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="w", S0="Hello world", I0=5,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlrow", S2=" ")
PC=24; OP=66 (dec_i); ARGS=(I0=5)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=4, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2=" ", S0="Hello world", I0=4,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlrow ", S2="o")
PC=24; OP=66 (dec_i); ARGS=(I0=4)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=3, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="o", S0="Hello world", I0=3 1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlrow o", S2="l")
PC=24; OP=66 (dec_i); ARGS=(I0=3)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=2, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="l", S0="Hello world", I0=2,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlrow ol", S2="l")
PC=24; OP=66 (dec_i); ARGS=(I0=2)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=1, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="l", S0="Hello world", I0=1,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlrow oll", S2="e")
PC=24; OP=66 (dec_i); ARGS=(I0=1)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=0, 0, -10)
PC=16; OP=117 (substr_s_s_i_ic); ARGS=(S2="e", S0="Hello world", I0=0,1)
PC=21; OP=110 (concat_s_s); ARGS=(S1="dlrow olle", S2="H")
PC=24; OP=66 (dec_i); ARGS=(I0=0)
PC=26; OP=43 (ge_i_ic_ic); ARGS=(I0=-1, 0, -10)
PC=30; OP=8 (set_s_s); ARGS=(S0="Hello world", S1="dlrow olleH")
PC=33; OP=0 (end)
If it looks reasonable, I'll commit it.
Brian
Index: interpreter.c
===================================================================
RCS file: /home/perlcvs/parrot/interpreter.c,v
retrieving revision 1.29
diff -u -r1.29 interpreter.c
--- interpreter.c 2001/10/14 23:47:39 1.29
+++ interpreter.c 2001/10/17 20:15:42
@@ -81,7 +81,38 @@
fprintf(stderr, "; ARGS=(");
for(i = 1; i < interpreter->opcode_info[*pc].arg_count; i++) {
if (i > 1) { fprintf(stderr, ", "); }
- fprintf(stderr, "%ld", (long) *(pc + i));
+ switch(interpreter->opcode_info[*pc].types[i]) {
+ case PARROT_ARG_IC:
+ fprintf(stderr, "%ld", (long) *(pc + i));
+ break;
+ case PARROT_ARG_NC:
+ fprintf(stderr, "%f", interpreter->code->const_table->constants[*(pc
++ i)]->number);
+ break;
+ case PARROT_ARG_PC:
+ /* what is a PMC constant look like? */
+ fprintf(stderr, "%ld", (long) *(pc + i));
+ break;
+ case PARROT_ARG_SC:
+ fprintf(stderr, "\"%s\"",
+interpreter->code->const_table->constants[*(pc + i)]->string->bufstart);
+ break;
+ case PARROT_ARG_I:
+ fprintf(stderr, "I%ld=%ld", (long) *(pc + i), (long)
+interpreter->int_reg->registers[*(pc + i)]);
+ break;
+ case PARROT_ARG_N:
+ fprintf(stderr, "N%ld=%f", (long) *(pc + i),
+interpreter->num_reg->registers[*(pc + i)]);
+ break;
+ case PARROT_ARG_P:
+ /* what does a PMC constant look like? */
+ fprintf(stderr, "P%ld=???", (long) *(pc + i));
+ break;
+ case PARROT_ARG_S:
+ if(interpreter->string_reg->registers[*(pc + i)]) {
+ fprintf(stderr, "S%ld=\"%s\"", (long) *(pc + i),
+interpreter->string_reg->registers[*(pc + i)]->bufstart);
+ } else {
+ fprintf(stderr, "S%ld=(null)", (long) *(pc + i));
+ }
+ break;
+ }
}
fprintf(stderr, ")");
}
@@ -115,7 +146,38 @@
fprintf(stderr, "; ARGS=(");
for(i = 1; i < interpreter->opcode_info[*pc].arg_count; i++) {
if (i > 1) { fprintf(stderr, ", "); }
- fprintf(stderr, "%ld", (long) *(pc + i));
+ switch(interpreter->opcode_info[*pc].types[i]) {
+ case PARROT_ARG_IC:
+ fprintf(stderr, "%ld", (long) *(pc + i));
+ break;
+ case PARROT_ARG_NC:
+ fprintf(stderr, "%f",
+interpreter->code->const_table->constants[*(pc + i)]->number);
+ break;
+ case PARROT_ARG_PC:
+ /* what is a PMC constant look like? */
+ fprintf(stderr, "%ld", (long) *(pc + i));
+ break;
+ case PARROT_ARG_SC:
+ fprintf(stderr, "\"%s\"",
+interpreter->code->const_table->constants[*(pc + i)]->string->bufstart);
+ break;
+ case PARROT_ARG_I:
+ fprintf(stderr, "I%ld=%ld", (long) *(pc + i), (long)
+interpreter->int_reg->registers[*(pc + i)]);
+ break;
+ case PARROT_ARG_N:
+ fprintf(stderr, "N%ld=%f", (long) *(pc + i),
+interpreter->num_reg->registers[*(pc + i)]);
+ break;
+ case PARROT_ARG_P:
+ /* what does a PMC constant look like? */
+ fprintf(stderr, "P%ld=???", (long) *(pc + i));
+ break;
+ case PARROT_ARG_S:
+ if(interpreter->string_reg->registers[*(pc + i)]) {
+ fprintf(stderr, "S%ld=\"%s\"", (long) *(pc + i),
+interpreter->string_reg->registers[*(pc + i)]->bufstart);
+ } else {
+ fprintf(stderr, "S%ld=(null)", (long) *(pc + i));
+ }
+ break;
+ }
}
fprintf(stderr, ")");
}