mirror of
https://github.com/GayPizzaSpecifications/pork.git
synced 2025-08-03 13:11:32 +00:00
bir: mutable values and inspection
This commit is contained in:
@ -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))
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user