summaryrefslogtreecommitdiff
path: root/vala/valabasicblock.vala
blob: 26648aed6607667cf0e67eda38105d0f01c9b017 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* valabasicblock.vala
 *
 * Copyright (C) 2008  Jürg Billeter
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.

 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.

 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 *
 * Author:
 * 	Jürg Billeter <j@bitron.ch>
 */

using GLib;

/**
 * Represents a basic block, i.e. a straight-line piece of code without any
 * jumps or jump targets.
 */
public class Vala.BasicBlock {
	private List<CodeNode> nodes = new ArrayList<CodeNode> ();

	// control flow graph
	private List<weak BasicBlock> predecessors = new ArrayList<weak BasicBlock> ();
	private List<weak BasicBlock> successors = new ArrayList<weak BasicBlock> ();

	// dominator tree
	public weak BasicBlock parent { get; private set; }
	List<weak BasicBlock> children = new ArrayList<weak BasicBlock> ();
	Set<weak BasicBlock> df = new HashSet<weak BasicBlock> ();

	Set<PhiFunction> phi_functions = new HashSet<PhiFunction> ();

	public bool postorder_visited { get; set; }
	public int postorder_number { get; set; }

	public BasicBlock () {
	}

	public BasicBlock.entry () {
	}

	public BasicBlock.exit () {
	}

	public void add_node (CodeNode node) {
		nodes.add (node);
	}

	public unowned List<CodeNode> get_nodes () {
		return nodes;
	}

	public void connect (BasicBlock target) {
		if (!successors.contains (target)) {
			successors.add (target);
		}
		if (!target.predecessors.contains (this)) {
			target.predecessors.add (this);
		}
	}

	public unowned List<weak BasicBlock> get_predecessors () {
		return predecessors;
	}

	public unowned List<weak BasicBlock> get_successors () {
		return successors;
	}

	public void add_child (BasicBlock block) {
		children.add (block);
		block.parent = this;
	}

	public unowned List<weak BasicBlock> get_children () {
		return children;
	}

	public void add_dominator_frontier (BasicBlock block) {
		df.add (block);
	}

	public unowned Set<weak BasicBlock> get_dominator_frontier () {
		return df;
	}

	public void add_phi_function (PhiFunction phi) {
		phi_functions.add (phi);
	}

	public unowned Set<PhiFunction> get_phi_functions () {
		return phi_functions;
	}
}