Module diag
:- use_module(library(diag)).
Diagnostics library
The predicate wam_instructions/2
decompiles a predicate so that we can inspect its Warren Abstract Machine (WAM) instructions. In this way, we can verify and reason about compiled programs, and detect opportunities for optimization.
For example, we have:
?- use_module(library(lists)).
true.
?- use_module(library(diag)).
true.
?- use_module(library(format)).
true.
?- wam_instructions(append/3, Is),
maplist(portray_clause, Is).
switch_on_term(1,external(1),external(2),external(6),fail).
try_me_else(4).
get_constant(level(shallow),[],x(1)).
get_value(x(2),3).
proceed.
trust_me(0).
get_list(level(shallow),x(1)).
unify_variable(x(4)).
unify_variable(x(1)).
get_list(level(shallow),x(3)).
unify_value(x(4)).
unify_variable(x(3)).
execute(append,3).
Is = [switch_on_term(1,external(1),external(2),external(6),fail)|...].
wam_instructions(+PI, -Instrs)
Instrs are the WAM instructions corresponding to predicate indicator PI.