mirror of
https://github.com/irmen/prog8.git
synced 2025-12-20 12:19:39 +00:00
added symboltable into CompilationResult because it might be useful to inspect in tests
This commit is contained in:
@@ -35,6 +35,7 @@ import kotlin.time.measureTimedValue
|
|||||||
|
|
||||||
class CompilationResult(val compilerAst: Program, // deprecated, use codegenAst instead
|
class CompilationResult(val compilerAst: Program, // deprecated, use codegenAst instead
|
||||||
val codegenAst: PtProgram?,
|
val codegenAst: PtProgram?,
|
||||||
|
val codegenSymboltable: SymbolTable?,
|
||||||
val compilationOptions: CompilationOptions,
|
val compilationOptions: CompilationOptions,
|
||||||
val importedFiles: List<Path>)
|
val importedFiles: List<Path>)
|
||||||
|
|
||||||
@@ -87,6 +88,8 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
var symbolTable: SymbolTable? = null
|
||||||
|
|
||||||
val totalTime = measureTime {
|
val totalTime = measureTime {
|
||||||
val libraryDirs = if(compTarget.libraryPath!=null) listOf(compTarget.libraryPath.toString()) else emptyList()
|
val libraryDirs = if(compTarget.libraryPath!=null) listOf(compTarget.libraryPath.toString()) else emptyList()
|
||||||
val (parseresult, parseDuration) = measureTimedValue {
|
val (parseresult, parseDuration) = measureTimedValue {
|
||||||
@@ -176,19 +179,17 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
|||||||
println("*********** COMPILER AST END *************\n")
|
println("*********** COMPILER AST END *************\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
var symbolTable: SymbolTable
|
|
||||||
|
|
||||||
val (intermediateAst, simplifiedAstDuration2) = measureTimedValue {
|
val (intermediateAst, simplifiedAstDuration2) = measureTimedValue {
|
||||||
val intermediateAst = SimplifiedAstMaker(program, args.errors).transform()
|
val intermediateAst = SimplifiedAstMaker(program, args.errors).transform()
|
||||||
val stMaker = SymbolTableMaker(intermediateAst, compilationOptions)
|
val stMaker = SymbolTableMaker(intermediateAst, compilationOptions)
|
||||||
symbolTable = stMaker.make()
|
symbolTable = stMaker.make()
|
||||||
|
|
||||||
postprocessSimplifiedAst(intermediateAst, symbolTable, compilationOptions, args.errors)
|
postprocessSimplifiedAst(intermediateAst, symbolTable!!, compilationOptions, args.errors)
|
||||||
args.errors.report()
|
args.errors.report()
|
||||||
symbolTable = stMaker.make() // need an updated ST because the postprocessing changes stuff
|
symbolTable = stMaker.make() // need an updated ST because the postprocessing changes stuff
|
||||||
|
|
||||||
if (compilationOptions.optimize) {
|
if (compilationOptions.optimize) {
|
||||||
optimizeSimplifiedAst(intermediateAst, compilationOptions, symbolTable, args.errors)
|
optimizeSimplifiedAst(intermediateAst, compilationOptions, symbolTable!!, args.errors)
|
||||||
args.errors.report()
|
args.errors.report()
|
||||||
symbolTable = stMaker.make() // need an updated ST because the optimization changes stuff
|
symbolTable = stMaker.make() // need an updated ST because the optimization changes stuff
|
||||||
}
|
}
|
||||||
@@ -208,7 +209,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
|||||||
createAssemblyDuration = measureTime {
|
createAssemblyDuration = measureTime {
|
||||||
if (!createAssemblyAndAssemble(
|
if (!createAssemblyAndAssemble(
|
||||||
intermediateAst,
|
intermediateAst,
|
||||||
symbolTable,
|
symbolTable!!,
|
||||||
args.errors,
|
args.errors,
|
||||||
compilationOptions,
|
compilationOptions,
|
||||||
program.generatedLabelSequenceNumber
|
program.generatedLabelSequenceNumber
|
||||||
@@ -249,7 +250,7 @@ fun compileProgram(args: CompilerArguments): CompilationResult? {
|
|||||||
if(!args.quietAll) {
|
if(!args.quietAll) {
|
||||||
println("\nTotal compilation+assemble time: ${totalTime.toString(DurationUnit.SECONDS, 3)}.")
|
println("\nTotal compilation+assemble time: ${totalTime.toString(DurationUnit.SECONDS, 3)}.")
|
||||||
}
|
}
|
||||||
return CompilationResult(resultingProgram!!, ast, compilationOptions, importedFiles)
|
return CompilationResult(resultingProgram!!, ast, symbolTable, compilationOptions, importedFiles)
|
||||||
} catch (px: ParseError) {
|
} catch (px: ParseError) {
|
||||||
args.errors.printSingleError("${px.position.toClickableStr()} parse error: ${px.message}".trim())
|
args.errors.printSingleError("${px.position.toClickableStr()} parse error: ${px.message}".trim())
|
||||||
} catch (ac: ErrorsReportedException) {
|
} catch (ac: ErrorsReportedException) {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import io.kotest.matchers.shouldNotBe
|
|||||||
import io.kotest.matchers.string.shouldContain
|
import io.kotest.matchers.string.shouldContain
|
||||||
import io.kotest.matchers.string.shouldStartWith
|
import io.kotest.matchers.string.shouldStartWith
|
||||||
import io.kotest.matchers.types.instanceOf
|
import io.kotest.matchers.types.instanceOf
|
||||||
|
import prog8.code.StNodeType
|
||||||
import prog8.code.ast.*
|
import prog8.code.ast.*
|
||||||
import prog8.code.core.BaseDataType
|
import prog8.code.core.BaseDataType
|
||||||
import prog8.code.core.DataType
|
import prog8.code.core.DataType
|
||||||
@@ -81,6 +82,12 @@ main {
|
|||||||
val assign = start.children[2] as PtAssignment
|
val assign = start.children[2] as PtAssignment
|
||||||
assign.target.identifier!!.name shouldBe "cx16.r0"
|
assign.target.identifier!!.name shouldBe "cx16.r0"
|
||||||
assign.value shouldBe instanceOf<PtBinaryExpression>()
|
assign.value shouldBe instanceOf<PtBinaryExpression>()
|
||||||
|
|
||||||
|
val st = result.codegenSymboltable!!
|
||||||
|
st.flat.size shouldBeGreaterThan 100
|
||||||
|
st.flat["cbm.CHROUT"]?.type shouldBe StNodeType.EXTSUB
|
||||||
|
st.lookup("cbm.CHROUT")?.type shouldBe StNodeType.EXTSUB
|
||||||
|
st.lookupUnscoped("sizeof")?.type shouldBe StNodeType.BUILTINFUNC
|
||||||
}
|
}
|
||||||
|
|
||||||
test("peek and poke argument types") {
|
test("peek and poke argument types") {
|
||||||
|
|||||||
Reference in New Issue
Block a user