This repository has been archived by the owner on May 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstruction.java
49 lines (46 loc) · 2.22 KB
/
Instruction.java
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
public class Instruction
{
OpCode opCode;
int operand;
public Instruction(OpCode opCode)
{
this.opCode = opCode;
}
public Instruction(OpCode opCode, int operand)
{
this.opCode = opCode;
this.operand = operand;
}
public String toJasmin ()
{
String temp="";
switch (opCode)
{
case ldc : temp = " ldc " + operand + "\n"; break;
case invokestatic :
if( operand == 1)
temp = " invokestatic " + "Output/print(I)V" + "\n";
else
temp = " invokestatic " + "Output/read()I" + "\n"; break;
case iadd : temp = " iadd " + "\n"; break;
case imul : temp = " imul " + "\n"; break;
case idiv : temp = " idiv " + "\n"; break;
case isub : temp = " isub " + "\n"; break;
case ineg : temp = " ineg " + "\n"; break;
case istore : temp = " istore " + operand + "\n"; break;
case ior : temp = " ior " + "\n"; break;
case iand : temp = " iand " + "\n"; break;
case iload : temp = " iload " + operand + "\n"; break;
case if_icmpeq : temp = " if_icmpeq L" + operand + "\n"; break;
case if_icmple : temp = " if_icmple L" + operand + "\n"; break;
case if_icmplt : temp = " if_icmplt L" + operand + "\n"; break;
case if_icmpne : temp = " if_icmpne L" + operand + "\n"; break;
case if_icmpge : temp = " if_icmpge L" + operand + "\n"; break;
case if_icmpgt : temp = " if_icmpgt L" + operand + "\n"; break;
case ifne : temp = " ifne L" + operand + "\n"; break;
case GOto : temp = " goto L" + operand + "\n" ; break;
case label : temp = "L" + operand + ":\n"; break;
}
return temp;
}
}