diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 02b577df4..e744260b3 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -4,15 +4,6 @@
-
-
-
diff --git a/src/main/java/dk/camelot64/kickc/CompileLog.java b/src/main/java/dk/camelot64/kickc/CompileLog.java
index a02c9b8c4..22d8f07bf 100644
--- a/src/main/java/dk/camelot64/kickc/CompileLog.java
+++ b/src/main/java/dk/camelot64/kickc/CompileLog.java
@@ -85,6 +85,11 @@ public class CompileLog {
*/
private boolean verboseSsaSourceCode = false;
+ /**
+ * Print verbose info in the fix long branch fix pass
+ */
+ private boolean verboseFixLongBranch = false;
+
/**
* Should the log be output to System.out while being built
*/
@@ -132,6 +137,14 @@ public class CompileLog {
this.verboseSsaSourceCode = verboseSsaSourceCode;
}
+ public boolean isVerboseFixLongBranch() {
+ return verboseFixLongBranch;
+ }
+
+ public void setVerboseFixLongBranch(boolean verboseFixLongBranch) {
+ this.verboseFixLongBranch = verboseFixLongBranch;
+ }
+
public boolean isVerboseCreateSsa() {
return verboseCreateSsa;
}
diff --git a/src/main/java/dk/camelot64/kickc/KickC.java b/src/main/java/dk/camelot64/kickc/KickC.java
index 13f2b1935..96f1d5953 100644
--- a/src/main/java/dk/camelot64/kickc/KickC.java
+++ b/src/main/java/dk/camelot64/kickc/KickC.java
@@ -146,6 +146,9 @@ public class KickC implements Callable {
@CommandLine.Option(names = {"-vasmoptimize"}, description = "Verbosity Option. Assembler optimization.")
private boolean verboseAsmOptimize = false;
+ @CommandLine.Option(names = {"-vfixlongbranch"}, description = "Verbosity Option. Fix Long ASM branches.")
+ private boolean verboseFixLongBranch = false;
+
@CommandLine.Option(names = {"-Wfragment"}, description = "Warning Option. Missing fragments produces a warning instead of an error.")
private boolean warnFragmentMissing = false;
@@ -564,6 +567,11 @@ public class KickC implements Callable {
compiler.getLog().setVerboseAsmOptimize(true);
compiler.getLog().setSysOut(true);
}
+ if(verboseFixLongBranch) {
+ compiler.getLog().setVerboseFixLongBranch(true);
+ compiler.getLog().setSysOut(true);
+ }
+
}
/**
diff --git a/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java b/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java
index 78fba5c8c..5ee381c90 100644
--- a/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java
+++ b/src/main/java/dk/camelot64/kickc/passes/Pass5FixLongBranches.java
@@ -80,30 +80,37 @@ public class Pass5FixLongBranches extends Pass5AsmOptimization {
} catch(Throwable e) {
if(e instanceof AssertionError && e.getMessage().contains("Invalid number of bytes in memblock!")) {
throw new CompileError("Error! KickAssembler failed due to assertion. Please run java without -ea / -enableassertions.", e);
- } else {
+ } else {
throw new CompileError("Error! KickAssembler failed, while trying to fix long branch. " + e);
}
- } finally {
+ } finally {
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
String output = kickAssOut.toString();
+ if(getLog().isVerboseFixLongBranch())
+ getLog().append("Pass5FixLongBranches: ASM process result " + asmRes);
+
// Look for a long branch distance error
if(asmRes != 0) {
String outputLines[] = output.split("\\r?\\n");
+ if(getLog().isVerboseFixLongBranch())
+ getLog().append("Pass5FixLongBranches: Number of ASM lines " + outputLines.length);
for(int i = 0; i < outputLines.length; i++) {
String outputLine = outputLines[i];
if(outputLine.contains("Error: relative address is illegal (jump distance is too far).")) {
// Found a long branch!
String contextLine = outputLines[i + 1];
+ if(getLog().isVerboseFixLongBranch())
+ getLog().append("Pass5FixLongBranches: Found long branch " + contextLine);
Pattern contextPattern = Pattern.compile("at line ([0-9]*),.*");
Matcher matcher = contextPattern.matcher(contextLine);
- //getLog().append("Found long branch "+contextLine);
if(matcher.matches()) {
String contextLineIdxStr = matcher.group(1);
int contextLineIdx = Integer.parseInt(contextLineIdxStr);
// Found line number
- //getLog().append("Found long branch line number "+contextLineIdx);
+ if(getLog().isVerboseFixLongBranch())
+ getLog().append("Pass5FixLongBranches: Found long branch line number " + contextLineIdx);
if(fixLongBranch(contextLineIdx - 1)) {
return true;
}
@@ -138,7 +145,7 @@ public class Pass5FixLongBranches extends Pass5AsmOptimization {
String branchDest = asmInstruction.getOperandJumpTarget();
asmInstruction.setCpuOpcode(inverseCpuOpcode);
String newLabel = AsmFormat.asmFix("!" + branchDest);
- asmInstruction.setOperandJumpTarget(newLabel+"+");
+ asmInstruction.setOperandJumpTarget(newLabel + "+");
CpuOpcode jmpOpcode = getAsmProgram().getTargetCpu().getCpu65xx().getOpcode("jmp", CpuAddressingMode.ABS, false);
AsmInstruction jmpInstruction = new AsmInstruction(jmpOpcode, branchDest, null);
asmChunk.addLineAfter(asmInstruction, jmpInstruction);
@@ -186,7 +193,7 @@ public class Pass5FixLongBranches extends Pass5AsmOptimization {
}
private static File getTmpFile(Path tmpDir, String fileName) {
- return new File(tmpDir.toFile(), fileName );
+ return new File(tmpDir.toFile(), fileName);
}
}