Skip to content

Commit

Permalink
Merge pull request #205 from UQ-PAC/spec-registers
Browse files Browse the repository at this point in the history
Lets you refer to registers in existing spec language by naive pattern match on the name of idents.
  • Loading branch information
ailrst authored Jun 4, 2024
2 parents b6a2409 + 9cab102 commit 9292109
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions src/main/scala/translating/SpecificationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ case class SpecificationLoader(symbols: Set[SpecGlobal], program: Program) {

def visitId(ctx: IdContext, nameToGlobals: Map[String, SpecGlobal], params: Map[String, Parameter] = Map()): BExpr = {
val id = ctx.getText
if (id.startsWith("Gamma_")) {
id match {
case id if id.startsWith("Gamma_R") => {
BVariable(id, BoolBType, Scope.Global)
}
case id if (id.startsWith("Gamma_")) => {
val gamma_id = id.stripPrefix("Gamma_")
params.get(gamma_id) match {
case Some(p: Parameter) => p.value.toGamma
Expand All @@ -327,26 +331,31 @@ case class SpecificationLoader(symbols: Set[SpecGlobal], program: Program) {
case Some(g: SpecGlobal) => SpecGamma(g)
case None => throw new Exception(s"unresolvable reference to '$id' in specification")
}
}
}
case id if id.startsWith("R") => {
BVariable(id, BitVecBType(64), Scope.Global)
}
case id => {
params.get(id) match {
case Some(p: Parameter) =>
val registerSize = p.value.size
val paramSize = p.size
if (paramSize == registerSize) {
p.value.toBoogie
} else if (registerSize > paramSize) {
BVExtract(registerSize - p.size, 0, p.value.toBoogie)
} else {
throw Exception(s"parameter $p doesn't fit in register ${p.value} for ID $id")
}
case None =>
nameToGlobals.get(ctx.getText) match {
case Some(g: SpecGlobal) => g
case None => throw new Exception(s"unresolvable reference to '$id' in specification")
}
}
}
} else {
params.get(id) match {
case Some(p: Parameter) =>
val registerSize = p.value.size
val paramSize = p.size
if (paramSize == registerSize) {
p.value.toBoogie
} else if (registerSize > paramSize) {
BVExtract(registerSize - p.size, 0, p.value.toBoogie)
} else {
throw Exception(s"parameter $p doesn't fit in register ${p.value} for ID $id")
}
case None =>
nameToGlobals.get(ctx.getText) match {
case Some(g: SpecGlobal) => g
case None => throw new Exception(s"unresolvable reference to '$id' in specification")
}
}
}
}

def visitMulDivModOp(ctx: MulDivModOpContext): BVBinOp = ctx.getText match {
Expand Down

0 comments on commit 9292109

Please sign in to comment.