diff --git a/src/main/java/lysis/BitConverter.java b/src/main/java/lysis/BitConverter.java index 8d5982f..8aa0d2b 100644 --- a/src/main/java/lysis/BitConverter.java +++ b/src/main/java/lysis/BitConverter.java @@ -23,6 +23,15 @@ public static int ToInt32(byte[] bytes, int offset) { return result; } + public static int ToInt32LittleEndian(byte[] bytes, int offset) { + int result = (int) bytes[offset + 3] & 0xff; + result |= ((int) bytes[offset + 2] & 0xff) << 8; + result |= ((int) bytes[offset + 1] & 0xff) << 16; + result |= ((int) bytes[offset] & 0xff) << 24; + return result; + } + + public static long ToUInt32(byte[] bytes, int offset) { long result = (int) bytes[offset] & 0xff; result |= ((int) bytes[offset + 1] & 0xff) << 8; diff --git a/src/main/java/lysis/builder/MethodParser.java b/src/main/java/lysis/builder/MethodParser.java index 9b2bb65..15e5833 100644 --- a/src/main/java/lysis/builder/MethodParser.java +++ b/src/main/java/lysis/builder/MethodParser.java @@ -118,6 +118,11 @@ private long readUInt32() { return BitConverter.ToUInt32(file_.code().bytes(), (int) pc_ - 4); } + private int readInt32LittleEndian() { + pc_ += 4; + return BitConverter.ToInt32LittleEndian(file_.code().bytes(), (int) pc_ - 4); + } + private SPOpcode readOp() { return SPOpcode.values()[(int) readUInt32()]; } @@ -228,6 +233,13 @@ private LInstruction readInstruction(SPOpcode op) throws Exception { case idxaddr_b: return new LIndexAddress(readInt32()); + case align_pri: + case align_alt: + { + Register reg = (op == SPOpcode.addr_pri) ? Register.Pri : Register.Alt; + return new LAlign(trackGlobal(readInt32LittleEndian()), reg); + } + case move_pri: case move_alt: { Register reg = (op == SPOpcode.move_pri) ? Register.Pri : Register.Alt; @@ -685,13 +697,6 @@ 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); diff --git a/src/main/java/lysis/instructions/LAlign.java b/src/main/java/lysis/instructions/LAlign.java index a56ef53..e32db74 100644 --- a/src/main/java/lysis/instructions/LAlign.java +++ b/src/main/java/lysis/instructions/LAlign.java @@ -5,16 +5,16 @@ import lysis.lstructure.Register; -public class LAlign extends LInstructionReg { - - private long offset_; +public class LAlign extends LInstructionRegStack { + + private long number_; - public long offset() { - return offset_; - } - public LAlign(long offset, Register reg) { - super(reg); - offset_ = offset; + public long number() { + return number_; + } + public LAlign(long number, Register reg) { + super(reg, number); + number_ = number; } @Override @@ -24,7 +24,6 @@ public Opcode op() { @Override public void print(DataOutputStream tw) throws IOException { - tw.writeBytes("align." + RegisterName(reg()) + ", " - + (reg() == Register.Pri ? RegisterName(Register.Alt) : RegisterName(Register.Pri)) + offset()); + tw.writeBytes("align." + (reg() == Register.Pri ? RegisterName(Register.Pri) : RegisterName(Register.Alt)) + number()); } } \ No newline at end of file