bir: mutable values and inspection

This commit is contained in:
2023-12-27 16:44:32 -08:00
parent 962d079acc
commit 35ce58bb44
36 changed files with 125 additions and 66 deletions

View File

@ -4,16 +4,26 @@ import com.charleskorn.kaml.PolymorphismStyle
import com.charleskorn.kaml.Yaml
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.parameters.arguments.argument
import com.github.ajalt.clikt.parameters.options.flag
import com.github.ajalt.clikt.parameters.options.option
import gay.pizza.dough.fs.PlatformFsProvider
import gay.pizza.pork.ast.gen.Symbol
import gay.pizza.pork.bir.IrSymbolGraph
import gay.pizza.pork.bir.IrWorld
import gay.pizza.pork.bytecode.CompiledWorld
import gay.pizza.pork.compiler.Compiler
import gay.pizza.pork.minimal.FileTool
class CompileCommand : CliktCommand(help = "Compile Pork to Bytecode", name = "compile") {
class CompileCommand : CliktCommand(help = "Compile Pork", name = "compile") {
val showIrCode by option("--show-ir-code").flag(default = false)
val showIrSymbolGraph by option("--show-ir-symbol-graph").flag(default = false)
val path by argument("file")
private val yaml = Yaml(configuration = Yaml.default.configuration.copy(
polymorphismStyle = PolymorphismStyle.Property
))
override fun run() {
val tool = FileTool(PlatformFsProvider.resolve(path))
val world = tool.buildWorld()
@ -22,16 +32,22 @@ class CompileCommand : CliktCommand(help = "Compile Pork to Bytecode", name = "c
val compiledSlab = compiler.compilableSlabs.of(slab)
val compiledMain = compiledSlab.resolve(Symbol("main"))
?: throw RuntimeException("'main' function not found.")
val compiledWorld = compiler.compile(compiledMain)
val irWorld = compiler.compileIrWorld()
printCompiledIr(irWorld)
val compiledWorld = compiler.compile(compiledMain)
if (showIrCode) {
printCompiledIr(irWorld)
}
if (showIrSymbolGraph) {
val irSymbolGraph = IrSymbolGraph()
irSymbolGraph.buildFromRoot(irWorld)
println(yaml.encodeToString(IrSymbolGraph.serializer(), irSymbolGraph))
}
printCompiledWorld(compiledWorld)
}
private fun printCompiledIr(irWorld: IrWorld) {
val yaml = Yaml(configuration = Yaml.default.configuration.copy(
polymorphismStyle = PolymorphismStyle.Property
))
println(yaml.encodeToString(IrWorld.serializer(), irWorld))
}