Skip to content

Commit

Permalink
Refactored debug data generator
Browse files Browse the repository at this point in the history
  • Loading branch information
maccasoft committed Oct 15, 2024
1 parent 98453c3 commit e4f1089
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 334 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void testRegisterArray() {
Assertions.assertEquals(""
+ "00000 00000 01 ASMMODE\n"
+ "00001 00001 04 COGN\n"
+ "00002 00002 51 72 65 67 61 UDEC_ARRAY(rega)\n"
+ "00002 00002 51 72 65 67 61 UDEC_REG_ARRAY(rega)\n"
+ "00007 00007 00 80 01 80 04\n"
+ "0000C 0000C 00 DONE\n"
+ "", actual);
Expand All @@ -218,7 +218,7 @@ void testRegisterArrayImmediateCount() {
Assertions.assertEquals(""
+ "00000 00000 01 ASMMODE\n"
+ "00001 00001 04 COGN\n"
+ "00002 00002 51 72 65 67 61 UDEC_ARRAY(rega)\n"
+ "00002 00002 51 72 65 67 61 UDEC_REG_ARRAY(rega)\n"
+ "00007 00007 00 80 01 00 04\n"
+ "0000C 0000C 00 DONE\n"
+ "", actual);
Expand Down Expand Up @@ -818,10 +818,9 @@ Spin2StatementNode parse(String text) {
return builder.getRoot();
}

String dumpDebugData(byte[] data) {
String dumpDebugData(List<DataObject> l) {
Spin2Object object = new Spin2Object();

List<DataObject> l = Spin2Debugger.decodeDebugData(data);
for (DataObject obj : l) {
object.write(obj);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,9 @@ void testDebug() throws Exception {
+ "' Debug data\n"
+ "00B28 00000 06 00 \n"
+ "00B2A 00002 04 00 \n"
+ "00B2C 00004 04 00 \n"
+ "' #1\n"
+ "00B2C 00004 04 COGN\n"
+ "00B2D 00005 00 DONE\n"
+ "", compile(text, true));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public int setBytes(byte[] bytes, int index) {
return index;
}

public int size() {
return bytes != null ? bytes.length : 0;
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,23 +224,20 @@ public Spin2Object generateDebugData() {
List<DataObject> l = new ArrayList<DataObject>();
for (Object node : debugStatements) {
try {
List<DataObject> list = null;
if (node instanceof Spin2StatementNode) {
byte[] data = debug.compileDebugStatement((Spin2StatementNode) node);

l.add(new CommentDataObject(String.format("#%d", index++)));
l.addAll(Spin2Debugger.decodeDebugData(data));

object.writeWord(pos);
pos += data.length;
list = debug.compileDebugStatement((Spin2StatementNode) node);
}
else if (node instanceof Spin2PAsmDebugLine) {
byte[] data = debug.compilePAsmDebugStatement((Spin2PAsmDebugLine) node);

list = debug.compilePAsmDebugStatement((Spin2PAsmDebugLine) node);
}
if (list != null) {
l.add(new CommentDataObject(String.format("#%d", index++)));
l.addAll(Spin2Debugger.decodeDebugData(data));

object.writeWord(pos);
pos += data.length;
for (DataObject o : list) {
l.add(o);
pos += o.size();
}
}
} catch (Exception e) {
// Do nothing, exception are catched at the object compiler level
Expand Down
Loading

0 comments on commit e4f1089

Please sign in to comment.