summaryrefslogtreecommitdiff
path: root/src/spiglet/spiglet2kanga/SpgStmt.java
blob: 4f2ffb2cac58f21aafdef37da1c846b6dc0d0ad7 (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
package spiglet.spiglet2kanga;

import java.util.HashSet;

public class SpgStmt extends SpgSym{
	public enum StmtType { NOOP, ERROR, CJUMP, JUMP, STORE, LOAD, MOVE, PRINT };
	StmtType type;
	public SpgTemp tmp1, tmp2;
	public int imm;
	public String jmptarget;
	public SpgExpr exp;
	
	public String lb;
	public SpgStmt succ1, succ2;
	
	public HashSet<SpgTemp> def, use;
	
	public SpgStmt(StmtType t) {
		type = t;
	}
	
	public String toString() {
		String str="";
		if (lb!=null) str = lb + " ";
		switch (type) {
		case CJUMP:
			return str + "CJUMP " + tmp1.toString() + " " + jmptarget;
		case ERROR:
			return str + "ERROR";
		case JUMP:
			return str + "JUMP " + jmptarget;
		case LOAD:
			return str + "LD " + tmp1.toString() + " " + tmp2.toString() + " " + imm;
		case MOVE:
			return str + "MOVE " + tmp1.toString() + " " + exp.toString();
		case NOOP:
			return str + "NOOP";
		case PRINT:
			return str + "PRINT " + exp.toString();
		case STORE:
			return str + "STORE " + tmp1.toString() + " " + imm + " " + tmp2.toString();
		default:
			return null;		
		}
	}
	
	public void getDefUse() {
		switch (type) {
		case CJUMP:
			def = null;
			use = tmp1.getTmpUsed();
			break;
		case ERROR:
			def = use = null;
			break;
		case JUMP:
			def = use = null;
			break;
		case LOAD:
			def = tmp1.getTmpUsed();
			use = tmp2.getTmpUsed();
			break;
		case MOVE:
			def = tmp1.getTmpUsed();
			use = exp.getTmpUsed();
			break;
		case NOOP:
			def = use = null;
			break;
		case PRINT:
			def = null;
			use = exp.getTmpUsed();
			break;
		case STORE:
			def = null;
			use = tmp1.getTmpUsed();
			use.add(tmp2);
			break;
		default:
			System.err.println("Unknown statement type");
			def = use = null;
			break;
		
		}
	}
}