Skip to content

Commit

Permalink
Implemented Align node
Browse files Browse the repository at this point in the history
  • Loading branch information
ShadowsAdi committed Mar 10, 2024
1 parent 7b31676 commit 8970540
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/lysis/builder/MethodParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/lysis/builder/SourceBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand All @@ -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 = "";
Expand Down Expand Up @@ -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() + ")");
Expand Down
19 changes: 10 additions & 9 deletions src/main/java/lysis/nodes/NodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/lysis/nodes/NodeRewriter.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/lysis/nodes/NodeType.java
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 4 additions & 0 deletions src/main/java/lysis/nodes/NodeVisitor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -117,4 +118,7 @@ public void visit(DGenArray genarray) throws Exception {

public void visit(DLabel gototarget) {
}

public void visit(DAlign number) {
}
}
33 changes: 33 additions & 0 deletions src/main/java/lysis/nodes/types/DAlign.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
4 changes: 4 additions & 0 deletions src/main/java/lysis/types/BackwardTypePropagation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -401,4 +402,7 @@ public void visit(DGenArray genarray) throws Exception {
genarray.getOperand(i).accept(this);
}
}

public void visit(DAlign check) {
}
}
5 changes: 5 additions & 0 deletions src/main/java/lysis/types/ForwardTypePropagation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -293,4 +294,8 @@ public void visit(DGenArray genarray) throws Exception {
genarray.addType(new TypeUnit(tu));
}
}

@Override
public void visit(DAlign node) {
}
}

0 comments on commit 8970540

Please sign in to comment.