prog8/compiler/test/helpers/compileXyz.kt

69 lines
2.1 KiB
Kotlin
Raw Normal View History

package prog8tests.helpers
2022-09-27 14:32:44 +00:00
import prog8.code.core.ICompilationTarget
import prog8.code.core.IErrorReporter
2021-10-29 03:28:02 +00:00
import prog8.compiler.CompilationResult
2021-11-30 00:40:21 +00:00
import prog8.compiler.CompilerArguments
2021-10-29 03:28:02 +00:00
import prog8.compiler.compileProgram
2021-10-10 22:22:04 +00:00
import java.nio.file.Path
import kotlin.io.path.name
internal fun compileFile(
platform: ICompilationTarget,
optimize: Boolean,
fileDir: Path,
fileName: String,
2022-06-26 16:51:03 +00:00
outputDir: Path = prog8tests.helpers.outputDir,
errors: IErrorReporter? = null,
writeAssembly: Boolean = true,
2022-03-07 20:41:12 +00:00
) : CompilationResult? {
val filepath = fileDir.resolve(fileName)
2022-06-26 16:51:03 +00:00
assumeReadableFile(filepath)
2021-11-30 00:40:21 +00:00
val args = CompilerArguments(
filepath,
optimize,
writeAssembly = writeAssembly,
warnSymbolShadowing = false,
quietAssembler = true,
asmListfile = false,
includeSourcelines = false,
experimentalCodegen = false,
dumpVariables = false,
dumpSymbols = false,
2023-06-26 22:27:34 +00:00
varsHighBank = null,
varsGolden = false,
slabsHighBank = null,
slabsGolden = false,
platform.name,
symbolDefs = emptyMap(),
2021-11-30 00:40:21 +00:00
outputDir = outputDir,
2023-05-30 17:08:34 +00:00
errors = errors ?: ErrorReporterForTests(),
2023-10-15 19:55:09 +00:00
splitWordArrays = false,
breakpointCpuInstruction = null,
printAst1 = false,
2024-03-03 16:48:52 +00:00
printAst2 = false,
ignoreFootguns = false,
)
2021-11-30 00:40:21 +00:00
return compileProgram(args)
}
/**
* Takes a [sourceText] as a String, writes it to a temporary
* file and then runs the compiler on that.
* @see compileFile
*/
internal fun compileText(
platform: ICompilationTarget,
optimize: Boolean,
sourceText: String,
errors: IErrorReporter? = null,
writeAssembly: Boolean = true,
2022-03-07 20:41:12 +00:00
) : CompilationResult? {
2022-06-26 16:51:03 +00:00
val filePath = outputDir.resolve("on_the_fly_test_" + sourceText.hashCode().toUInt().toString(16) + ".p8")
// we don't assumeNotExists(filePath) - should be ok to just overwrite it
filePath.toFile().writeText(sourceText)
return compileFile(platform, optimize, filePath.parent, filePath.name,
2023-07-15 10:12:26 +00:00
errors=errors, writeAssembly=writeAssembly)
}