From 73864c810174e24e45c9a3a10bc64ae9f0bf0567 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Tue, 26 Dec 2023 15:30:18 +0100 Subject: [PATCH] added -check command line option --- compiler/res/prog8lib/virtual/floats.p8 | 2 ++ compiler/src/prog8/CompilerMain.kt | 17 +++++++++++++---- docs/source/compiling.rst | 3 +++ docs/source/todo.rst | 2 +- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/compiler/res/prog8lib/virtual/floats.p8 b/compiler/res/prog8lib/virtual/floats.p8 index 5ac120312..beed68e96 100644 --- a/compiler/res/prog8lib/virtual/floats.p8 +++ b/compiler/res/prog8lib/virtual/floats.p8 @@ -174,6 +174,7 @@ sub normalize(float value) -> float { } sub push(float value) { + ; note: this *should* be inlined, however since the VM has separate program counter and value stacks, this also works %ir {{ loadm.f fr65535,floats.push.value push.f fr65535 @@ -182,6 +183,7 @@ sub push(float value) { } sub pop() -> float { + ; note: this *should* be inlined, however since the VM has separate program counter and value stacks, this also works %ir {{ pop.f fr65535 returnr.f fr65535 diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index cfb79679f..04d9c7777 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -37,6 +37,7 @@ fun pathFrom(stringPath: String, vararg rest: String): Path = FileSystems.getDe private fun compileMain(args: Array): Boolean { val cli = ArgParser("prog8compiler", prefixStyle = ArgParser.OptionPrefixStyle.JVM) val asmListfile by cli.option(ArgType.Boolean, fullName = "asmlist", description = "make the assembler produce a listing file as well") + val checkSource by cli.option(ArgType.Boolean, fullName = "check", description = "quickly check program for errors, no output will be produced") val symbolDefs by cli.option(ArgType.String, fullName = "D", description = "define assembly symbol(s) with -D SYMBOL=VALUE").multiple() val startEmulator1 by cli.option(ArgType.Boolean, fullName = "emu", description = "auto-start emulator after successful compilation") val startEmulator2 by cli.option(ArgType.Boolean, fullName = "emu2", description = "auto-start alternative emulator after successful compilation") @@ -142,8 +143,8 @@ private fun compileMain(args: Array): Boolean { val filepath = pathFrom(filepathRaw).normalize() val compilerArgs = CompilerArguments( filepath, - dontOptimize != true, - dontWriteAssembly != true, + if(checkSource==true) false else dontOptimize != true, + if(checkSource==true) false else dontWriteAssembly != true, warnSymbolShadowing == true, quietAssembler == true, asmListfile == true, @@ -161,6 +162,10 @@ private fun compileMain(args: Array): Boolean { outputPath ) val compilationResult = compileProgram(compilerArgs) + + if(checkSource==true) + println("No output produced.") + if(compilationResult!=null) results.add(compilationResult) } @@ -214,8 +219,8 @@ private fun compileMain(args: Array): Boolean { try { val compilerArgs = CompilerArguments( filepath, - dontOptimize != true, - dontWriteAssembly != true, + if(checkSource==true) false else dontOptimize != true, + if(checkSource==true) false else dontWriteAssembly != true, warnSymbolShadowing == true, quietAssembler == true, asmListfile == true, @@ -233,6 +238,10 @@ private fun compileMain(args: Array): Boolean { outputPath ) val result = compileProgram(compilerArgs) + + if(checkSource==true) + println("No output produced.") + if(result==null) return false else diff --git a/docs/source/compiling.rst b/docs/source/compiling.rst index dde1a4ed9..35ab3685d 100644 --- a/docs/source/compiling.rst +++ b/docs/source/compiling.rst @@ -172,6 +172,9 @@ One or more .p8 module files ``-asmlist`` Generate an assembler listing file as well. +``-check`` + Quickly check the program for errors. No output will be produced. + ``-breakinstr`` Also output a CPU instruction for a ``%breakpoint``, as well as the entry in the vice monitor list file. This can be useful on emulators/systems that don't parse the breakpoint information in the list file, diff --git a/docs/source/todo.rst b/docs/source/todo.rst index d3dd9dc1b..5b57b5e57 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -2,7 +2,7 @@ TODO ==== -- add -nowarnunused, or %option ignore_unused (module scope), to suppress all warnings about unused symbols. Useful in libraries. +- add -nowarnunused, or %option ignore_unused (module and block scope), to suppress all warnings about unused symbols. Useful in libraries. put this in all library code, like %option no_symbol_prefixing, and get rid of the "trick" it uses currently to suppress unused symbol warnings for library modules. - [on branch: shortcircuit] investigate McCarthy evaluation again? this may also reduce code size perhaps for things like if a>4 or a<2 ....