fix: include correct main position and don't re-create label

This commit is contained in:
2025-03-14 15:51:34 +00:00
parent 8f7c902ed5
commit 68435207fe
6 changed files with 12 additions and 16 deletions

View File

@@ -51,9 +51,9 @@ private class LabelGenerator {
permittedFuncFile match { permittedFuncFile match {
case Some(f) if f != pos.file.getCanonicalPath => Chain.empty case Some(f) if f != pos.file.getCanonicalPath => Chain.empty
case _ => case _ =>
val customLabel = if name == "main" then Chain.empty else Chain(LabelDef(name))
permittedFuncFile = Some(pos.file.getCanonicalPath) permittedFuncFile = Some(pos.file.getCanonicalPath)
Chain( customLabel ++ Chain(
LabelDef(name),
Directive.Location(getDebugFile(pos.file), pos.line, None), Directive.Location(getDebugFile(pos.file), pos.line, None),
Directive.Type(label, SymbolType.Function), Directive.Type(label, SymbolType.Function),
Directive.Func(name, label) Directive.Func(name, label)

View File

@@ -37,11 +37,7 @@ object asmGenerator {
val Program(funcs, main) = microProg val Program(funcs, main) = microProg
val mainLabel = LabelDef("main") val mainLabel = LabelDef("main")
val mainAsm = main.headOption match { val mainAsm = labelGenerator.getDebugFunc(microProg.pos, "main", mainLabel) + mainLabel
case Some(stmt) =>
labelGenerator.getDebugFunc(stmt.pos, "$main", mainLabel) + mainLabel
case None => Chain.one(mainLabel)
}
val progAsm = mainAsm.concatAll( val progAsm = mainAsm.concatAll(
funcPrologue(), funcPrologue(),
main.foldMap(generateStmt(_)), main.foldMap(generateStmt(_)),

View File

@@ -93,5 +93,5 @@ object microWacc {
// Program // Program
case class FuncDecl(name: Ident, params: List[Ident], body: Chain[Stmt])(val pos: Position) case class FuncDecl(name: Ident, params: List[Ident], body: Chain[Stmt])(val pos: Position)
case class Program(funcs: Chain[FuncDecl], stmts: Chain[Stmt]) case class Program(funcs: Chain[FuncDecl], stmts: Chain[Stmt])(val pos: Position)
} }

View File

@@ -200,7 +200,7 @@ object renamer {
(chunks :+ func, errors ++ scope.add(name, public = true)) (chunks :+ func, errors ++ scope.add(name, public = true))
} }
// ...and main body. // ...and main body.
val mainBodyIdent = Ident(MAIN, ty = FuncType(?, Nil))(prog.pos) val mainBodyIdent = Ident(MAIN, ty = FuncType(?, Nil))(main.head.pos)
val mainBodyErrors = scope.add(mainBodyIdent, public = false) val mainBodyErrors = scope.add(mainBodyIdent, public = false)
val mainBodyChunk = FuncDecl(IntType()(prog.pos), mainBodyIdent, Nil, main)(prog.pos) val mainBodyChunk = FuncDecl(IntType()(prog.pos), mainBodyIdent, Nil, main)(prog.pos)

View File

@@ -36,7 +36,7 @@ object semantics {
case Some((head, tail)) => (head.body, tail) case Some((head, tail)) => (head.body, tail)
case None => (Chain.empty, Chain.empty) case None => (Chain.empty, Chain.empty)
} }
} yield (microWacc.Program(funcs, typedMain), globalErrors ++ errors) } yield (microWacc.Program(funcs, typedMain)(main.pos), globalErrors ++ errors)
} }
} }