I wrote this pile of predicates to use when constructing my new checks.
%% dpl/1 Prints the names for a list of opcodes. dpl([T]) :- op_name(T,N), write(N), nl. dpl([H|T]) :- op_name(H,N), write(N), write(','), dpl(T). %% curcop/2 finds the closest COP node curcop(O, Cop) :- findall(C1, (op_preceding(O,C1), op_name(C1,nextstate)), C2), last(C2,Cop). last([H|T], O) :- T = [] -> O = H; last(T,O). %% Optree primitives op_name( O, N ) :- arg( 1, O, N ). op_flags( O, F ) :- arg( 2, O, F ). op_first( O, O2 ) :- arg( 3, O, O2 ). op_sibling( O, O2 ) :- arg( 4, O, O2 ). %% Some useful optree axes op_following_siblings( Op, Sibling ) :- op_sibling( Op, Sibling ). op_following_siblings( Op, Sibling ) :- op_sibling( Op, Temp ), op_following_siblings( Temp, Sibling ). op_child( Op, Child ) :- op_first( Op, Child ). op_child( Op, Child ) :- op_first( Op, Temp ), op_following_siblings( Temp, Child ). %% op_descendant/2 op_descendant( Op, Descendant ) :- op_child( Op, Descendant ). op_descendant( Op, Descendant ) :- op_child( Op, Temp ), op_descendant( Temp, Descendant ). %% op_descendant/3 op_descendant( Op, [Op], Descendant ) :- op_child( Op, Descendant ). op_descendant( Op, [Op|Rest], Descendant ) :- op_child( Op, Temp ), op_descendant( Temp, Rest, Descendant ). %% op_descendant_or_self/2 op_descendant_or_self( Op, Op ). op_descendant_or_self( Op, Descendant ) :- op_child( Op, Descendant ). op_descendant_or_self( Op, Descendant ) :- op_child( Op, Temp ), op_descendant_or_self( Temp, Descendant ). %% op_descendant_or_self/3 op_descendant_or_self( Op, [], Op ). op_descendant_or_self( Op, [Op], Descendant ) :- op_child( Op, Descendant ). op_descendant_or_self( Op, [Op|Rest], Descendant ) :- op_child( Op, Temp ), op_descendant_or_self( Temp, Rest, Descendant ). %% op_following/2 op_following( Op, Descendant ) :- op_descendant( Op, Descendant ). op_following( Op, Sibling ) :- op_sibling( Op, Sibling ). op_following( Op, SibDesc ) :- op_sibling( Op, Sibling ), op_following( Sibling, SibDesc ). %% op_following/3 op_following( Op, Middle, Descendant ) :- op_descendant( Op, Middle, Descendant ). op_following( Op, _, Sibling ) :- op_sibling( Op, Sibling ). op_following( Op, Middle, SibDesc ) :- op_sibling( Op, Sibling ), op_following( Sibling, Middle, SibDesc ). %% op_parent/2 op_parent( Op, Parent ) :- optree( Root ), op_descendant( Root, Parent ), op_child( Parent, Op ). %% op_ancestor/2 op_ancestor( Op, Root ) :- optree( Root ), op_descendant( Root, Op ). op_ancestor( Op, Ancestor ) :- optree( Root ), op_descendant( Root, Ancestor ), op_descendant( Ancestor, Op ). %% op_ancestor/3 op_ancestor( Op, Middle, Ancestor ) :- optree( Root ), op_descendant( Root, _, Ancestor), op_descendant( Ancestor, Middle, Op ). %% op_ancestor_or_self/2 op_ancestor_or_self( Op, Op ). op_ancestor_or_self( Op, Ancestor ) :- op_ancestor( Op, Ancestor ). %% TODO: op_ancestor_or_self/3 op_ancestor_or_self( Op, [], Op ). op_ancestor_or_self( Op, Middle, Ancestor ) :- op_ancestor( Op, Middle, Ancestor ). op_preceding_sibling(Op, Sibling) :- op_parent( Op, Parent ), op_child( Parent, Sibling ), op_following_siblings( Sibling, Op ). %% op_preceding/2 op_preceding( Op, Preceding ) :- optree( Root ), op_following( Root, Preceding ), op_folowing( Preceding, Op ). %% op_preceding/3 op_preceding( Op, Middle, Preceding ) :- optree( Root ), op_following( Root, _, Preceding ), op_folowing( Preceding, Middle, Op ).
⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊
In reply to Re: B::Concise -> Prolog
by diotalevi
in thread B::Concise -> Prolog
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |