-
Notifications
You must be signed in to change notification settings - Fork 51
Btor2Xcfa #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Btor2Xcfa #348
Changes from all commits
7c5019b
d5e44a1
3cdde30
f62bb8c
5ee57f9
3414084
2bd77ab
3e903f4
798b83c
43f8d05
886d110
faa0235
fd99e2f
72aa8a6
ad9c4a7
15fa41c
73ff08f
1f8300e
bab1bc3
ad98e80
9b71fde
bb7446a
72ffa57
c0823fe
f5b75b3
60ed341
1a5701c
5692252
3f8b214
e5a5ded
2ae4787
82ceee7
c621ca2
6a3077c
16e2877
74f068b
6315291
4b4d9ce
3a62b62
643161c
abb4c24
11a285f
828e8ca
5101678
2014d7d
c4007aa
cad4348
98598f8
ca86a27
2f5b06e
d9f16d6
6269e93
bbac0e7
d103676
e8506ae
117a5bb
664f3dc
8f75faf
5daad76
024952f
3cd03ce
30b3ee1
35b4700
c1ac755
4d91bac
0179f14
4b1f0f9
87a8b06
d5eda86
f80ce52
78a643c
58b44c5
84d710f
8b8a0db
be3015d
0b55508
0ce42ae
0347786
b30a08d
0c87660
f53a47f
2787c75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Soon... | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think soon is now - feel free to reuse the PR description, I think that turned out well. :) |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Copyright 2025 Budapest University of Technology and Economics | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| plugins { | ||
| id("kotlin-common") | ||
| id("antlr-grammar") | ||
| } | ||
| dependencies { | ||
| implementation(project(":theta-core")) | ||
| implementation(project(":theta-common")) | ||
| implementation(project(":theta-grammar")) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // WARNING: this grammar is NOT an official BTOR2 grammar and will accept invalid btor2 circuits. | ||
| // Check your circuit with catbtor before using this grammar! | ||
| grammar Btor2; | ||
|
|
||
| // Lexer rules | ||
| WS: [ ]+ -> skip; | ||
| UNARYOP: 'not' | ||
| | 'inc' | 'dec' | 'neg' | ||
| | 'redand' | 'redor' | 'redxor'; | ||
| TERNARYOP: 'ite' | 'write'; | ||
| BINOP: 'and' | 'nand' | 'nor' | 'or' | 'xnor' | 'xor' | 'iff' | 'implies' | ||
| | 'eq' | 'neq' | ||
| | 'slt' | 'slte' | 'sgt' | 'sgte' | ||
| | 'ult' | 'ulte' | 'ugt' | 'ugte' | ||
| | 'concat' | 'add' | 'mul' | 'sub' | ||
| | 'udiv' | 'urem' | ||
| | 'sdiv' | 'srem' | 'smod' | ||
| | 'saddo' | 'sdivo' | 'smulo' | 'ssubo' | ||
| | 'uaddo' | 'umulo' | 'usubo' | ||
| | 'rol' | 'ror' | 'sll' | 'sra' | 'srl' | 'read'; | ||
| NUM: (MINUS)? (HEX | BIN | DEC); | ||
| HEX: [0-9a-fA-F]+; | ||
| BIN: [0-1]+; | ||
| DEC: [0-9]+; | ||
| PLUS: '+'; | ||
| MINUS: '-'; | ||
| COMMENT: ';' ~[\r\n]+; | ||
| SYMBOL: ~[ \r\n]+; | ||
| NEWLINE: [\r\n]+; | ||
|
|
||
| // Parser rules | ||
| btor2: (line NEWLINE)* line (NEWLINE)* EOF; | ||
|
|
||
| line: comment | node (symbol)? (comment)?; | ||
|
|
||
| comment: COMMENT; | ||
|
|
||
| nid: NUM; | ||
| sid: NUM; | ||
|
|
||
| node: ( array_sort | bitvec_sort ) #sort // sort declaration | ||
| | (input | state | init | next | property) #stateful | ||
| | (opidx | op) #operation | ||
| | (filled_constant | constant | constant_d | constant_h) #constantNode; | ||
|
|
||
| opidx: ext | slice; | ||
|
|
||
| ext: id=nid operator=('uext'|'sext') sid opd1=nid w=NUM; | ||
| slice: id=nid 'slice' sid opd1=nid u=NUM l=NUM; | ||
|
|
||
| op: binop | unop | terop; | ||
|
|
||
| binop: id=nid BINOP sid opd1=nid opd2=nid; | ||
| unop: id=nid UNARYOP sid opd1=nid; | ||
| terop: id=nid TERNARYOP sid opd1=nid opd2=nid opd3=nid; | ||
|
|
||
| input: id=nid ('input') sid; | ||
|
|
||
| init: id=nid 'init' sid param1=nid param2=nid; | ||
| next: id=nid 'next' sid param1=nid param2=nid; | ||
|
|
||
| state: id=nid 'state' sid; | ||
|
|
||
| property: id=nid property_type=('bad' | 'constraint' | 'fair' | 'output' | 'justice' ) param=nid; | ||
|
|
||
| array_sort: id=sid 'sort array' sid1=sid sid2=sid; | ||
| bitvec_sort: id=sid 'sort bitvec' width=NUM; | ||
|
|
||
| constant: id=nid 'const' sid bin=NUM; | ||
| constant_d: id=nid 'constd' sid dec=NUM; | ||
| constant_h: id=nid 'consth' sid hex=NUM; | ||
| filled_constant: id=nid fill=('one' | 'ones' | 'zero') sid; | ||
|
|
||
| symbol: (SYMBOL | NUM); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * Copyright 2025 Budapest University of Technology and Economics | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package hu.bme.mit.theta.frontend.models | ||
|
|
||
| import hu.bme.mit.theta.core.decl.Decls | ||
| import hu.bme.mit.theta.core.decl.VarDecl | ||
| import hu.bme.mit.theta.core.type.Expr | ||
| import hu.bme.mit.theta.core.type.bvtype.BvExprs | ||
| import hu.bme.mit.theta.core.type.bvtype.BvType | ||
|
|
||
| data class Btor2Const( | ||
| override val nid: UInt, | ||
| val value: BooleanArray, | ||
| override val sort: Btor2Sort, | ||
| ) : Btor2Node(nid, sort) { | ||
| val declsVar = Decls.Var("const_$nid", BvExprs.BvType(sort.width.toInt())) | ||
|
|
||
| override fun getVar(): VarDecl<*>? { | ||
| return declsVar | ||
| } | ||
|
|
||
| override fun getExpr(): Expr<BvType> { | ||
| return declsVar.ref as Expr<BvType> | ||
| } | ||
|
|
||
| override fun <R, P> accept(visitor: Btor2NodeVisitor<R, P>, param: P): R { | ||
| return visitor.visit(this, param) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| /* | ||
| * Copyright 2025 Budapest University of Technology and Economics | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package hu.bme.mit.theta.frontend.models | ||
|
|
||
| import hu.bme.mit.theta.core.decl.VarDecl | ||
| import hu.bme.mit.theta.core.type.Expr | ||
|
|
||
| interface Btor2NodeVisitor<R, P> { | ||
| fun visit(node: Btor2UnaryOperation, param: P): R | ||
|
|
||
| fun visit(node: Btor2BinaryOperation, param: P): R | ||
|
|
||
| fun visit(node: Btor2TernaryOperation, param: P): R | ||
|
|
||
| fun visit(node: Btor2SliceOperation, param: P): R | ||
|
|
||
| fun visit(node: Btor2ExtOperation, param: P): R | ||
|
|
||
| fun visit(node: Btor2Comparison, param: P): R | ||
|
|
||
| fun visit(node: Btor2Boolean, param: P): R | ||
|
|
||
| fun visit(node: Btor2BitvecSort, param: P): R | ||
|
|
||
| fun visit(node: Btor2Input, param: P): R | ||
|
|
||
| fun visit(node: Btor2State, param: P): R | ||
|
|
||
| fun visit(node: Btor2Init, param: P): R | ||
|
|
||
| fun visit(node: Btor2Next, param: P): R | ||
|
|
||
| fun visit(node: Btor2Bad, param: P): R | ||
|
|
||
| fun visit(node: Btor2Const, param: P): R | ||
| } | ||
|
|
||
| object Btor2Circuit { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the parsed circuit being a singleton object is not a good pattern, we should instantiate a different object for each parsing. |
||
| private val _nodes = mutableMapOf<UInt, Btor2Node>() | ||
| private val _sorts = mutableMapOf<UInt, Btor2Sort>() | ||
| private val _constants = mutableMapOf<UInt, Btor2Const>() | ||
| private val _ops = mutableMapOf<UInt, Btor2Operation>() | ||
| private val _states = mutableMapOf<UInt, Btor2Stateful>() | ||
| private val _properties = mutableMapOf<UInt, Btor2Bad>() | ||
|
|
||
| val nodes: Map<UInt, Btor2Node> | ||
| get() = _nodes | ||
|
|
||
| val sorts: Map<UInt, Btor2Sort> | ||
| get() = _sorts | ||
|
|
||
| val constants: Map<UInt, Btor2Const> | ||
| get() = _constants | ||
|
|
||
| val ops: Map<UInt, Btor2Operation> | ||
| get() = _ops | ||
|
|
||
| val states: Map<UInt, Btor2Stateful> | ||
| get() = _states | ||
|
|
||
| val properties: Map<UInt, Btor2Bad> | ||
| get() = _properties | ||
|
|
||
| fun addSort(sort: Btor2Sort) { | ||
| _sorts[sort.sid] = sort | ||
| } | ||
|
|
||
| fun addNode(node: Btor2Node) { | ||
| _nodes[node.nid] = node | ||
| when (node) { | ||
| is Btor2Const -> _constants[node.nid] = node | ||
| is Btor2Operation -> _ops[node.nid] = node | ||
| is Btor2Stateful -> _states[node.nid] = node | ||
| is Btor2Bad -> _properties[node.nid] = node | ||
| else -> error("Btor2Circuit cannot sort this type: ${node.javaClass}") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // sortID lookup in Btor2Sort | ||
| abstract class Btor2Node(id: UInt, btor2Sort: Btor2Sort? = null) { | ||
| abstract val nid: UInt | ||
| abstract val sort: Btor2Sort? | ||
|
|
||
| open fun getVar(): VarDecl<*>? { | ||
| return null | ||
| } | ||
|
|
||
| abstract fun <R, P> accept(visitor: Btor2NodeVisitor<R, P>, param: P): R | ||
|
|
||
| abstract fun getExpr(): Expr<*> | ||
| } | ||
|
|
||
| abstract class Btor2Sort(sid: UInt, width: UInt) { | ||
| abstract val sid: UInt | ||
| abstract val width: UInt | ||
| } | ||
|
|
||
| // Ezt egyelőre nem használjuk mert csak bitvektoraink vannak | ||
| data class Btor2BitvecSort(override val sid: UInt, override val width: UInt) : | ||
| Btor2Sort(sid, width) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please remove this