From 11c000f7643d9334d07e0eb3aecf4060f314a089 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Mon, 26 Sep 2022 19:52:12 +0200 Subject: [PATCH] moved codeGenVirtual module into virtualmachine module --- codeGenVirtual/build.gradle | 66 ------------------- codeGenVirtual/codeGenVirtual.iml | 21 ------ compiler/build.gradle | 1 - compiler/compiler.iml | 3 +- compiler/src/prog8/compiler/Compiler.kt | 3 +- docs/source/technical.rst | 2 +- docs/source/todo.rst | 1 - settings.gradle | 1 - virtualmachine/build.gradle | 1 + .../src/prog8/vm/codegen}/VmCodeGen.kt | 16 ++--- virtualmachine/virtualmachine.iml | 1 + 11 files changed, 11 insertions(+), 105 deletions(-) delete mode 100644 codeGenVirtual/build.gradle delete mode 100644 codeGenVirtual/codeGenVirtual.iml rename {codeGenVirtual/src/prog8/codegen/virtual => virtualmachine/src/prog8/vm/codegen}/VmCodeGen.kt (70%) diff --git a/codeGenVirtual/build.gradle b/codeGenVirtual/build.gradle deleted file mode 100644 index d2803c867..000000000 --- a/codeGenVirtual/build.gradle +++ /dev/null @@ -1,66 +0,0 @@ - -plugins { - id 'java' - id 'application' - id "org.jetbrains.kotlin.jvm" - id "io.kotest" version "0.3.9" -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(javaVersion) - } -} - -compileKotlin { - kotlinOptions { - jvmTarget = javaVersion - } -} - -compileTestKotlin { - kotlinOptions { - jvmTarget = javaVersion - } -} - -dependencies { - implementation project(':codeCore') - implementation project(':intermediate') - implementation project(':codeGenIntermediate') - implementation project(':virtualmachine') - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" - // implementation "org.jetbrains.kotlin:kotlin-reflect" - implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.16" - - testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.3.2' -} - -sourceSets { - main { - java { - srcDirs = ["${project.projectDir}/src"] - } - resources { - srcDirs = ["${project.projectDir}/res"] - } - } - test { - java { - srcDir "${project.projectDir}/test" - } - } -} - -test { - // Enable JUnit 5 (Gradle 4.6+). - useJUnitPlatform() - - // Always run tests, even when nothing changed. - dependsOn 'cleanTest' - - // Show test results. - testLogging { - events "skipped", "failed" - } -} diff --git a/codeGenVirtual/codeGenVirtual.iml b/codeGenVirtual/codeGenVirtual.iml deleted file mode 100644 index 8a466fb93..000000000 --- a/codeGenVirtual/codeGenVirtual.iml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/compiler/build.gradle b/compiler/build.gradle index c74d14b12..7193556db 100644 --- a/compiler/build.gradle +++ b/compiler/build.gradle @@ -31,7 +31,6 @@ dependencies { implementation project(':codeOptimizers') implementation project(':compilerAst') implementation project(':codeGenCpu6502') - implementation project(':codeGenVirtual') implementation project(':codeGenExperimental') implementation project(':virtualmachine') implementation 'org.antlr:antlr4-runtime:4.10.1' diff --git a/compiler/compiler.iml b/compiler/compiler.iml index 7d5c118e1..3803d9874 100644 --- a/compiler/compiler.iml +++ b/compiler/compiler.iml @@ -21,7 +21,6 @@ - - \ No newline at end of file + diff --git a/compiler/src/prog8/compiler/Compiler.kt b/compiler/src/prog8/compiler/Compiler.kt index 8c6e3d9dd..2b8ec57fd 100644 --- a/compiler/src/prog8/compiler/Compiler.kt +++ b/compiler/src/prog8/compiler/Compiler.kt @@ -17,6 +17,7 @@ import prog8.code.target.* import prog8.compiler.astprocessing.* import prog8.optimizer.* import prog8.parser.ParseError +import prog8.vm.codegen.VmCodeGen import java.nio.file.Path import kotlin.io.path.Path import kotlin.io.path.nameWithoutExtension @@ -455,7 +456,7 @@ internal fun asmGeneratorFor(program: Program, return prog8.codegen.cpu6502.AsmGen(program, symbolTable, options, errors) if (options.compTarget.name == VMTarget.NAME) { val intermediateAst = IntermediateAstMaker(program).transform() - return prog8.codegen.virtual.VmCodeGen(intermediateAst, symbolTable, options, errors) + return VmCodeGen(intermediateAst, symbolTable, options, errors) } } diff --git a/docs/source/technical.rst b/docs/source/technical.rst index ea2295792..465afbb40 100644 --- a/docs/source/technical.rst +++ b/docs/source/technical.rst @@ -139,7 +139,7 @@ Some notes and references into the compiler's source code modules: #. 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' compilaton target and use ``-emu`` to launch the VM. - (``intermediate`` and ``codeGenIntermediate`` modules, and ``codeGenVirtual`` and ``virtualmachine`` module for the VM related stuff) + (``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) diff --git a/docs/source/todo.rst b/docs/source/todo.rst index 5e182902a..01344e718 100644 --- a/docs/source/todo.rst +++ b/docs/source/todo.rst @@ -3,7 +3,6 @@ TODO For next release ^^^^^^^^^^^^^^^^ -- vm: move codeGenVirtual module into virtualmachine module? - vm: actually translate IRProgram to vm program list again. - docs: modify compiler arch picture once this is done. diff --git a/settings.gradle b/settings.gradle index 7cb2988ad..04a20a70c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -6,7 +6,6 @@ include( ':codeOptimizers', ':virtualmachine', ':codeGenIntermediate', - ':codeGenVirtual', ':codeGenCpu6502', ':codeGenExperimental', ':compiler', diff --git a/virtualmachine/build.gradle b/virtualmachine/build.gradle index 95a9fb1a8..53cfa899f 100644 --- a/virtualmachine/build.gradle +++ b/virtualmachine/build.gradle @@ -27,6 +27,7 @@ compileTestKotlin { dependencies { implementation project(':codeCore') implementation project(':intermediate') + implementation project(':codeGenIntermediate') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "com.michael-bull.kotlin-result:kotlin-result-jvm:1.1.16" testImplementation 'io.kotest:kotest-runner-junit5-jvm:5.3.2' diff --git a/codeGenVirtual/src/prog8/codegen/virtual/VmCodeGen.kt b/virtualmachine/src/prog8/vm/codegen/VmCodeGen.kt similarity index 70% rename from codeGenVirtual/src/prog8/codegen/virtual/VmCodeGen.kt rename to virtualmachine/src/prog8/vm/codegen/VmCodeGen.kt index 9bde3c480..5b747ea6a 100644 --- a/codeGenVirtual/src/prog8/codegen/virtual/VmCodeGen.kt +++ b/virtualmachine/src/prog8/vm/codegen/VmCodeGen.kt @@ -1,4 +1,4 @@ -package prog8.codegen.virtual +package prog8.vm.codegen import prog8.code.SymbolTable import prog8.code.ast.PtProgram @@ -22,14 +22,8 @@ class VmCodeGen(private val program: PtProgram, val irCodeGen = IRCodeGen(program, symbolTable, options, errors) val irProgram = irCodeGen.generate() - return if(options.keepIR) { - //create IR file on disk and read it back. - val irFile = IRFileWriter(irProgram, null).write() - val irProgram2 = IRFileReader().read(irFile) - VmAssemblyProgram(irProgram2.name, irProgram2) - } else { - VmAssemblyProgram(irProgram.name, irProgram) - } + // no need to check options.keepIR, as the VM file format *is* the IR file. + return VmAssemblyProgram(irProgram.name, irProgram) } companion object { @@ -44,8 +38,8 @@ class VmCodeGen(private val program: PtProgram, internal class VmAssemblyProgram(override val name: String, private val irProgram: IRProgram): IAssemblyProgram { override fun assemble(options: CompilationOptions): Boolean { - val writtenFile = IRFileWriter(irProgram, null).write() - println("Wrote intermediate representation to $writtenFile") + // the VM reads the IR file from disk. + IRFileWriter(irProgram, null).write() return true } } diff --git a/virtualmachine/virtualmachine.iml b/virtualmachine/virtualmachine.iml index 6cf1ccbbb..c03a653ff 100644 --- a/virtualmachine/virtualmachine.iml +++ b/virtualmachine/virtualmachine.iml @@ -14,5 +14,6 @@ + \ No newline at end of file