Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
7c5019b
Btor2 is now in project
szaboeva2004 Feb 25, 2025
d5e44a1
Btor2Xcfa, tests are good and running
szaboeva2004 Feb 25, 2025
3cdde30
Examples added, println changed to logger
szaboeva2004 Mar 3, 2025
f62bb8c
Merge branch 'ftsrg:master' into btor2xcfa
szaboeva2004 Mar 3, 2025
5ee57f9
Fixed up logger, count2&4 works
szaboeva2004 Mar 4, 2025
3414084
Merge branch 'btor2xcfa' of https://github.com/szaboeva2004/theta int…
szaboeva2004 Mar 4, 2025
2bd77ab
Visitors, models are reworked (ongoing)
szaboeva2004 Mar 12, 2025
3e903f4
Model reworked, grammar changed according to btor2tools
szaboeva2004 Mar 17, 2025
798b83c
Merge branch 'ftsrg:master' into btor2xcfa
szaboeva2004 Mar 17, 2025
43f8d05
Added operation expressions
szaboeva2004 Mar 25, 2025
886d110
Zsófi konzi
szaboeva2004 Mar 25, 2025
faa0235
Zsófi konzi
szaboeva2004 Mar 25, 2025
fd99e2f
fixed ref for btor2bad get expr
AdamZsofi Mar 25, 2025
72aa8a6
Small changes in models and visitors
szaboeva2004 Apr 9, 2025
ad9c4a7
Btor2 config added
szaboeva2004 Apr 12, 2025
15fa41c
Checks added
szaboeva2004 Apr 15, 2025
73ff08f
Run config added
szaboeva2004 Apr 15, 2025
1f8300e
procedure to initial proc fix
AdamZsofi Apr 15, 2025
bab1bc3
Added more resources and minuses
May 8, 2025
ad98e80
Minus still doesn't work
May 9, 2025
9b71fde
Added visitors and operations, still not working minuses
May 12, 2025
bb7446a
Binary operators working, comparison still not
May 12, 2025
72ffa57
Constants have a problem
May 13, 2025
c0823fe
create instead of of in getExpr in btor2
AdamZsofi May 13, 2025
f5b75b3
removed booltype, todo ite
AdamZsofi May 13, 2025
60ed341
Btor2Const reworked
May 13, 2025
1a5701c
package eqexpr in ite to make it bv
AdamZsofi May 13, 2025
5692252
If the types are bv why does it say it's not
May 14, 2025
3f8b214
Slice corrected
May 15, 2025
e5a5ded
ITS ALIVE
May 15, 2025
2ae4787
Hex numbers work
Jun 24, 2025
82ceee7
Sub added, fixed grammar
Jun 25, 2025
c621ca2
Fixed ite and init
Jun 26, 2025
6a3077c
Ite might be fixed
Jul 5, 2025
16e2877
Added some more specific TODOs and extended some
Jul 6, 2025
74f068b
Idk what else is wrong with ite but let's try this one
Jul 6, 2025
6315291
Took out logger from Btor2Visitor
Jul 6, 2025
4b4d9ce
Maybe ha kicserélem Notra?
Jul 6, 2025
3a62b62
Binary operations improvement?
Jul 6, 2025
643161c
ITE operation is the bane of my existence
Jul 6, 2025
abb4c24
Unary ops statement added
Jul 7, 2025
11a285f
Refactored Expressions and Stmts
Jul 7, 2025
828e8ca
Added some resources
Jul 7, 2025
5101678
Fixed some operators, bad property, decimal numbers
Jul 8, 2025
2014d7d
Bad now has getStmt
Jul 8, 2025
c4007aa
Slice works in some cases
Jul 9, 2025
cad4348
Resource added, slice might be fixed
Jul 9, 2025
98598f8
fix typo in grammar
AdamZsofi Jul 9, 2025
ca86a27
patched btor2 grammar symbol issue; improved check message
AdamZsofi Jul 9, 2025
2f5b06e
Slice, next update
Jul 10, 2025
d9f16d6
Operation negations updated
Jul 11, 2025
6269e93
We need bitwise negation so that is switched
Jul 11, 2025
bbac0e7
Next edge adding
Jul 11, 2025
d103676
added gcd example
AdamZsofi Jul 11, 2025
e8506ae
States, inputs edges improved
Jul 11, 2025
117a5bb
fixed missing location counter increase
AdamZsofi Jul 16, 2025
664f3dc
spotless formatting
AdamZsofi Jul 16, 2025
8f75faf
remove unnecessary parameter
AdamZsofi Jul 16, 2025
5daad76
btor2xcfa builder comment cleanup
AdamZsofi Jul 16, 2025
024952f
formatting and added empty edge removal to btor2 passes
AdamZsofi Jul 16, 2025
3cd03ce
fix: var refs used for operands
AdamZsofi Jul 16, 2025
30b3ee1
btor2circuit obj refactor; input fix; formatting
AdamZsofi Jul 16, 2025
35b4700
fix: which loc is loop head
AdamZsofi Jul 16, 2025
c1ac755
added bitwise trait to xcfa made from btor2
AdamZsofi Jul 16, 2025
4d91bac
parsecontext integrated to btor2xcfa
AdamZsofi Jul 16, 2025
0179f14
removeFirst to removeAt fix
AdamZsofi Jul 16, 2025
4b1f0f9
minor remove first fix
AdamZsofi Jul 16, 2025
87a8b06
added missing initial state havocs
AdamZsofi Jul 16, 2025
d5eda86
minor fix
AdamZsofi Jul 16, 2025
f80ce52
over-cautious check removed
AdamZsofi Jul 18, 2025
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
Empty file added .z3-trace
Empty file.
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include(
"common/ltl-cli",

"frontends/c-frontend",
"frontends/btor2-frontend",
"frontends/petrinet-frontend/petrinet-model",
"frontends/petrinet-frontend/petrinet-analysis",
"frontends/petrinet-frontend/petrinet-xsts",
Expand All @@ -42,6 +43,7 @@ include(
"xcfa/xcfa",
"xcfa/cat",
"xcfa/c2xcfa",
"xcfa/btor2xcfa",
"xcfa/litmus2xcfa",
"xcfa/llvm2xcfa",
"xcfa/xcfa2chc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class OcCheckerBase<E : Event> : OcChecker<E> {
if (from == to) return reason // cycle (self-loop) found
val toClose = mutableListOf(from to to to reason)
while (toClose.isNotEmpty()) {
val (fromTo, r) = toClose.removeFirst()
val (fromTo, r) = toClose.removeAt(0)
val (i1, i2) = fromTo
check(i1 != i2)
if (rels[i1][i2] != null) continue
Expand Down Expand Up @@ -160,7 +160,7 @@ abstract class OcCheckerBase<E : Event> : OcChecker<E> {
val unassignedCopy = unassignedWss.toMutableList()
val pairs = mutableListOf<Pair<Relation<E>, Relation<E>>>()
while (unassignedCopy.isNotEmpty()) {
val ws = unassignedCopy.removeFirst()
val ws = unassignedCopy.removeAt(0)
val pair = unassignedCopy.find { it.from == ws.to || it.to == ws.from }
if (pair != null) {
pairs.add(ws to pair)
Expand Down
1 change: 1 addition & 0 deletions subprojects/frontends/btor2-frontend/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Soon...
24 changes: 24 additions & 0 deletions subprojects/frontends/btor2-frontend/build.gradle.kts
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"))
}
74 changes: 74 additions & 0 deletions subprojects/frontends/btor2-frontend/src/main/antlr/Btor2.g4
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 {
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)
Loading