Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for align_(pri|alt) OPcodes #44

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/main/java/lysis/builder/MethodParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
import lysis.instructions.LZeroGlobal;
import lysis.instructions.LZeroLocal;
import lysis.instructions.SwitchCase;
import lysis.instructions.LAlign;
import lysis.lstructure.Function;
import lysis.lstructure.LBlock;
import lysis.lstructure.LGraph;
Expand Down Expand Up @@ -684,6 +685,13 @@ private LInstruction readInstruction(SPOpcode op) throws Exception {
pc_ += num - 8; // skip dbgname
return new LDebugBreak();
}

case align_pri:
case align_alt:
{
Register reg = (op == SPOpcode.addr_pri) ? Register.Pri : Register.Alt;
return new LAlign(trackGlobal(readInt32()), reg);
}

default:
throw new Exception("Unrecognized opcode: " + op);
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/lysis/instructions/LAlign.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lysis.instructions;

import java.io.DataOutputStream;
import java.io.IOException;

import lysis.lstructure.Register;

public class LAlign extends LInstructionReg {

private long offset_;

public long offset() {
return offset_;
}
public LAlign(long offset, Register reg) {
super(reg);
offset_ = offset;
}

@Override
public Opcode op() {
return Opcode.Align;
}

@Override
public void print(DataOutputStream tw) throws IOException {
tw.writeBytes("align." + RegisterName(reg()) + ", "
ShadowsAdi marked this conversation as resolved.
Show resolved Hide resolved
+ (reg() == Register.Pri ? RegisterName(Register.Alt) : RegisterName(Register.Pri)) + offset());
}
}
2 changes: 1 addition & 1 deletion src/main/java/lysis/instructions/Opcode.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package lysis.instructions;

public enum Opcode {
LoadLocal, StoreLocal, LoadLocalRef, StoreLocalRef, Load, Constant, StackAddress, Store, IndexAddress, Move, PushReg, PushConstant, Pop, Stack, Return, Jump, JumpCondition, AddConstant, MulConstant, ZeroGlobal, IncGlobal, DecGlobal, IncLocal, DecLocal, IncI, IncReg, DecI, DecReg, Fill, Bounds, SysReq, Swap, PushStackAddress, DebugBreak, Goto, PushLocal, Exchange, Binary, ShiftLeftConstant, PushGlobal, StoreGlobal, LoadGlobal, Call, EqualConstant, LoadIndex, Unary, StoreGlobalConstant, StoreLocalConstant, ZeroLocal, Heap, MemCopy, Switch, GenArray, StackAdjust, LoadCtrl, StoreCtrl, InitArray
LoadLocal, StoreLocal, LoadLocalRef, StoreLocalRef, Load, Constant, StackAddress, Store, IndexAddress, Move, PushReg, PushConstant, Pop, Stack, Return, Jump, JumpCondition, AddConstant, MulConstant, ZeroGlobal, IncGlobal, DecGlobal, IncLocal, DecLocal, IncI, IncReg, DecI, DecReg, Fill, Bounds, SysReq, Swap, PushStackAddress, DebugBreak, Goto, PushLocal, Exchange, Binary, ShiftLeftConstant, PushGlobal, StoreGlobal, LoadGlobal, Call, EqualConstant, LoadIndex, Unary, StoreGlobalConstant, StoreLocalConstant, ZeroLocal, Heap, MemCopy, Switch, GenArray, StackAdjust, LoadCtrl, StoreCtrl, InitArray, Align
}
10 changes: 10 additions & 0 deletions src/main/java/lysis/nodes/NodeBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import lysis.instructions.LUnary;
import lysis.instructions.LZeroGlobal;
import lysis.instructions.LZeroLocal;
import lysis.instructions.LAlign;
import lysis.instructions.Opcode;
import lysis.lstructure.Function;
import lysis.lstructure.LBlock;
Expand Down Expand Up @@ -791,6 +792,15 @@ 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