support debugging of compiler-level instructions.

This commit is contained in:
Vítor Santos Costa 2014-05-22 21:57:54 +01:00
parent 3310a904c4
commit b7c05b49e2
4 changed files with 297 additions and 149 deletions

View File

@ -3685,7 +3685,7 @@ do_pass(int pass_no, yamop **entry_codep, int assembling, int *clause_has_blobsp
case count_retry_op: case count_retry_op:
code_p = a_pl(_count_retry, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no); code_p = a_pl(_count_retry, (PredEntry *)(cip->cpc->rnd1), code_p, pass_no);
break; break;
case fetch_args_for_bccall: case fetch_args_for_bccall_op:
if (cip->cpc->nextInst->op != bccall_op) { if (cip->cpc->nextInst->op != bccall_op) {
Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "compiling binary test", (int) cip->cpc->op); Yap_Error(INTERNAL_COMPILER_ERROR, TermNil, "compiling binary test", (int) cip->cpc->op);
save_machine_regs(); save_machine_regs();

View File

@ -447,7 +447,7 @@ c_var(Term t, Int argno, unsigned int arity, unsigned int level, compiler_struct
} }
break; break;
case bt1_flag: case bt1_flag:
Yap_emit(fetch_args_for_bccall, t, 0, &cglobs->cint); Yap_emit(fetch_args_for_bccall_op, t, 0, &cglobs->cint);
break; break;
case bt2_flag: case bt2_flag:
Yap_emit(bccall_op, t, (CELL)cglobs->current_p0, &cglobs->cint); Yap_emit(bccall_op, t, (CELL)cglobs->current_p0, &cglobs->cint);
@ -2196,7 +2196,7 @@ usesvar(compiler_vm_op ic)
case save_pair_op: case save_pair_op:
case f_val_op: case f_val_op:
case f_var_op: case f_var_op:
case fetch_args_for_bccall: case fetch_args_for_bccall_op:
case bccall_op: case bccall_op:
return TRUE; return TRUE;
default: default:
@ -2963,7 +2963,7 @@ c_layout(compiler_struct *cglobs)
case unify_s_var_op: case unify_s_var_op:
case unify_s_val_op: case unify_s_val_op:
#endif #endif
case fetch_args_for_bccall: case fetch_args_for_bccall_op:
case bccall_op: case bccall_op:
checktemp(arg, rn, ic, cglobs); checktemp(arg, rn, ic, cglobs);
break; break;

View File

@ -67,7 +67,7 @@ static char SccsId[] = "%W% %G%";
#endif #endif
#ifdef DEBUG #ifdef DEBUG
static void ShowOp(char *, struct PSEUDO *); static void ShowOp(const char *, struct PSEUDO *);
#endif /* DEBUG */ #endif /* DEBUG */
/* /*
@ -446,7 +446,7 @@ write_functor(Functor f)
} }
static void static void
ShowOp (char *f, struct PSEUDO *cpc) ShowOp (const char *f, struct PSEUDO *cpc)
{ {
char ch; char ch;
Int arg = cpc->rnd1; Int arg = cpc->rnd1;
@ -468,6 +468,7 @@ ShowOp (char *f, struct PSEUDO *cpc)
#endif #endif
case 'a': case 'a':
case 'n': case 'n':
case 'S':
Yap_DebugPlWrite ((Term) arg); Yap_DebugPlWrite ((Term) arg);
break; break;
case 'b': case 'b':
@ -666,143 +667,286 @@ ShowOp (char *f, struct PSEUDO *cpc)
Yap_DebugErrorPutc ('\n'); Yap_DebugErrorPutc ('\n');
} }
static char *opformat[] = static const char *
{ getFormat(compiler_vm_op ic) {
"nop", switch( ic ) {
"get_var\t\t%v,%r", case nop_op:
"put_var\t\t%v,%r", return "nop";
"get_val\t\t%v,%r", case get_var_op:
"put_val\t\t%v,%r", return "get_var\t\t%v,%r";
"get_atom\t%a,%r", case put_var_op:
"put_atom\t%a,%r", return "put_var\t\t%v,%r";
"get_num\t\t%n,%r", case get_val_op:
"put_num\t\t%n,%r", return "get_val\t\t%v,%r";
"get_float\t\t%w,%r", case put_val_op:
"put_float\t\t%w,%r", return "put_val\t\t%v,%r";
"get_dbterm\t%w,%r", case get_atom_op:
"put_dbterm\t%w,%r", return "get_atom\t%a,%r";
"get_longint\t\t%w,%r", case put_atom_op:
"put_longint\t\t%w,%r", return "put_atom\t%a,%r";
"get_bigint\t\t%l,%r", case get_num_op:
"put_bigint\t\t%l,%r", return "get_num\t\t%n,%r";
"get_list\t%r", case put_num_op:
"put_list\t%r", return "put_num\t\t%n,%r";
"get_struct\t%f,%r", case get_float_op:
"put_struct\t%f,%r", return "get_float\t\t%w,%r";
"put_unsafe\t%v,%r", case put_float_op:
"unify_var\t%v", return "put_float\t\t%w,%r";
"write_var\t%v", case get_string_op:
"unify_val\t%v", return "get_string\t\t%w,%S";
"write_val\t%v", case put_string_op:
"unify_atom\t%a", return "put_string\t\t%w,%S";
"write_atom\t%a", case get_dbterm_op:
"unify_num\t%n", return "get_dbterm\t%w,%r";
"write_num\t%n", case put_dbterm_op:
"unify_float\t%w", return "put_dbterm\t%w,%r";
"write_float\t%w", case get_longint_op:
"unify_dbterm\t%w", return "get_longint\t\t%w,%r";
"write_dbterm\t%w", case put_longint_op:
"unify_longint\t%w", return "put_longint\t\t%w,%r";
"write_longint\t%w", case get_bigint_op:
"unify_bigint\t%l", return "get_bigint\t\t%l,%r";
"write_bigint\t%l", case put_bigint_op:
"unify_list", return "put_bigint\t\t%l,%r";
"write_list", case get_list_op:
"unify_struct\t%f", return "get_list\t%r";
"write_struct\t%f", case put_list_op:
"write_unsafe\t%v", return "put_list\t%r";
"unify_local\t%v", case get_struct_op:
"write local\t%v", return "get_struct\t%f,%r";
"unify_last_list", case put_struct_op:
"write_last_list", return "put_struct\t%f,%r";
"unify_last_struct\t%f", case put_unsafe_op:
"write_last_struct\t%f", return "put_unsafe\t%v,%r";
"unify_last_var\t%v", case unify_var_op:
"unify_last_val\t%v", return "unify_var\t%v";
"unify_last_local\t%v", case write_var_op:
"unify_last_atom\t%a", return "write_var\t%v";
"unify_last_num\t%n", case unify_val_op:
"unify_last_float\t%w", return "unify_val\t%v";
"unify_last_dbterm\t%w", case write_val_op:
"unify_last_longint\t%w", return "write_val\t%v";
"unify_last_bigint\t%l", case unify_atom_op:
"ensure_space", return "unify_atom\t%a";
"native_code", case write_atom_op:
"function_to_var\t%v,%B", return "write_atom\t%a";
"function_to_val\t%v,%B", case unify_num_op:
"function_to_0\t%B", return "unify_num\t%n";
"align_float", case write_num_op:
"fail", return "write_num\t%n";
"cut", case unify_float_op:
"cutexit", return "unify_float\t%w";
"allocate", case write_float_op:
"deallocate", return "write_float\t%w";
"try_me_else\t\t%l\t%x", case unify_string_op:
"jump\t\t%l", return "unify_string\t%S";
"jump\t\t%l", case write_string_op:
"proceed", return "write_string\t%S";
"call\t\t%p,%d,%z", case unify_dbterm_op:
"execute\t\t%p", return "unify_dbterm\t%w";
"sys\t\t%p", case write_dbterm_op:
"%l:", return "write_dbterm\t%w";
"name\t\t%m,%d", case unify_longint_op:
"pop\t\t%l", return "unify_longint\t%w";
"retry_me_else\t\t%l\t%x", case write_longint_op:
"trust_me_else_fail\t%x", return "write_longint\t%w";
"either_me\t\t%l,%d,%z", case unify_bigint_op:
"or_else\t\t%l,%z", return "unify_bigint\t%l";
"or_last", case write_bigint_op:
"push_or", return "write_bigint\t%l";
"pushpop_or", case unify_list_op:
"pop_or", return "unify_list";
"save_by\t\t%v", case write_list_op:
"commit_by\t\t%v", return "write_list";
"patch_by\t\t%v", case unify_struct_op:
"try\t\t%g\t%x", return "unify_struct\t%f";
"retry\t\t%g\t%x", case write_struct_op:
"trust\t\t%g\t%x", return "write_struct\t%f";
"try_in\t\t%g\t%x", case write_unsafe_op:
"jump_if_var\t\t%g", return "write_unsafe\t%v";
"jump_if_nonvar\t\t%g", case unify_local_op:
"cache_arg\t%r", return "unify_local\t%v";
"cache_sub_arg\t%d", case write_local_op:
"user_index", return "write local\t%v";
"switch_on_type\t%h\t%h\t%h\t%h", case unify_last_list_op:
"switch_on_constant\t%i\n%c", return "unify_last_list";
"if_constant\t%i\n%c", case write_last_list_op:
"switch_on_functor\t%i\n%e", return "write_last_list";
"if_functor\t%i\n%e", case unify_last_struct_op:
"if_not_then\t%i\t%h\t%h\t%h", return "unify_last_struct\t%f";
"index_on_dbref", case write_last_struct_op:
"index_on_blob", return "write_last_struct\t%f";
"index_on_long", case unify_last_var_op:
"check_var\t %r", return "unify_last_var\t%v";
"save_pair\t%v", case unify_last_val_op:
"save_appl\t%v", return "unify_last_val\t%v";
"pvar_bitmap\t%l,%b", case unify_last_local_op:
"pvar_live_regs\t%l,%b", return "unify_last_local\t%v";
"fetch_reg1_reg2\t%N,%N", case unify_last_atom_op:
"fetch_constant_reg\t%l,%N", return "unify_last_atom\t%a";
"fetch_reg_constant\t%l,%N", case unify_last_num_op:
"fetch_integer_reg\t%d,%N", return "unify_last_num\t%n";
"fetch_reg_integer\t%d,%N", case unify_last_float_op:
"enter_profiling\t\t%g", return "unify_last_float\t%w";
"retry_profiled\t\t%g", case unify_last_string_op:
"count_call_op\t\t%g", return "unify_last_string\t%S";
"count_retry_op\t\t%g", case unify_last_dbterm_op:
"restore_temps\t\t%l", return "unify_last_dbterm\t%w";
"restore_temps_and_skip\t\t%l", case unify_last_longint_op:
"enter_lu", return "unify_last_longint\t%w";
"empty_call\t\t%l,%d", case unify_last_bigint_op:
return "unify_last_bigint\t%l";
case ensure_space_op:
return "ensure_space";
case native_op:
return "native_code";
case f_var_op:
return "function_to_var\t%v,%B";
case f_val_op:
return "function_to_val\t%v,%B";
case f_0_op:
return "function_to_0\t%B";
case align_float_op:
return "align_float";
case fail_op:
return "fail";
case cut_op:
return "cut";
case cutexit_op:
return "cutexit";
case allocate_op:
return "allocate";
case deallocate_op:
return "deallocate";
case tryme_op:
return "try_me_else\t\t%l\t%x";
case jump_op:
return "jump\t\t%l";
case jumpi_op:
return "jump_in_indexing\t\t%i";
case procceed_op:
return "proceed";
case call_op:
return "call\t\t%p,%d,%z";
case execute_op:
return "execute\t\t%p";
case safe_call_op:
return "sys\t\t%p";
case label_op:
return "%l:";
case name_op:
return "name\t\t%m,%d";
case pop_op:
return "pop\t\t%l";
case retryme_op:
return "retry_me_else\t\t%l\t%x";
case trustme_op:
return "trust_me_else_fail\t%x";
case either_op:
return "either_me\t\t%l,%d,%z";
case orelse_op:
return "or_else\t\t%l,%z";
case orlast_op:
return "or_last";
case push_or_op:
return "push_or";
case pop_or_op:
return "pop_or";
case pushpop_or_op:
return "pushpop_or";
case save_b_op:
return "save_by\t\t%v";
case commit_b_op:
return "commit_by\t\t%v";
case patch_b_op:
return "patch_by\t\t%v";
case try_op:
return "try\t\t%g\t%x";
case retry_op:
return "retry\t\t%g\t%x";
case trust_op:
return "trust\t\t%g\t%x";
case try_in_op:
return "try_in\t\t%g\t%x";
case jump_v_op:
return "jump_if_var\t\t%g";
case jump_nv_op:
return "jump_if_nonvar\t\t%g";
case cache_arg_op:
return "cache_arg\t%r";
case cache_sub_arg_op:
return "cache_sub_arg\t%d";
case user_switch_op:
return "user_switch";
case switch_on_type_op:
return "switch_on_type\t%h\t%h\t%h\t%h";
case switch_c_op:
return "switch_on_constant\t%i\n%c";
case if_c_op:
return "if_constant\t%i\n%c";
case switch_f_op:
return "switch_on_functor\t%i\n%e";
case if_f_op:
return "if_functor\t%i\n%e";
case if_not_op:
return "if_not_then\t%i\t%h\t%h\t%h";
case index_dbref_op:
return "index_on_dbref";
case index_blob_op:
return "index_on_blob";
case index_long_op:
return "index_on_blob";
case index_string_op:
return "index_on_string";
case if_nonvar_op:
return "check_var\t %r";
case save_pair_op:
return "save_pair\t%v";
case save_appl_op:
return "save_appl\t%v";
case mark_initialised_pvars_op:
return "pvar_bitmap\t%l,%b";
case mark_live_regs_op:
return "pvar_live_regs\t%l,%b";
case fetch_args_vv_op:
return "fetch_reg1_reg2\t%N,%N";
case fetch_args_cv_op:
return "fetch_constant_reg\t%l,%N";
case fetch_args_vc_op:
return "fetch_reg_constant\t%l,%N";
case fetch_args_iv_op:
return "fetch_integer_reg\t%d,%N";
case fetch_args_vi_op:
return "fetch_reg_integer\t%d,%N";
case enter_profiling_op:
return "enter_profiling\t\t%g";
case retry_profiled_op:
return "retry_profiled\t\t%g";
case count_call_op:
return "count_call_op\t\t%g";
case count_retry_op:
return "count_retry_op\t\t%g";
case restore_tmps_op:
return "restore_temps\t\t%l";
case restore_tmps_and_skip_op:
return "restore_temps_and_skip\t\t%l";
case enter_lu_op:
return "enter_lu";
case empty_call_op:
return "empty_call\t\t%l,%d";
#ifdef YAPOR #ifdef YAPOR
"sync", case sync_op:
return "sync";
#endif /* YAPOR */ #endif /* YAPOR */
#ifdef TABLING #ifdef TABLING
"table_new_answer", case table_new_answer_op:
"table_try_single\t%g\t%x", return "table_new_answer";
case table_try_single_op:
return "table_try_single\t%g\t%x";
#endif /* TABLING */ #endif /* TABLING */
#ifdef TABLING_INNER_CUTS #ifdef TABLING_INNER_CUTS
"clause_with_cut", case "clause_with_cut":
return clause_with_cut_op;
#endif /* TABLING_INNER_CUTS */ #endif /* TABLING_INNER_CUTS */
#ifdef BEAM #ifdef BEAM
"run_op %1,%4", "run_op %1,%4",
@ -828,10 +972,16 @@ static char *opformat[] =
"equal_op", "equal_op",
"exit", "exit",
#endif #endif
"fetch_args_for_bccall\t%v", case fetch_args_for_bccall_op:
"binary_cfunc\t\t%v,%P", return "fetch_args_for_bccall\t%v";
"blob\t%O", case bccall_op:
"label_control\t" return "binary_cfunc\t\t%v,%P";
case blob_op:
return "blob\t%O";
case string_op:
return "string\t%O";
case label_ctl_op:
return "label_control\t";
#ifdef SFUNC #ifdef SFUNC
, ,
"get_s_f_op\t%f,%r", "get_s_f_op\t%f,%r",
@ -849,14 +999,13 @@ static char *opformat[] =
"unify_s_end", "unify_s_end",
"write_s_end" "write_s_end"
#endif #endif
}; }
}
void void
Yap_ShowCode (struct intermediates *cint) Yap_ShowCode (struct intermediates *cint)
{ {
CACHE_REGS CACHE_REGS
CELL *oldH = HR;
struct PSEUDO *cpc; struct PSEUDO *cpc;
cpc = cint->CodeStart; cpc = cint->CodeStart;
@ -865,12 +1014,11 @@ Yap_ShowCode (struct intermediates *cint)
while (cpc) { while (cpc) {
compiler_vm_op ic = cpc->op; compiler_vm_op ic = cpc->op;
if (ic != nop_op) { if (ic != nop_op) {
ShowOp (opformat[ic], cpc);
} }
ShowOp (getFormat(ic), cpc);
cpc = cpc->nextInst; cpc = cpc->nextInst;
} }
Yap_DebugErrorPutc ('\n'); Yap_DebugErrorPutc ('\n');
HR = oldH;
} }
#endif /* DEBUG */ #endif /* DEBUG */

View File

@ -185,7 +185,7 @@ typedef enum compiler_op {
equal_op, equal_op,
exit_op, exit_op,
#endif #endif
fetch_args_for_bccall, fetch_args_for_bccall_op,
bccall_op, bccall_op,
blob_op, blob_op,
string_op, string_op,