From 4b3f31c2ee3927414a7dfca393f885899d50310a Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Sat, 30 Oct 2021 15:26:40 +0200 Subject: [PATCH] added option to suppress assembler output (and enabled this in unit tests) --- .../src/prog8/compiler/target/cbm/AssemblyProgram.kt | 5 ++++- compiler/src/prog8/CompilerMain.kt | 9 +++++++-- compiler/src/prog8/compiler/Compiler.kt | 6 ++++-- compiler/test/TestCompilerOnExamples.kt | 1 + compiler/test/TestCompilerOptionLibdirs.kt | 1 + compiler/test/helpers/compileXyz.kt | 1 + .../src/prog8/compilerinterface/IAssemblyGenerator.kt | 2 +- httpCompilerService/src/prog8/http/TestHttp.kt | 3 ++- 8 files changed, 21 insertions(+), 7 deletions(-) diff --git a/codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt b/codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt index 6190d8669..01256b881 100644 --- a/codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt +++ b/codeGeneration/src/prog8/compiler/target/cbm/AssemblyProgram.kt @@ -27,12 +27,15 @@ class AssemblyProgram( private val binFile = outputDir.resolve("$name.bin") private val viceMonListFile = outputDir.resolve("$name.$viceMonListPostfix") - override fun assemble(options: CompilationOptions): Int { + override fun assemble(quiet: Boolean, options: CompilationOptions): Int { // add "-Wlong-branch" to see warnings about conversion of branch instructions to jumps (default = do this silently) val command = mutableListOf("64tass", "--ascii", "--case-sensitive", "--long-branch", "-Wall", "-Wno-strict-bool", "-Wno-shadow", // "-Werror", "--dump-labels", "--vice-labels", "-l", viceMonListFile.toString(), "--no-monitor") + if(quiet) + command.add("--quiet") + val outFile = when (options.output) { OutputType.PRG -> { command.add("--cbm-prg") diff --git a/compiler/src/prog8/CompilerMain.kt b/compiler/src/prog8/CompilerMain.kt index f9c258068..65c4354ac 100644 --- a/compiler/src/prog8/CompilerMain.kt +++ b/compiler/src/prog8/CompilerMain.kt @@ -38,6 +38,7 @@ private fun compileMain(args: Array): Boolean { val dontOptimize by cli.option(ArgType.Boolean, fullName = "noopt", description = "don't perform any optimizations") val watchMode by cli.option(ArgType.Boolean, fullName = "watch", description = "continuous compilation mode (watches for file changes), greatly increases compilation speed") val slowCodegenWarnings by cli.option(ArgType.Boolean, fullName = "slowwarn", description="show debug warnings about slow/problematic assembly code generation") + val quietAssembler by cli.option(ArgType.Boolean, fullName = "quietasm", description = "don't print assembler output results") val compilationTarget by cli.option(ArgType.String, fullName = "target", description = "target output of the compiler, currently '${C64Target.name}' and '${Cx16Target.name}' available").default(C64Target.name) val sourceDirs by cli.option(ArgType.String, fullName="srcdirs", description = "list of extra paths, separated with ${File.pathSeparator}, to search in for imported modules").multiple().delimiter(File.pathSeparator) val moduleFiles by cli.argument(ArgType.String, fullName = "modules", description = "main module file(s) to compile").multiple(999) @@ -74,7 +75,9 @@ private fun compileMain(args: Array): Boolean { val results = mutableListOf() for(filepathRaw in moduleFiles) { val filepath = pathFrom(filepathRaw).normalize() - val compilationResult = compileProgram(filepath, dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, compilationTarget, srcdirs, outputPath) + val compilationResult = compileProgram(filepath, + dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, quietAssembler==true, + compilationTarget, srcdirs, outputPath) results.add(compilationResult) } @@ -111,7 +114,9 @@ private fun compileMain(args: Array): Boolean { val filepath = pathFrom(filepathRaw).normalize() val compilationResult: CompilationResult try { - compilationResult = compileProgram(filepath, dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, compilationTarget, srcdirs, outputPath) + compilationResult = compileProgram(filepath, + dontOptimize!=true, dontWriteAssembly!=true, slowCodegenWarnings==true, quietAssembler==true, + compilationTarget, srcdirs, outputPath) if(!compilationResult.success) return false } catch (x: ParsingFailedError) { diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 2665f08ea..3b7109505 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -34,6 +34,7 @@ fun compileProgram(filepath: Path, optimize: Boolean, writeAssembly: Boolean, slowCodegenWarnings: Boolean, + quietAssembler: Boolean, compilationTarget: String, sourceDirs: List, outputDir: Path, @@ -71,7 +72,7 @@ fun compileProgram(filepath: Path, // printAst(program) if (writeAssembly) { - val result = writeAssembly(program, errors, outputDir, compilationOptions) + val result = writeAssembly(program, errors, outputDir, quietAssembler, compilationOptions) when (result) { is WriteAssemblyResult.Ok -> programName = result.filename is WriteAssemblyResult.Fail -> { @@ -308,6 +309,7 @@ private sealed class WriteAssemblyResult { private fun writeAssembly(program: Program, errors: IErrorReporter, outputDir: Path, + quietAssembler: Boolean, compilerOptions: CompilationOptions ): WriteAssemblyResult { // asm generation directly from the Ast @@ -325,7 +327,7 @@ private fun writeAssembly(program: Program, outputDir).compileToAssembly() return if(assembly.valid && errors.noErrors()) { - val assemblerReturnStatus = assembly.assemble(compilerOptions) + val assemblerReturnStatus = assembly.assemble(quietAssembler, compilerOptions) if(assemblerReturnStatus!=0) WriteAssemblyResult.Fail("assembler step failed with return code $assemblerReturnStatus") else { diff --git a/compiler/test/TestCompilerOnExamples.kt b/compiler/test/TestCompilerOnExamples.kt index 174967668..20ab55cc8 100644 --- a/compiler/test/TestCompilerOnExamples.kt +++ b/compiler/test/TestCompilerOnExamples.kt @@ -44,6 +44,7 @@ class TestCompilerOnExamples { optimize, writeAssembly = true, slowCodegenWarnings = false, + quietAssembler = true, compilationTarget = platform.name, sourceDirs = listOf(), outputDir diff --git a/compiler/test/TestCompilerOptionLibdirs.kt b/compiler/test/TestCompilerOptionLibdirs.kt index 9b4972bfe..83ae7207d 100644 --- a/compiler/test/TestCompilerOptionLibdirs.kt +++ b/compiler/test/TestCompilerOptionLibdirs.kt @@ -49,6 +49,7 @@ class TestCompilerOptionSourcedirs { optimize = false, writeAssembly = true, slowCodegenWarnings = false, + quietAssembler = true, compilationTarget = Cx16Target.name, sourceDirs, outputDir diff --git a/compiler/test/helpers/compileXyz.kt b/compiler/test/helpers/compileXyz.kt index 8fc8fe42f..4951d5298 100644 --- a/compiler/test/helpers/compileXyz.kt +++ b/compiler/test/helpers/compileXyz.kt @@ -42,6 +42,7 @@ internal fun compileFile( optimize, writeAssembly = writeAssembly, slowCodegenWarnings = false, + quietAssembler = true, platform.name, sourceDirs = listOf(), outputDir, diff --git a/compilerInterfaces/src/prog8/compilerinterface/IAssemblyGenerator.kt b/compilerInterfaces/src/prog8/compilerinterface/IAssemblyGenerator.kt index 934485fec..4cf4e4c69 100644 --- a/compilerInterfaces/src/prog8/compilerinterface/IAssemblyGenerator.kt +++ b/compilerInterfaces/src/prog8/compilerinterface/IAssemblyGenerator.kt @@ -11,5 +11,5 @@ const val subroutineFloatEvalResultVar2 = "_prog8_float_eval_result2" interface IAssemblyProgram { val valid: Boolean val name: String - fun assemble(options: CompilationOptions): Int + fun assemble(quiet: Boolean, options: CompilationOptions): Int } diff --git a/httpCompilerService/src/prog8/http/TestHttp.kt b/httpCompilerService/src/prog8/http/TestHttp.kt index f89c38378..e7363169f 100644 --- a/httpCompilerService/src/prog8/http/TestHttp.kt +++ b/httpCompilerService/src/prog8/http/TestHttp.kt @@ -35,7 +35,8 @@ class RequestParser : Take { slowCodegenWarnings = true, compilationTarget = "c64", sourceDirs = emptyList(), - outputDir = Path.of("") + outputDir = Path.of(""), + quietAssembler = false ) return RsJson(Jsonding()) }