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

import java.util.Vector;

public class SpgExpr extends SpgSym {
	public enum ExpType { CALL, ALLOC, BinOp, Simple };
	
	public ExpType type;
	public String op;
	public SpgTemp oprand;
	public SpgSimpExpr se;
	public Vector<SpgTemp> callParams;
	
	public SpgExpr(ExpType t) {
		type = t;
		callParams = new Vector<SpgTemp>();
	}
	
	public void addCallParam(SpgTemp t) {
		if (type!=ExpType.CALL) {
			System.err.println("Error adding parameter, should be a CALL expression.");
			return;
		}
		callParams.addElement(t);
	}
	
	public String toString() {
		String str;
		switch (type) {
		case ALLOC:
			return "ALLOC " + se.toString();
		case BinOp:
			return op + " " + oprand.toString() + " " + se.toString();
		case CALL:
			str = "CALL " + se.toString();
			for (int i=0; i<callParams.size(); i++) {
				str += " " + callParams.elementAt(i).toString();
			}
			return str;
		case Simple:
			return ((SpgSimpExpr)this).toString();
		default:
			return null;
		
		}
	}
}