2021-07-17 08:37:58 +00:00
|
|
|
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
|
2021-07-17 08:37:58 +00:00
|
|
|
|
2021-07-30 15:39:43 +00:00
|
|
|
|
2021-07-17 08:37:58 +00:00
|
|
|
internal fun compileFile(
|
|
|
|
platform: ICompilationTarget,
|
|
|
|
optimize: Boolean,
|
|
|
|
fileDir: Path,
|
|
|
|
fileName: String,
|
2022-06-26 16:51:03 +00:00
|
|
|
outputDir: Path = prog8tests.helpers.outputDir,
|
2021-10-21 23:25:26 +00:00
|
|
|
errors: IErrorReporter? = null,
|
2021-11-09 02:45:07 +00:00
|
|
|
writeAssembly: Boolean = true,
|
2022-03-07 20:41:12 +00:00
|
|
|
) : CompilationResult? {
|
2021-07-17 08:37:58 +00:00
|
|
|
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(
|
2021-07-17 08:37:58 +00:00
|
|
|
filepath,
|
|
|
|
optimize,
|
2021-10-21 23:25:26 +00:00
|
|
|
writeAssembly = writeAssembly,
|
2023-07-30 15:10:54 +00:00
|
|
|
warnSymbolShadowing = false,
|
2021-10-30 13:26:40 +00:00
|
|
|
quietAssembler = true,
|
2021-12-30 13:38:40 +00:00
|
|
|
asmListfile = false,
|
2023-08-02 19:26:40 +00:00
|
|
|
includeSourcelines = false,
|
2022-02-05 20:25:19 +00:00
|
|
|
experimentalCodegen = false,
|
2024-02-10 17:42:31 +00:00
|
|
|
dumpVariables = false,
|
2024-04-09 16:30:56 +00:00
|
|
|
dumpSymbols = false,
|
2023-06-26 22:27:34 +00:00
|
|
|
varsHighBank = null,
|
2023-12-23 19:11:50 +00:00
|
|
|
varsGolden = false,
|
2023-12-23 19:45:30 +00:00
|
|
|
slabsHighBank = null,
|
|
|
|
slabsGolden = false,
|
2021-07-17 08:37:58 +00:00
|
|
|
platform.name,
|
2022-07-06 21:40:36 +00:00
|
|
|
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,
|
2024-01-22 20:07:51 +00:00
|
|
|
breakpointCpuInstruction = null,
|
2024-01-01 21:48:19 +00:00
|
|
|
printAst1 = false,
|
2024-03-03 16:48:52 +00:00
|
|
|
printAst2 = false,
|
|
|
|
strictBool = true
|
2021-07-17 08:37:58 +00:00
|
|
|
)
|
2021-11-30 00:40:21 +00:00
|
|
|
return compileProgram(args)
|
2021-07-17 08:37:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
2021-10-21 23:25:26 +00:00
|
|
|
sourceText: String,
|
|
|
|
errors: IErrorReporter? = null,
|
2021-11-09 02:45:07 +00:00
|
|
|
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")
|
2021-07-17 08:37:58 +00:00
|
|
|
// we don't assumeNotExists(filePath) - should be ok to just overwrite it
|
|
|
|
filePath.toFile().writeText(sourceText)
|
2022-09-24 11:54:00 +00:00
|
|
|
return compileFile(platform, optimize, filePath.parent, filePath.name,
|
2023-07-15 10:12:26 +00:00
|
|
|
errors=errors, writeAssembly=writeAssembly)
|
2021-11-09 02:45:07 +00:00
|
|
|
}
|