[phc-internals] [phc commit] r1414 - branches/saturn/src/analyse
codesite-noreply at google.com
codesite-noreply at google.com
Thu Jul 3 17:07:30 IST 2008
Author: paul.biggar
Date: Thu Jul 3 09:06:46 2008
New Revision: 1414
Modified:
branches/saturn/src/analyse/cfg.clp
branches/saturn/src/analyse/cfgdot.clp
branches/saturn/src/analyse/do_versioning.clp
branches/saturn/src/analyse/errors.clp
Log:
Versioning was broken in a number of cases. This is a cleaner, more
elegant and more robust method for the same thing.
Modified: branches/saturn/src/analyse/cfg.clp
==============================================================================
--- branches/saturn/src/analyse/cfg.clp (original)
+++ branches/saturn/src/analyse/cfg.clp Thu Jul 3 09:06:46 2008
@@ -24,26 +24,18 @@
cfg_node (N) :- cfg_edge (N, _).
cfg_node (N) :- cfg_edge (_, N).
-% Allow any user to annotation the CFG with strings. cfgdot, if
imported, will
-% pick up on these.
+% Allow any user to annotation the CFG with strings. cfgdot, if imported,
+% will pick up on these.
predicate in_annotation (BB:t_cfg_node, ANNOTATION:string).
predicate out_annotation (BB:t_cfg_node, ANNOTATION:string).
-% Indicates the CFG has changed this iteration, and another iteration
is required.
+% Indicates the CFG has changed this iteration, and another iteration is
+% required.
predicate reiterate ().
-% This block, and its incoming and outgoing edges are dead, and will
be removed
-% in the next version. PRIVATE.
-predicate is_dead (BB:t_cfg_node).
-is_dead (BB) :- remove_bb (BB).
-
-
% Remove a node from the CFG
+% These are defined in do_versioning.
predicate remove_bb (BB:t_cfg_node).
-remove_bb (BB), +replace_bb (BB, []).
-replace_bb (BB, _), +is_dead (BB), +reiterate ().
-
-% Replace a CFG node with a list of nodes
predicate replace_bb (BB:t_cfg_node, NEW_BBS:list[t_cfg_node]).
Modified: branches/saturn/src/analyse/cfgdot.clp
==============================================================================
--- branches/saturn/src/analyse/cfgdot.clp (original)
+++ branches/saturn/src/analyse/cfgdot.clp Thu Jul 3 09:06:46 2008
@@ -44,7 +44,8 @@
% Build the dotty graph
dotty_graph (NAME, true, dotgraph{Nodes, Edges},
[dg_attr{"outputorder", "edgesfirst"}], [], []) :-
- cfg_node (nentry{METHOD}), get_method_name (METHOD, NAME),
+ cfg (METHOD_NAME, VERSION),
+ NAME = str_cat_list ([METHOD_NAME, "_v", tostring (VERSION)]),
\/(dotty_node (DN, NAs), N = dg_node{DN, NAs}):list_all(N, Nodes),
\/(dotty_edge (DE1, DE2, EAs), E = dg_edge{DE1, DE2,
EAs}):list_all(E, Edges).
Modified: branches/saturn/src/analyse/do_versioning.clp
==============================================================================
--- branches/saturn/src/analyse/do_versioning.clp (original)
+++ branches/saturn/src/analyse/do_versioning.clp Thu Jul 3 09:06:46 2008
@@ -4,38 +4,45 @@
% nothing marked dead, we turn it into an mir(), which is unparsed
into XML
% later (see linearize_cfg.clp).
-% Replacing a single node with multiple nodes
-reiterate(),
+% Replacing an edge with its new counterpart. get_*_replacement
handles cases
+% where the BB is dead or not.
+reiterate (),
cfg_edge (BB1, BB2),
- ~is_dead (BB1),
-
- % get the new target (it may already be dead)
- get_non_dead_target (BB2, TARGET),
-
- % Create the list of BBs (may be empty),
- ((
- replace_bb (BB2, BB_LIST),
- +print (str_cat ("Adding new statements: ", tostring (BB_LIST))))
- ;
- (~is_dead (BB2), BB_LIST = [])),
- +add_list_of_bbs (flatten ([[BB1], BB_LIST, [TARGET]])).
-
-
-predicate get_non_dead_target (in BB:t_cfg_node, out
TARGET:t_cfg_node) succeeds [many].
-get_non_dead_target (BB, TARGET) :-
- (~is_dead (BB), TARGET = BB)
- ;
- ( is_dead (BB),
- cfg_edge (BB, NEXT),
- +print (str_cat ("Removing dead statement: ", tostring (BB))),
- get_non_dead_target (NEXT, TARGET)).
+ cfg (METHOD, VERSION),
+ NEW_BB1 = get_first_replacement (BB1),
+ NEW_BB2 = get_last_replacement (BB2),
+ +cfg (METHOD, VERSION+1)->cfg_edge (NEW_BB1, NEW_BB2).
+
+predicate get_first_replacement (in IN:t_cfg_node, out OUT:t_cfg_node)
succeeds [once].
+predicate get_last_replacement (in IN:t_cfg_node, out OUT:t_cfg_node)
succeeds [once].
+get_first_replacement (BB, BB) :- ~replace_bb (BB, _).
+get_first_replacement (BB, H) :- replace_bb (BB, [H|_]).
+get_last_replacement (BB, BB) :- ~replace_bb (BB, _).
+get_last_replacement (BB, H) :- replace_bb (BB, LIST), [H|_] =
list_reverse (LIST).
+
+% If there is more than one node, add it
+replace_bb (_, LIST), int_gt (list_length (LIST), 2),
+ +add_bbs (LIST).
+predicate add_bbs (BBS:list[t_cfg_node]).
+add_bbs ([H1,H2|T]),
+ cfg (METHOD, VERSION),
+ +cfg (METHOD, VERSION+1)->cfg_edge (H1, H2),
+ +add_bbs ([H2|T]).
-predicate add_list_of_bbs (BBS:list[t_cfg_node]).
+predicate add_list_of_bbs (LIST:list[t_cfg_node]).
% Single element lists means we've done it
add_list_of_bbs ([H1,H2|T]),
cfg (METHOD, VERSION),
+cfg (METHOD, VERSION+1)->cfg_edge (H1, H2),
+add_list_of_bbs ([H2|T]). % recurse
+
+
+replace_bb (_, _), +reiterate ().
+remove_bb (BB), BB = nblock{S},
+ +replace_bb (BB, [nempty{S}]).
+
+% Only allow removing blocks
+remove_bb (BB), BB \= nblock{_}, +error_in (BB, "Can only handle nblocks").
Modified: branches/saturn/src/analyse/errors.clp
==============================================================================
--- branches/saturn/src/analyse/errors.clp (original)
+++ branches/saturn/src/analyse/errors.clp Thu Jul 3 09:06:46 2008
@@ -3,11 +3,11 @@
% Error handling
predicate error_in (BB:t_cfg_node, NAME:string).
-error_in (BB, NAME) :-
+error_in (BB, MESSAGE) :-
cfg_node (BB),
(
- ~live_handled (BB), NAME = "LIVE"
- ; ~alias_handled (BB), NAME = "ALIAS"
+ ~live_handled (BB), MESSAGE = "LIVE"
+ ; ~alias_handled (BB), MESSAGE = "ALIAS"
).
% This is done in separate predicates so that the error will print
before the
More information about the phc-internals
mailing list