Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions src/main/scala/translating/PrettyPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ import scala.collection.mutable

private val localSigils = false

/*
Santises variables names

BinCaml requires that there are no dots in variable names
*/
def santise_var_name(name: String): String =
return name.replace(".", "__")

object PrettyPrinter {

type PrettyPrintable = Program | Procedure | Statement | Jump | Command | Block | Expr | IRContext
Expand Down Expand Up @@ -569,18 +577,21 @@ class BasilIRPrettyPrinter(
case m: MapType => s"(${vtype(m.param)} -> ${vtype(m.result)})"
}

override def vrvar(e: Variable): PPProg[Variable] = e match {
case l: LocalVar =>
val sigil = if localSigils then Sigil.BASIR.localVar else ""
BST(s"${sigil}${e.name}:${vtype(e.getType)}")
case l: Global => BST(s"${Sigil.BASIR.globalVar}${e.name}:${vtype(e.getType)}")
}
override def vrvar(e: Variable): PPProg[Variable] =
val namefixed = santise_var_name(e.name)
e match {
case l: LocalVar =>
val sigil = if localSigils then Sigil.BASIR.localVar else ""
BST(s"${sigil}${namefixed}:${vtype(e.getType)}")
case l: Global => BST(s"${Sigil.BASIR.globalVar}${namefixed}:${vtype(e.getType)}")
}
override def vlvar(e: Variable): PPProg[Variable] = {
val namefixed = santise_var_name(e.name)
e match {
case l: LocalVar =>
val sigil = if localSigils then Sigil.BASIR.localVar else ""
BST(s"var $sigil${e.name}: ${vtype(e.getType)}")
case l: Global => BST(s"${Sigil.BASIR.globalVar}${e.name}: ${vtype(e.getType)}")
BST(s"var $sigil${namefixed}: ${vtype(e.getType)}")
case l: Global => BST(s"${Sigil.BASIR.globalVar}${namefixed}: ${vtype(e.getType)}")
}
}

Expand Down
Loading