mirror of
https://github.com/irmen/prog8.git
synced 2025-01-10 20:30:23 +00:00
slight tweak to codegenerator backend interface
This commit is contained in:
parent
fc253237c9
commit
48fed4e6fb
@ -13,7 +13,5 @@ interface ICodeGeneratorBackend {
|
||||
|
||||
interface IAssemblyProgram {
|
||||
val name: String
|
||||
fun assemble(options: CompilationOptions): Boolean
|
||||
fun assemble(options: CompilationOptions, errors: IErrorReporter): Boolean
|
||||
}
|
||||
|
||||
fun viceMonListName(baseFilename: String) = "$baseFilename.vice-mon-list"
|
||||
|
@ -16,5 +16,7 @@ class C64Target: ICompilationTarget, IStringEncoding by Encoder, IMemSizer by Cb
|
||||
|
||||
companion object {
|
||||
const val NAME = "c64"
|
||||
|
||||
fun viceMonListName(baseFilename: String) = "$baseFilename.vice-mon-list"
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package prog8.code.target.c128
|
||||
|
||||
import prog8.code.core.*
|
||||
import prog8.code.target.C64Target
|
||||
import prog8.code.target.cbm.Mflpt5
|
||||
import java.nio.file.Path
|
||||
|
||||
@ -40,7 +41,7 @@ class C128MachineDefinition: IMachineDefinition {
|
||||
}
|
||||
|
||||
println("\nStarting C-128 emulator x128...")
|
||||
val viceMonlist = viceMonListName(programNameWithPath.toString())
|
||||
val viceMonlist = C64Target.viceMonListName(programNameWithPath.toString())
|
||||
val cmdline = listOf("x128", "-silent", "-moncommands", viceMonlist,
|
||||
"-autostartprgmode", "1", "-autostart-warp", "-autostart", "${programNameWithPath}.prg")
|
||||
val processb = ProcessBuilder(cmdline).inheritIO()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package prog8.code.target.c64
|
||||
|
||||
import prog8.code.core.*
|
||||
import prog8.code.target.C64Target
|
||||
import prog8.code.target.cbm.Mflpt5
|
||||
import java.io.IOException
|
||||
import java.nio.file.Path
|
||||
@ -42,7 +43,7 @@ class C64MachineDefinition: IMachineDefinition {
|
||||
|
||||
for(emulator in listOf("x64sc", "x64")) {
|
||||
println("\nStarting C-64 emulator $emulator...")
|
||||
val viceMonlist = viceMonListName(programNameWithPath.toString())
|
||||
val viceMonlist = C64Target.viceMonListName(programNameWithPath.toString())
|
||||
val cmdline = listOf(emulator, "-silent", "-moncommands", viceMonlist,
|
||||
"-autostartprgmode", "1", "-autostart-warp", "-autostart", "${programNameWithPath}.prg")
|
||||
val processb = ProcessBuilder(cmdline).inheritIO()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package prog8.code.target.cx16
|
||||
|
||||
import prog8.code.core.*
|
||||
import prog8.code.target.C64Target
|
||||
import prog8.code.target.cbm.Mflpt5
|
||||
import java.nio.file.Path
|
||||
|
||||
@ -43,7 +44,7 @@ class CX16MachineDefinition: IMachineDefinition {
|
||||
}
|
||||
2 -> {
|
||||
emulator = "box16"
|
||||
extraArgs = listOf("-sym", viceMonListName(programNameWithPath.toString()))
|
||||
extraArgs = listOf("-sym", C64Target.viceMonListName(programNameWithPath.toString()))
|
||||
}
|
||||
else -> {
|
||||
System.err.println("Cx16 target only supports x16emu and box16 emulators.")
|
||||
|
@ -4,6 +4,7 @@ import com.github.michaelbull.result.Ok
|
||||
import com.github.michaelbull.result.Result
|
||||
import com.github.michaelbull.result.mapError
|
||||
import prog8.code.core.*
|
||||
import prog8.code.target.C64Target
|
||||
import java.io.File
|
||||
import java.nio.file.Path
|
||||
import kotlin.io.path.Path
|
||||
@ -19,10 +20,10 @@ internal class AssemblyProgram(
|
||||
private val prgFile = outputDir.resolve("$name.prg") // CBM prg executable program
|
||||
private val xexFile = outputDir.resolve("$name.xex") // Atari xex executable program
|
||||
private val binFile = outputDir.resolve("$name.bin")
|
||||
private val viceMonListFile = outputDir.resolve(viceMonListName(name))
|
||||
private val viceMonListFile = outputDir.resolve(C64Target.viceMonListName(name))
|
||||
private val listFile = outputDir.resolve("$name.list")
|
||||
|
||||
override fun assemble(options: CompilationOptions): Boolean {
|
||||
override fun assemble(options: CompilationOptions, errors: IErrorReporter): Boolean {
|
||||
|
||||
val assemblerCommand: List<String>
|
||||
|
||||
|
@ -26,7 +26,7 @@ class VmCodeGen: ICodeGeneratorBackend {
|
||||
|
||||
internal class VmAssemblyProgram(override val name: String, internal val irProgram: IRProgram): IAssemblyProgram {
|
||||
|
||||
override fun assemble(options: CompilationOptions): Boolean {
|
||||
override fun assemble(options: CompilationOptions, errors: IErrorReporter): Boolean {
|
||||
// the VM reads the IR file from disk.
|
||||
IRFileWriter(irProgram, null).write()
|
||||
return true
|
||||
|
@ -413,7 +413,7 @@ private fun createAssemblyAndAssemble(program: PtProgram,
|
||||
errors.report()
|
||||
|
||||
return if(assembly!=null && errors.noErrors()) {
|
||||
assembly.assemble(compilerOptions)
|
||||
assembly.assemble(compilerOptions, errors)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
@ -158,14 +158,13 @@ Some notes and references into the compiler's source code modules:
|
||||
#. ANTLR is a Java parser generator and is used for initial parsing of the source code. (``parser`` module)
|
||||
#. Most of the compiler and the optimizer operate on the *Compiler AST*. These are complicated
|
||||
syntax nodes closely representing the Prog8 program structure. (``compilerAst`` module)
|
||||
#. For code generation, a much simpler *intermediate AST* has been defined that replaces the *Compiler AST*.
|
||||
Most notably, node type information is now baked in. (``codeCore`` module)
|
||||
#. For code generation, a much simpler AST has been defined that replaces the *Compiler AST*.
|
||||
Most notably, node type information is now baked in. (``codeCore`` module, Pt- classes)
|
||||
#. An *Intermediate Representation* has been defined that is generated from the intermediate AST. This IR
|
||||
is more or less a machine code language for a virtual machine - and indeed this is what the built-in
|
||||
prog8 VM will execute if you use the 'virtual' compilation target and use ``-emu`` to launch the VM.
|
||||
(``intermediate`` and ``codeGenIntermediate`` modules, and ``virtualmachine`` module for the VM related stuff)
|
||||
#. Currently the 6502 ASM code generator still works directly on the *Compiler AST*. A future version
|
||||
should replace this by working on the IR code, and should be much smaller and simpler.
|
||||
(``codeGenCpu6502`` module)
|
||||
#. Other code generators may either work on the intermediate AST or on the IR. Selection of what code generator
|
||||
to use is mostly based on the compilation target, and is done in the ``asmGeneratorFor()`` function.
|
||||
#. The code generator backends all implement a common interface ``ICodeGeneratorBackend`` defined in the ``codeCore`` module.
|
||||
Currently they get handed the program Ast, Symboltable and several other things.
|
||||
If the code generator wants it can use the ``IRCodeGen`` class from the ``codeGenIntermediate`` module
|
||||
to convert the Ast into IR first. The VM target uses this, but the 6502 codegen doesn't right now.
|
||||
|
Loading…
x
Reference in New Issue
Block a user