Line data Source code
1 : /* valabasicblock.vala
2 : *
3 : * Copyright (C) 2008 Jürg Billeter
4 : *
5 : * This library is free software; you can redistribute it and/or
6 : * modify it under the terms of the GNU Lesser General Public
7 : * License as published by the Free Software Foundation; either
8 : * version 2.1 of the License, or (at your option) any later version.
9 :
10 : * This library is distributed in the hope that it will be useful,
11 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 : * Lesser General Public License for more details.
14 :
15 : * You should have received a copy of the GNU Lesser General Public
16 : * License along with this library; if not, write to the Free Software
17 : * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 : *
19 : * Author:
20 : * Jürg Billeter <j@bitron.ch>
21 : */
22 :
23 : using GLib;
24 :
25 : /**
26 : * Represents a basic block, i.e. a straight-line piece of code without any
27 : * jumps or jump targets.
28 : */
29 13376282 : public class Vala.BasicBlock {
30 1323292 : private List<CodeNode> nodes = new ArrayList<CodeNode> ();
31 :
32 : // control flow graph
33 1323292 : private List<weak BasicBlock> predecessors = new ArrayList<weak BasicBlock> ();
34 1323292 : private List<weak BasicBlock> successors = new ArrayList<weak BasicBlock> ();
35 :
36 : // dominator tree
37 1552816 : public weak BasicBlock parent { get; private set; }
38 1323292 : List<weak BasicBlock> children = new ArrayList<weak BasicBlock> ();
39 1323292 : Set<weak BasicBlock> df = new HashSet<weak BasicBlock> ();
40 :
41 1323292 : Set<PhiFunction> phi_functions = new HashSet<PhiFunction> ();
42 :
43 1417860 : public bool postorder_visited { get; set; }
44 8339086 : public int postorder_number { get; set; }
45 :
46 952148 : public BasicBlock () {
47 : }
48 :
49 185572 : public BasicBlock.entry () {
50 : }
51 :
52 185572 : public BasicBlock.exit () {
53 : }
54 :
55 653448 : public void add_node (CodeNode node) {
56 653448 : nodes.add (node);
57 : }
58 :
59 1978554 : public unowned List<CodeNode> get_nodes () {
60 1978554 : return nodes;
61 : }
62 :
63 665656 : public void connect (BasicBlock target) {
64 665656 : if (!successors.contains (target)) {
65 665642 : successors.add (target);
66 : }
67 665656 : if (!target.predecessors.contains (this)) {
68 665642 : target.predecessors.add (this);
69 : }
70 : }
71 :
72 2235437 : public unowned List<weak BasicBlock> get_predecessors () {
73 2235437 : return predecessors;
74 : }
75 :
76 1978554 : public unowned List<weak BasicBlock> get_successors () {
77 1978554 : return successors;
78 : }
79 :
80 566732 : public void add_child (BasicBlock block) {
81 566732 : children.add (block);
82 566732 : block.parent = this;
83 : }
84 :
85 1319036 : public unowned List<weak BasicBlock> get_children () {
86 1319036 : return children;
87 : }
88 :
89 407432 : public void add_dominator_frontier (BasicBlock block) {
90 407432 : df.add (block);
91 : }
92 :
93 1025546 : public unowned Set<weak BasicBlock> get_dominator_frontier () {
94 1025546 : return df;
95 : }
96 :
97 267509 : public void add_phi_function (PhiFunction phi) {
98 267509 : phi_functions.add (phi);
99 : }
100 :
101 1984592 : public unowned Set<PhiFunction> get_phi_functions () {
102 1984592 : return phi_functions;
103 : }
104 : }
|