Release 0.7.8
[vala-lang.git] / vala / valabasicblock.vala
blob498622c8964d9f2c0347e8eb16f33ffc32380eb6
1 /* valabasicblock.vala
3 * Copyright (C) 2008 Jürg Billeter
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.
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.
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
19 * Author:
20 * Jürg Billeter <j@bitron.ch>
23 using GLib;
25 /**
26 * Represents a basic block, i.e. a straight-line piece of code without any
27 * jumps or jump targets.
29 public class Vala.BasicBlock {
30 private List<CodeNode> nodes = new ArrayList<CodeNode> ();
32 // control flow graph
33 private List<weak BasicBlock> predecessors = new ArrayList<weak BasicBlock> ();
34 private List<BasicBlock> successors = new ArrayList<BasicBlock> ();
36 // dominator tree
37 public BasicBlock parent { get; private set; }
38 List<BasicBlock> children = new ArrayList<BasicBlock> ();
39 Set<BasicBlock> df = new HashSet<BasicBlock> ();
41 Set<PhiFunction> phi_functions = new HashSet<PhiFunction> ();
43 public BasicBlock () {
46 public BasicBlock.entry () {
49 public BasicBlock.exit () {
52 public void add_node (CodeNode node) {
53 nodes.add (node);
56 public List<CodeNode> get_nodes () {
57 return nodes;
60 public void connect (BasicBlock target) {
61 if (!successors.contains (target)) {
62 successors.add (target);
64 if (!target.predecessors.contains (this)) {
65 target.predecessors.add (this);
69 public List<weak BasicBlock> get_predecessors () {
70 return new ReadOnlyList<weak BasicBlock> (predecessors);
73 public List<weak BasicBlock> get_successors () {
74 return new ReadOnlyList<weak BasicBlock> (successors);
77 public void add_child (BasicBlock block) {
78 children.add (block);
79 block.parent = this;
82 public List<BasicBlock> get_children () {
83 return children;
86 public void add_dominator_frontier (BasicBlock block) {
87 df.add (block);
90 public Set<BasicBlock> get_dominator_frontier () {
91 return df;
94 public void add_phi_function (PhiFunction phi) {
95 phi_functions.add (phi);
98 public Set<PhiFunction> get_phi_functions () {
99 return phi_functions;