summaryrefslogtreecommitdiff
path: root/vaporize/library/CFGNode.java
blob: a01bfb0bda4f48d1d51b910f03eeb85b5fa80be3 (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
package vaporize.library;

import cs132.vapor.ast.*;
import java.util.ArrayList;

class CFGNode {

    private Node instruction;
    private ArrayList<CFGNode> sources;
    private ArrayList<CFGNode> dests;
    private int line;

    protected CFGNode(Node instruction) {
        this.instruction = instruction;
        this.sources = new ArrayList<>();
        this.dests = new ArrayList<>();
        this.line = this.instruction.sourcePos.line;
    }

    public String toString() {
        return this.instruction.toString();
    }

    public int hashCode() {
        return this.line;
    }

    public boolean equals(Node other) {
        return other.sourcePos ==
            this.instruction.sourcePos;
    }

    protected void addSource(CFGNode node) {
        this.sources.add(node);
    }

    protected void addDest(CFGNode node) {
        this.dests.add(node);
    }

    protected Node getInstruction() {
        return this.instruction;
    }

    protected ArrayList<CFGNode> getSources() {
        return this.sources;
    }

    protected ArrayList<CFGNode> getDests() {
        return this.dests;
    }

}