diff --git a/src/main/java/lysis/builder/MethodParser.java b/src/main/java/lysis/builder/MethodParser.java index 15e5833..e4d6d99 100644 --- a/src/main/java/lysis/builder/MethodParser.java +++ b/src/main/java/lysis/builder/MethodParser.java @@ -236,7 +236,7 @@ private LInstruction readInstruction(SPOpcode op) throws Exception { case align_pri: case align_alt: { - Register reg = (op == SPOpcode.addr_pri) ? Register.Pri : Register.Alt; + Register reg = (op == SPOpcode.align_pri) ? Register.Pri : Register.Alt; return new LAlign(trackGlobal(readInt32LittleEndian()), reg); } diff --git a/src/main/java/lysis/builder/SourceBuilder.java b/src/main/java/lysis/builder/SourceBuilder.java index 5d969ef..57a591d 100644 --- a/src/main/java/lysis/builder/SourceBuilder.java +++ b/src/main/java/lysis/builder/SourceBuilder.java @@ -26,6 +26,7 @@ import lysis.nodes.NodeBlock; import lysis.nodes.NodeList; import lysis.nodes.NodeType; +import lysis.nodes.types.DAlign; import lysis.nodes.types.DArrayRef; import lysis.nodes.types.DBinary; import lysis.nodes.types.DBoolean; @@ -410,6 +411,10 @@ private String buildLoadStoreRef(DNode node) throws Exception { case Unary: { return buildUnary((DUnary) node) + "/* ERROR unknown load Unary */"; } + + case Align: { + return buildAlign((DAlign) node); + } default: throw new Exception("unknown load " + node.type()); @@ -419,6 +424,10 @@ private String buildLoadStoreRef(DNode node) throws Exception { private String buildLoad(DLoad load) throws Exception { return buildLoadStoreRef(load.getOperand(0)); } + + private String buildAlign(DAlign alg) throws Exception { + return buildLoadStoreRef(alg.getOperand(0)); + } private String buildSysReq(DSysReq sysreq) throws Exception { String args = ""; @@ -813,6 +822,9 @@ private void writeStatement(DNode node) throws Exception { case Label: writeLabel((DLabel) node); break; + + case Align: + break; default: throw new Exception("unknown op (" + node.type() + ")"); diff --git a/src/main/java/lysis/nodes/NodeBuilder.java b/src/main/java/lysis/nodes/NodeBuilder.java index 583cf81..b853d2c 100644 --- a/src/main/java/lysis/nodes/NodeBuilder.java +++ b/src/main/java/lysis/nodes/NodeBuilder.java @@ -66,6 +66,7 @@ import lysis.lstructure.Register; import lysis.lstructure.Scope; import lysis.lstructure.Variable; +import lysis.nodes.types.DAlign; import lysis.nodes.types.DArrayRef; import lysis.nodes.types.DBinary; import lysis.nodes.types.DBoundsCheck; @@ -387,6 +388,15 @@ public void traverse(NodeBlock block) throws Exception { block.add(node); break; } + + case Align: { + LAlign ins = (LAlign) uins; + DAlign node = new DAlign((ins.reg() == Register.Pri) ? block.stack().pri() : block.stack().alt(), ins.number()); + + block.stack().set((ins.reg() == Register.Pri) ? Register.Pri : Register.Alt, node); + block.add(node); + break; + } case Move: { LMove ins = (LMove) uins; @@ -792,15 +802,6 @@ public void traverse(NodeBlock block) throws Exception { block.add(new DLabel(ins.pc())); break; } - - case Align: { - LAlign ins = (LAlign) uins; - if (ins.reg() == Register.Pri) - block.stack().set(Register.Pri, block.stack().alt()); - else - block.stack().set(Register.Alt, block.stack().pri()); - break; - } default: throw new Exception("unhandled opcode " + uins.op()); diff --git a/src/main/java/lysis/nodes/NodeRewriter.java b/src/main/java/lysis/nodes/NodeRewriter.java index a10a912..acc6a22 100644 --- a/src/main/java/lysis/nodes/NodeRewriter.java +++ b/src/main/java/lysis/nodes/NodeRewriter.java @@ -1,5 +1,6 @@ package lysis.nodes; +import lysis.nodes.types.DAlign; import lysis.nodes.types.DArrayRef; import lysis.nodes.types.DBinary; import lysis.nodes.types.DBoundsCheck; @@ -291,6 +292,10 @@ public void visit(DCall call) throws Exception { throw new Exception("unknown spop"); } } + + @Override + public void visit(DAlign check) { + } private void rewriteBlock(NodeBlock block) throws Exception { current_ = block; diff --git a/src/main/java/lysis/nodes/NodeType.java b/src/main/java/lysis/nodes/NodeType.java index 83ee077..d406522 100644 --- a/src/main/java/lysis/nodes/NodeType.java +++ b/src/main/java/lysis/nodes/NodeType.java @@ -1,5 +1,5 @@ package lysis.nodes; public enum NodeType { - 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 + 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 } diff --git a/src/main/java/lysis/nodes/NodeVisitor.java b/src/main/java/lysis/nodes/NodeVisitor.java index 38e55ab..fb878b6 100644 --- a/src/main/java/lysis/nodes/NodeVisitor.java +++ b/src/main/java/lysis/nodes/NodeVisitor.java @@ -1,5 +1,6 @@ package lysis.nodes; +import lysis.nodes.types.DAlign; import lysis.nodes.types.DArrayRef; import lysis.nodes.types.DBinary; import lysis.nodes.types.DBoolean; @@ -117,4 +118,7 @@ public void visit(DGenArray genarray) throws Exception { public void visit(DLabel gototarget) { } + + public void visit(DAlign number) { + } } diff --git a/src/main/java/lysis/nodes/types/DAlign.java b/src/main/java/lysis/nodes/types/DAlign.java new file mode 100644 index 0000000..c614ad1 --- /dev/null +++ b/src/main/java/lysis/nodes/types/DAlign.java @@ -0,0 +1,33 @@ +package lysis.nodes.types; + +import lysis.nodes.NodeType; +import lysis.nodes.NodeVisitor; + +public class DAlign extends DUnaryNode { + + private long amount_; + + public DAlign(DNode index, long amount) throws Exception { + super(index); + amount_ = amount; + } + + public long amount() { + return amount_; + } + + @Override + public NodeType type() { + return NodeType.Align; + } + + @Override + public void accept(NodeVisitor visitor) { + visitor.visit(this); + } + + @Override + public boolean guard() { + return true; + } +} diff --git a/src/main/java/lysis/types/BackwardTypePropagation.java b/src/main/java/lysis/types/BackwardTypePropagation.java index 192b92c..0778f3d 100644 --- a/src/main/java/lysis/types/BackwardTypePropagation.java +++ b/src/main/java/lysis/types/BackwardTypePropagation.java @@ -15,6 +15,7 @@ import lysis.nodes.NodeList; import lysis.nodes.NodeType; import lysis.nodes.NodeVisitor; +import lysis.nodes.types.DAlign; import lysis.nodes.types.DArrayRef; import lysis.nodes.types.DBinary; import lysis.nodes.types.DBoolean; @@ -401,4 +402,7 @@ public void visit(DGenArray genarray) throws Exception { genarray.getOperand(i).accept(this); } } + + public void visit(DAlign check) { + } } diff --git a/src/main/java/lysis/types/ForwardTypePropagation.java b/src/main/java/lysis/types/ForwardTypePropagation.java index 490c213..526d505 100644 --- a/src/main/java/lysis/types/ForwardTypePropagation.java +++ b/src/main/java/lysis/types/ForwardTypePropagation.java @@ -9,6 +9,7 @@ import lysis.nodes.NodeList; import lysis.nodes.NodeType; import lysis.nodes.NodeVisitor; +import lysis.nodes.types.DAlign; import lysis.nodes.types.DArrayRef; import lysis.nodes.types.DBinary; import lysis.nodes.types.DBoundsCheck; @@ -293,4 +294,8 @@ public void visit(DGenArray genarray) throws Exception { genarray.addType(new TypeUnit(tu)); } } + + @Override + public void visit(DAlign node) { + } }