-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
242 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 0 additions & 95 deletions
95
subprojects/frontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/Btor2Visitor.kt
This file was deleted.
Oops, something went wrong.
13 changes: 8 additions & 5 deletions
13
...ontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/model/Btor2Declarations.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import hu.bme.mit.theta.frontend.model.Btor2Node | ||
import java.math.BigInteger | ||
|
||
// Declarations | ||
|
||
abstract class Btor2Sort(open val sid : Int) : Btor2Node(sid) | ||
|
||
// TODO start supporting arrays | ||
//data class Btor2ArrayDeclaration(val id: Int, val indexSort: Btor2SortDeclaration, val elementSort: Btor2SortDeclaration) | ||
data class Btor2BvSortDeclaration(val id: Int, val width: Int) : Btor2Node(id) | ||
// data class Btor2ArrayDeclaration(val id: Int, val indexSort: Btor2SortDeclaration, val elementSort: Btor2SortDeclaration) | ||
data class Btor2BvSort(override val sid: Int, val width: Int) : Btor2Sort(sid) | ||
|
||
// Constants | ||
data class Btor2ConstDeclaration(val id: Int, val value: Int, val type: Btor2BvSortDeclaration) : Btor2Node(id) // it can be in binary, decimal or hex in the circuit, but we extract the actual value to the int from that | ||
data class Btor2Const(override val nid: Int, val value: BigInteger, val type: Btor2BvSort) : Btor2Node(nid) // it can be in binary, decimal or hex in the circuit, but we extract the actual value to the int from that | ||
|
||
// Inputs and States | ||
data class Btor2InputDeclaration(val id: Int, val type: Btor2BvSortDeclaration) : Btor2Node(id) | ||
data class Btor2StateDeclaration(val id: Int, val type: Btor2BvSortDeclaration) : Btor2Node(id) | ||
data class Btor2Input(override val nid: Int, val type: Btor2BvSort) : Btor2Node(nid) | ||
data class Btor2State(override val nid: Int, val type: Btor2BvSort) : Btor2Node(nid) |
2 changes: 1 addition & 1 deletion
2
...jects/frontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/model/Btor2Node.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package hu.bme.mit.theta.frontend.model | ||
|
||
open class Btor2Node(val nid: Int) | ||
open class Btor2Node(open val nid: Int) |
10 changes: 5 additions & 5 deletions
10
.../frontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/model/Btor2Operators.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../frontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/visitor/Btor2Visitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package hu.bme.mit.theta.frontend.visitor | ||
|
||
import Btor2Sort | ||
import hu.bme.mit.theta.btor2.frontend.dsl.gen.Btor2BaseVisitor | ||
import hu.bme.mit.theta.btor2.frontend.dsl.gen.Btor2Parser | ||
import hu.bme.mit.theta.frontend.model.Btor2Node | ||
import java.util.LinkedHashMap | ||
|
||
class Btor2Visitor : Btor2BaseVisitor<Btor2Node>() { | ||
val idVisitor = IdVisitor() | ||
val sortVisitor = SortVisitor(idVisitor) | ||
val sorts = LinkedHashMap<Int, Btor2Sort>() | ||
val constantVisitor = ConstantVisitor(idVisitor, sorts) | ||
|
||
// Parser rules | ||
override fun visitBtor2(ctx: Btor2Parser.Btor2Context): Btor2Node { | ||
return visitChildren(ctx) // TODO | ||
} | ||
|
||
override fun visitLine(ctx: Btor2Parser.LineContext): Btor2Node { | ||
return visitChildren(ctx) // TODO | ||
} | ||
|
||
override fun visitSort(ctx: Btor2Parser.SortContext): Btor2Node { | ||
val newSort = sortVisitor.visit(ctx) | ||
check(!sorts.containsKey(newSort.nid)) | ||
sorts[newSort.nid] = newSort | ||
return newSort | ||
} | ||
|
||
override fun visitConstantNode(ctx: Btor2Parser.ConstantNodeContext): Btor2Node { | ||
val newConstant = constantVisitor.visit(ctx) | ||
return newConstant | ||
} | ||
|
||
//////////////////// | ||
|
||
override fun visitInput(ctx: Btor2Parser.InputContext): Btor2Node { | ||
// Implementation for visiting input rule | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun visitInit(ctx: Btor2Parser.InitContext): Btor2Node { | ||
// Implementation for visiting init rule | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun visitNext(ctx: Btor2Parser.NextContext): Btor2Node { | ||
// Implementation for visiting next rule | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun visitState(ctx: Btor2Parser.StateContext): Btor2Node { | ||
// Implementation for visiting state rule | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun visitProperty(ctx: Btor2Parser.PropertyContext): Btor2Node { | ||
// Implementation for visiting property rule | ||
throw NotImplementedError() | ||
} | ||
|
||
override fun visitSymbol(ctx: Btor2Parser.SymbolContext): Btor2Node { | ||
// Implementation for visiting symbol rule | ||
throw NotImplementedError() | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...ontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/visitor/ConstantVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package hu.bme.mit.theta.frontend.visitor | ||
|
||
import Btor2BvSort | ||
import Btor2Const | ||
import Btor2Sort | ||
import hu.bme.mit.theta.btor2.frontend.dsl.gen.Btor2BaseVisitor | ||
import hu.bme.mit.theta.btor2.frontend.dsl.gen.Btor2Parser | ||
import java.math.BigInteger | ||
|
||
class ConstantVisitor(val idVisitor : IdVisitor, val sorts : Map<Int, Btor2Sort>) : Btor2BaseVisitor<Btor2Const>() { | ||
override fun visitConstantNode(ctx: Btor2Parser.ConstantNodeContext): Btor2Const { | ||
check(ctx.childCount==1) | ||
return ctx.children[0].accept(this) | ||
} | ||
|
||
override fun visitConstant(ctx: Btor2Parser.ConstantContext): Btor2Const { | ||
val nid = idVisitor.visit(ctx.nid()) | ||
val sid = idVisitor.visit(ctx.sid()) | ||
val sort : Btor2BvSort = sorts[sid] as Btor2BvSort | ||
|
||
val value = BigInteger(ctx.bin.text, 2) | ||
val node = Btor2Const(nid, value, sort) | ||
return node | ||
} | ||
|
||
override fun visitConstant_d(ctx: Btor2Parser.Constant_dContext): Btor2Const { | ||
val nid = idVisitor.visit(ctx.nid()) | ||
val sid = idVisitor.visit(ctx.sid()) | ||
val sort : Btor2BvSort = sorts[sid] as Btor2BvSort | ||
|
||
var value = BigInteger(ctx.dec.text) | ||
ctx.MINUS()?.let{ value = value.multiply(BigInteger("-1")) } | ||
val node = Btor2Const(nid, value, sort) | ||
return node | ||
} | ||
|
||
override fun visitConstant_h(ctx: Btor2Parser.Constant_hContext): Btor2Const { | ||
val nid = idVisitor.visit(ctx.nid()) | ||
val sid = idVisitor.visit(ctx.sid()) | ||
val sort : Btor2BvSort = sorts[sid] as Btor2BvSort | ||
|
||
val value = BigInteger(ctx.hex.text, 16) | ||
val node = Btor2Const(nid, value, sort) | ||
return node | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...cts/frontends/btor2-frontend/src/main/java/hu/bme/mit/theta/frontend/visitor/IdVisitor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package hu.bme.mit.theta.frontend.visitor | ||
|
||
import hu.bme.mit.theta.btor2.frontend.dsl.gen.Btor2BaseVisitor | ||
import hu.bme.mit.theta.btor2.frontend.dsl.gen.Btor2Parser | ||
|
||
class IdVisitor : Btor2BaseVisitor<Int>() { | ||
override fun visitNid(ctx: Btor2Parser.NidContext): Int { | ||
val nid = ctx.NUM().text.toInt() | ||
if (nid <= 0) { | ||
throw RuntimeException("nid should be bigger than 0") | ||
} | ||
return nid | ||
} | ||
|
||
override fun visitSid(ctx: Btor2Parser.SidContext): Int { | ||
val sid = ctx.NUM().text.toInt() | ||
if (sid <= 0) { | ||
throw RuntimeException("nid should be bigger than 0") | ||
} | ||
return sid | ||
} | ||
|
||
} |
Oops, something went wrong.