Skip to content

Commit 7b31676

Browse files
committed
Improved align.(pri|alt) read
1 parent 2504487 commit 7b31676

File tree

3 files changed

+31
-18
lines changed

3 files changed

+31
-18
lines changed

src/main/java/lysis/BitConverter.java

+9
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ public static int ToInt32(byte[] bytes, int offset) {
2323
return result;
2424
}
2525

26+
public static int ToInt32LittleEndian(byte[] bytes, int offset) {
27+
int result = (int) bytes[offset + 3] & 0xff;
28+
result |= ((int) bytes[offset + 2] & 0xff) << 8;
29+
result |= ((int) bytes[offset + 1] & 0xff) << 16;
30+
result |= ((int) bytes[offset] & 0xff) << 24;
31+
return result;
32+
}
33+
34+
2635
public static long ToUInt32(byte[] bytes, int offset) {
2736
long result = (int) bytes[offset] & 0xff;
2837
result |= ((int) bytes[offset + 1] & 0xff) << 8;

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

+12-7
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ private long readUInt32() {
118118
return BitConverter.ToUInt32(file_.code().bytes(), (int) pc_ - 4);
119119
}
120120

121+
private int readInt32LittleEndian() {
122+
pc_ += 4;
123+
return BitConverter.ToInt32LittleEndian(file_.code().bytes(), (int) pc_ - 4);
124+
}
125+
121126
private SPOpcode readOp() {
122127
return SPOpcode.values()[(int) readUInt32()];
123128
}
@@ -228,6 +233,13 @@ private LInstruction readInstruction(SPOpcode op) throws Exception {
228233
case idxaddr_b:
229234
return new LIndexAddress(readInt32());
230235

236+
case align_pri:
237+
case align_alt:
238+
{
239+
Register reg = (op == SPOpcode.addr_pri) ? Register.Pri : Register.Alt;
240+
return new LAlign(trackGlobal(readInt32LittleEndian()), reg);
241+
}
242+
231243
case move_pri:
232244
case move_alt: {
233245
Register reg = (op == SPOpcode.move_pri) ? Register.Pri : Register.Alt;
@@ -685,13 +697,6 @@ private LInstruction readInstruction(SPOpcode op) throws Exception {
685697
pc_ += num - 8; // skip dbgname
686698
return new LDebugBreak();
687699
}
688-
689-
case align_pri:
690-
case align_alt:
691-
{
692-
Register reg = (op == SPOpcode.addr_pri) ? Register.Pri : Register.Alt;
693-
return new LAlign(trackGlobal(readInt32()), reg);
694-
}
695700

696701
default:
697702
throw new Exception("Unrecognized opcode: " + op);

src/main/java/lysis/instructions/LAlign.java

+10-11
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55

66
import lysis.lstructure.Register;
77

8-
public class LAlign extends LInstructionReg {
9-
10-
private long offset_;
8+
public class LAlign extends LInstructionRegStack {
9+
10+
private long number_;
1111

12-
public long offset() {
13-
return offset_;
14-
}
15-
public LAlign(long offset, Register reg) {
16-
super(reg);
17-
offset_ = offset;
12+
public long number() {
13+
return number_;
14+
}
15+
public LAlign(long number, Register reg) {
16+
super(reg, number);
17+
number_ = number;
1818
}
1919

2020
@Override
@@ -24,7 +24,6 @@ public Opcode op() {
2424

2525
@Override
2626
public void print(DataOutputStream tw) throws IOException {
27-
tw.writeBytes("align." + RegisterName(reg()) + ", "
28-
+ (reg() == Register.Pri ? RegisterName(Register.Alt) : RegisterName(Register.Pri)) + offset());
27+
tw.writeBytes("align." + (reg() == Register.Pri ? RegisterName(Register.Pri) : RegisterName(Register.Alt)) + number());
2928
}
3029
}

0 commit comments

Comments
 (0)