diff --git a/docs/api/command-line.md b/docs/api/command-line.md index 27d30837..21c9ccc2 100644 --- a/docs/api/command-line.md +++ b/docs/api/command-line.md @@ -278,3 +278,37 @@ By default, the compiler emits only some of the most important warnings. * `-Wnone` – Disable all warnings. * `-Wfatal` – Treat warnings as errors. + +You can also enable or disable warnings individually: + +* `-Wbuggy`, `-Wno-buggy` – + Whether should warn about code that may cause surprising behaviours or even miscompilation. + Default: enabled. + +* `-Wdeprecation`, `-Wno-deprecation` – + Whether should warn about deprecated aliases. + Default: enabled. + +* `-Wextra-comparisons`, `-Wno-extra-comparisons` – + Whether should warn about simplifiable unsigned integer comparisons. + Default: disabled. + +* `-Wfallback`, `-Wno-fallback` – + Whether should warn about the use of default values by text codecs, the preprocessor, and array literals. + Default: enabled. + +* `-Wmissing-output`, `-Wno-missing-output` – + Whether should warn about data that is missing in output files. + Default: enabled. + +* `-Woverlapping-call`, `-Wno-overlapping-call` – + Whether should warn about calls to functions in a different, yet overlapping segment. + Default: enabled. + +* `-Wror`, `-Wno-ror` – + Whether should warn about the ROR instruction (6502 only). + Default: disabled. + +* `-Wuseless`, `-Wno-useless` – + Whether should warn about code that does nothing. + Default: enabled. diff --git a/src/main/scala/millfork/CompilationOptions.scala b/src/main/scala/millfork/CompilationOptions.scala index 687c8709..3c67cbfb 100644 --- a/src/main/scala/millfork/CompilationOptions.scala +++ b/src/main/scala/millfork/CompilationOptions.scala @@ -413,8 +413,20 @@ object Cpu extends Enumeration { import CompilationFlag._ private val alwaysDefaultFlags = Set( - VariableOverlap, CompactReturnDispatchParams, FunctionFallthrough, RegisterVariables, FunctionDeduplication, EnableBreakpoints, - GenericWarnings, UselessCodeWarning, BuggyCodeWarning, FallbackValueUseWarning, DeprecationWarning, NonZeroTerminatedLiteralWarning, CallToOverlappingBankWarning, + VariableOverlap, + CompactReturnDispatchParams, + FunctionFallthrough, + RegisterVariables, + FunctionDeduplication, + EnableBreakpoints, + GenericWarnings, + UselessCodeWarning, + BuggyCodeWarning, + FallbackValueUseWarning, + DeprecationWarning, + NonZeroTerminatedLiteralWarning, + CallToOverlappingBankWarning, + DataMissingInOutputWarning, ) private val mosAlwaysDefaultFlags = alwaysDefaultFlags @@ -578,12 +590,23 @@ object CompilationFlag extends Enumeration { RorWarning, NonZeroTerminatedLiteralWarning, CallToOverlappingBankWarning, + DataMissingInOutputWarning, FatalWarnings, // special options for internal compiler use EnableInternalTestSyntax, InternalCurrentlyOptimizingForMeasurement = Value - val allWarnings: Set[CompilationFlag.Value] = Set(GenericWarnings, UselessCodeWarning, BuggyCodeWarning, DeprecationWarning, FallbackValueUseWarning, ExtraComparisonWarnings, NonZeroTerminatedLiteralWarning, CallToOverlappingBankWarning) + val allWarnings: Set[CompilationFlag.Value] = Set( + GenericWarnings, + UselessCodeWarning, + BuggyCodeWarning, + DeprecationWarning, + FallbackValueUseWarning, + ExtraComparisonWarnings, + NonZeroTerminatedLiteralWarning, + CallToOverlappingBankWarning, + DataMissingInOutputWarning, + ) val fromString: Map[String, CompilationFlag.Value] = Map( "lunix" -> LUnixRelocatableCode, diff --git a/src/main/scala/millfork/Main.scala b/src/main/scala/millfork/Main.scala index bf2c0017..f0a039ed 100644 --- a/src/main/scala/millfork/Main.scala +++ b/src/main/scala/millfork/Main.scala @@ -781,6 +781,40 @@ object Main { c.changeFlag(CompilationFlag.FatalWarnings, true) }.description("Treat warnings as errors.") + fluff("", "Specific warning options:", "") + + boolean("-Wbuggy", "-Wno-buggy").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.BuggyCodeWarning, v) + }.description("Whether should warn about code that may cause surprising behaviours or even miscompilation. Default: enabled.") + + boolean("-Wdeprecation", "-Wno-deprecation").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.DeprecationWarning, v) + }.description("Whether should warn about deprecated aliases. Default: enabled.") + + boolean("-Wextra-comparisons", "-Wno-extra-comparisons").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.ExtraComparisonWarnings, v) + }.description("Whether should warn about simplifiable unsigned integer comparisons. Default: disabled.") + + boolean("-Wfallback", "-Wno-fallback").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.FallbackValueUseWarning, v) + }.description("Whether should warn about the use of default values by text codecs, the preprocessor, and array literals. Default: enabled.") + + boolean("-Wmissing-output", "-Wno-missing-output").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.DataMissingInOutputWarning, v) + }.description("Whether should warn about data that is missing in output files. Default: enabled.") + + boolean("-Woverlapping-call", "-Wno-overlapping-call").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.CallToOverlappingBankWarning, v) + }.description("Whether should warn about calls to functions in a different, yet overlapping segment. Default: enabled.") + + boolean("-Wror", "-Wno-ror").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.RorWarning, v) + }.description("Whether should warn about the ROR instruction (6502 only). Default: disabled.") + + boolean("-Wuseless", "-Wno-useless").repeatable().action { (c, v) => + c.changeFlag(CompilationFlag.UselessCodeWarning, v) + }.description("Whether should warn about code that does nothing. Default: enabled.") + fluff("", "Other options:", "") expansion("-Xd")("-O1", "-s", "-fsource-in-asm", "-g").description("Do a debug build. Equivalent to -O1 -s -fsource-in-asm -g") diff --git a/src/main/scala/millfork/output/AbstractAssembler.scala b/src/main/scala/millfork/output/AbstractAssembler.scala index 9dac2ea2..64c77c1f 100644 --- a/src/main/scala/millfork/output/AbstractAssembler.scala +++ b/src/main/scala/millfork/output/AbstractAssembler.scala @@ -718,11 +718,13 @@ abstract class AbstractAssembler[T <: AbstractCode](private val program: Program val outputPackager = platform.outputPackagers.getOrElse(b, platform.defaultOutputPackager) b -> outputPackager.packageOutput(mem, b) }.toMap - for (bank <- mem.banks.keys.toSeq.sorted) { - val missing = mem.banks(bank).initializedNotOutputted - if (missing.nonEmpty) { - val missingFormatted = MathUtils.collapseConsecutiveInts(missing, i => f"$$$i%04x") - log.warn(s"Fragments of segment ${bank} are not contained in any output: $missingFormatted") + if (options.flag(CompilationFlag.DataMissingInOutputWarning)) { + for (bank <- mem.banks.keys.toSeq.sorted) { + val missing = mem.banks(bank).initializedNotOutputted + if (missing.nonEmpty) { + val missingFormatted = MathUtils.collapseConsecutiveInts(missing, i => f"$$$i%04x") + log.warn(s"Fragments of segment ${bank} are not contained in any output: $missingFormatted") + } } } AssemblerOutput(code, assembly.toArray, labelMap.toList, breakpointSet.toList.sorted)