fix: include correct main position and don't re-create label
This commit is contained in:
@@ -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)
|
||||||
|
|||||||
@@ -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(_)),
|
||||||
|
|||||||
@@ -210,12 +210,12 @@ object assemblyIR {
|
|||||||
case Size(label: LabelDef, expr: SizeExpr)
|
case Size(label: LabelDef, expr: SizeExpr)
|
||||||
|
|
||||||
override def toString(): String = this match {
|
override def toString(): String = this match {
|
||||||
case IntelSyntax => ".intel_syntax noprefix"
|
case IntelSyntax => ".intel_syntax noprefix"
|
||||||
case Global(name) => s".globl $name"
|
case Global(name) => s".globl $name"
|
||||||
case Text => ".text"
|
case Text => ".text"
|
||||||
case RoData => ".section .rodata"
|
case RoData => ".section .rodata"
|
||||||
case Int(value) => s"\t.int $value"
|
case Int(value) => s"\t.int $value"
|
||||||
case Asciz(string) => s"\t.asciz \"$string\""
|
case Asciz(string) => s"\t.asciz \"$string\""
|
||||||
case File(no, file) => s".file $no \"${file}\""
|
case File(no, file) => s".file $no \"${file}\""
|
||||||
case Location(fileNo, lineNo, colNo) =>
|
case Location(fileNo, lineNo, colNo) =>
|
||||||
s"\t.loc $fileNo $lineNo" + colNo.map(c => s" $c").getOrElse("")
|
s"\t.loc $fileNo $lineNo" + colNo.map(c => s" $c").getOrElse("")
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user