Skip to content

Commit 8970540

Browse files
committed
Implemented Align node
1 parent 7b31676 commit 8970540

9 files changed

+75
-11
lines changed

src/main/java/lysis/builder/MethodParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ private LInstruction readInstruction(SPOpcode op) throws Exception {
236236
case align_pri:
237237
case align_alt:
238238
{
239-
Register reg = (op == SPOpcode.addr_pri) ? Register.Pri : Register.Alt;
239+
Register reg = (op == SPOpcode.align_pri) ? Register.Pri : Register.Alt;
240240
return new LAlign(trackGlobal(readInt32LittleEndian()), reg);
241241
}
242242

src/main/java/lysis/builder/SourceBuilder.java

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import lysis.nodes.NodeBlock;
2727
import lysis.nodes.NodeList;
2828
import lysis.nodes.NodeType;
29+
import lysis.nodes.types.DAlign;
2930
import lysis.nodes.types.DArrayRef;
3031
import lysis.nodes.types.DBinary;
3132
import lysis.nodes.types.DBoolean;
@@ -410,6 +411,10 @@ private String buildLoadStoreRef(DNode node) throws Exception {
410411
case Unary: {
411412
return buildUnary((DUnary) node) + "/* ERROR unknown load Unary */";
412413
}
414+
415+
case Align: {
416+
return buildAlign((DAlign) node);
417+
}
413418

414419
default:
415420
throw new Exception("unknown load " + node.type());
@@ -419,6 +424,10 @@ private String buildLoadStoreRef(DNode node) throws Exception {
419424
private String buildLoad(DLoad load) throws Exception {
420425
return buildLoadStoreRef(load.getOperand(0));
421426
}
427+
428+
private String buildAlign(DAlign alg) throws Exception {
429+
return buildLoadStoreRef(alg.getOperand(0));
430+
}
422431

423432
private String buildSysReq(DSysReq sysreq) throws Exception {
424433
String args = "";
@@ -813,6 +822,9 @@ private void writeStatement(DNode node) throws Exception {
813822
case Label:
814823
writeLabel((DLabel) node);
815824
break;
825+
826+
case Align:
827+
break;
816828

817829
default:
818830
throw new Exception("unknown op (" + node.type() + ")");

src/main/java/lysis/nodes/NodeBuilder.java

+10-9
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
import lysis.lstructure.Register;
6767
import lysis.lstructure.Scope;
6868
import lysis.lstructure.Variable;
69+
import lysis.nodes.types.DAlign;
6970
import lysis.nodes.types.DArrayRef;
7071
import lysis.nodes.types.DBinary;
7172
import lysis.nodes.types.DBoundsCheck;
@@ -387,6 +388,15 @@ public void traverse(NodeBlock block) throws Exception {
387388
block.add(node);
388389
break;
389390
}
391+
392+
case Align: {
393+
LAlign ins = (LAlign) uins;
394+
DAlign node = new DAlign((ins.reg() == Register.Pri) ? block.stack().pri() : block.stack().alt(), ins.number());
395+
396+
block.stack().set((ins.reg() == Register.Pri) ? Register.Pri : Register.Alt, node);
397+
block.add(node);
398+
break;
399+
}
390400

391401
case Move: {
392402
LMove ins = (LMove) uins;
@@ -792,15 +802,6 @@ public void traverse(NodeBlock block) throws Exception {
792802
block.add(new DLabel(ins.pc()));
793803
break;
794804
}
795-
796-
case Align: {
797-
LAlign ins = (LAlign) uins;
798-
if (ins.reg() == Register.Pri)
799-
block.stack().set(Register.Pri, block.stack().alt());
800-
else
801-
block.stack().set(Register.Alt, block.stack().pri());
802-
break;
803-
}
804805

805806
default:
806807
throw new Exception("unhandled opcode " + uins.op());

src/main/java/lysis/nodes/NodeRewriter.java

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package lysis.nodes;
22

3+
import lysis.nodes.types.DAlign;
34
import lysis.nodes.types.DArrayRef;
45
import lysis.nodes.types.DBinary;
56
import lysis.nodes.types.DBoundsCheck;
@@ -291,6 +292,10 @@ public void visit(DCall call) throws Exception {
291292
throw new Exception("unknown spop");
292293
}
293294
}
295+
296+
@Override
297+
public void visit(DAlign check) {
298+
}
294299

295300
private void rewriteBlock(NodeBlock block) throws Exception {
296301
current_ = block;
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package lysis.nodes;
22

33
public enum NodeType {
4-
Sentinel, Constant, DeclareLocal, DeclareStatic, LocalRef, Jump, JumpCondition, SysReq, Binary, BoundsCheck, ArrayRef, Store, Load, Return, Global, String, Boolean, Float, Function, Character, Call, TempName, Phi, Unary, IncDec, Heap, MemCopy, InlineArray, Switch, GenArray, Label
4+
Sentinel, Constant, DeclareLocal, DeclareStatic, LocalRef, Jump, JumpCondition, SysReq, Binary, BoundsCheck, ArrayRef, Store, Load, Return, Global, String, Boolean, Float, Function, Character, Call, TempName, Phi, Unary, IncDec, Heap, MemCopy, InlineArray, Switch, GenArray, Label, Align
55
}

src/main/java/lysis/nodes/NodeVisitor.java

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package lysis.nodes;
22

3+
import lysis.nodes.types.DAlign;
34
import lysis.nodes.types.DArrayRef;
45
import lysis.nodes.types.DBinary;
56
import lysis.nodes.types.DBoolean;
@@ -117,4 +118,7 @@ public void visit(DGenArray genarray) throws Exception {
117118

118119
public void visit(DLabel gototarget) {
119120
}
121+
122+
public void visit(DAlign number) {
123+
}
120124
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package lysis.nodes.types;
2+
3+
import lysis.nodes.NodeType;
4+
import lysis.nodes.NodeVisitor;
5+
6+
public class DAlign extends DUnaryNode {
7+
8+
private long amount_;
9+
10+
public DAlign(DNode index, long amount) throws Exception {
11+
super(index);
12+
amount_ = amount;
13+
}
14+
15+
public long amount() {
16+
return amount_;
17+
}
18+
19+
@Override
20+
public NodeType type() {
21+
return NodeType.Align;
22+
}
23+
24+
@Override
25+
public void accept(NodeVisitor visitor) {
26+
visitor.visit(this);
27+
}
28+
29+
@Override
30+
public boolean guard() {
31+
return true;
32+
}
33+
}

src/main/java/lysis/types/BackwardTypePropagation.java

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import lysis.nodes.NodeList;
1616
import lysis.nodes.NodeType;
1717
import lysis.nodes.NodeVisitor;
18+
import lysis.nodes.types.DAlign;
1819
import lysis.nodes.types.DArrayRef;
1920
import lysis.nodes.types.DBinary;
2021
import lysis.nodes.types.DBoolean;
@@ -401,4 +402,7 @@ public void visit(DGenArray genarray) throws Exception {
401402
genarray.getOperand(i).accept(this);
402403
}
403404
}
405+
406+
public void visit(DAlign check) {
407+
}
404408
}

src/main/java/lysis/types/ForwardTypePropagation.java

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import lysis.nodes.NodeList;
1010
import lysis.nodes.NodeType;
1111
import lysis.nodes.NodeVisitor;
12+
import lysis.nodes.types.DAlign;
1213
import lysis.nodes.types.DArrayRef;
1314
import lysis.nodes.types.DBinary;
1415
import lysis.nodes.types.DBoundsCheck;
@@ -293,4 +294,8 @@ public void visit(DGenArray genarray) throws Exception {
293294
genarray.addType(new TypeUnit(tu));
294295
}
295296
}
297+
298+
@Override
299+
public void visit(DAlign node) {
300+
}
296301
}

0 commit comments

Comments
 (0)