bind

package module
v0.0.0-...-77a9638 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 8 Imported by: 0

README

go-stp

Go-stp provides bindings for the Simple Theorem Prover on Linux. Most operations are supported.

Installation

The bindings make use of the Simple Theorem Prover which should be setup first. After STP has been setup, just clone the repo in your $GOPATH/src folder.

git clone https://github.com/arckt/go-stp.git

Note that for the bindings to work, the stp dynamic library is assumed to be in /usr/local/lib/. If the library is unaccessible run the following.

sudo ldconfig /path/to/lib/library

Usage

The bindings could be used purely as a c wrapper which is done through cgo or with the convenient Python-like API which is used in the Python STP bindings.

An example of a golang program that uses the Python-like API.

package main

import "fmt"
import g"arckt/go-stp"

func main() {
  h := g.Init() //Initialize solver
  defer h.Destroy() //Destroy solver at end of main()

  x := h.Bitvec("x", 32) //Add symbollic variable of bitwidth 32 of name "x"

  h.add("x + 3 == 5") //Add constraint for the solver to evaluate
  res := h.Solve(x) //Tell solver to evaluate value of symbollic variable x to fulfill constraints

  fmt.Println(res[0]) //Print symbollic variable of x if it is solvable
}

Contributing

Anyone is free to contribute or suggest any changes to this repository if they are interested.

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExprString

func ExprString(e Expr) string

HIGH LEVEL API FUNCTIONS ExprString converts an Expr e into its string counterpart

func GetBVLen

func GetBVLen(e Expr) int

GetBVLen returns the bitvector length of an Expr e

func RegisterErrorHandler

func RegisterErrorHandler()

SOLVER RELATED FUNCTIONS RegisterErrorHandler registers an error handler which triggers when there is an error in the C api

Types

type Expr

type Expr C.Expr

type Solver

type Solver struct {
	// contains filtered or unexported fields
}

func Init

func Init() Solver

CreateValidityChecker initializes the stp checker

func (*Solver) Add

func (s *Solver) Add(in string)

Add adds constraints to a solver through a string in

func (*Solver) AndExpr

func (s *Solver) AndExpr(left, right Expr) Expr

BOOLEAN RELATED FUNCTIONS AndExpr returns an Expr where left && right

func (*Solver) AssertFormula

func (s *Solver) AssertFormula(e Expr)

AssertFormula adds constraint e to the solver

func (*Solver) BitVec

func (s *Solver) BitVec(in string, bitWidth int) Expr

BitVec returns an Expr which is symbollic of string in with bit length bithWidth

func (*Solver) BvAndExpr

func (s *Solver) BvAndExpr(left, right Expr) Expr

BvAndExpr returns an Expr of bit length bitWidth between two Exprs left and right which are bitwise and

func (*Solver) BvConstExprFromInt

func (s *Solver) BvConstExprFromInt(bitWidth int, value uint) Expr

BvConstExprFromInt returns an Expr of bit length bitWidth which is a constant of value

func (*Solver) BvDivExpr

func (s *Solver) BvDivExpr(bitWidth int, dividend Expr, divisor Expr) Expr

BvDivExpr returns an Expr of bit length bitWidth between two Exprs dividend and divisor which are divided

func (*Solver) BvGeExpr

func (s *Solver) BvGeExpr(left, right Expr) Expr

BvGeExpr returns an Expr where left >= right

func (*Solver) BvGtExpr

func (s *Solver) BvGtExpr(left, right Expr) Expr

BvGtExpr returns an Expr where left > right

func (*Solver) BvLShiftExpr

func (s *Solver) BvLShiftExpr(bitWidth int, left Expr, right Expr) Expr

BvLShiftExpr returns an Expr of bit length bitWidth where left << right

func (*Solver) BvLeExpr

func (s *Solver) BvLeExpr(left, right Expr) Expr

BvLeExpr returns an Expr where left <= right

func (*Solver) BvLtExpr

func (s *Solver) BvLtExpr(left, right Expr) Expr

BvLtExpr returns an Expr where left < right

func (*Solver) BvMinusExpr

func (s *Solver) BvMinusExpr(bitWidth int, left Expr, right Expr) Expr

BVPlusExpr returns an Expr of bit length bitWidth between two Exprs left and right which are subtracted

func (*Solver) BvModExpr

func (s *Solver) BvModExpr(bitWidth int, dividend Expr, divisor Expr) Expr

BvDivExpr returns an Expr of bit length bitWidth between two Exprs dividend and divisor which are in modulo

func (*Solver) BvMultExpr

func (s *Solver) BvMultExpr(bitWidth int, left Expr, right Expr) Expr

BvMultExpr returns an Expr of bit length bitWidth between two Exprs left and right which are multiplied

func (*Solver) BvNotExpr

func (s *Solver) BvNotExpr(child Expr) Expr

BvAndExpr returns an Expr which is the logical not of the Expr child

func (*Solver) BvOrExpr

func (s *Solver) BvOrExpr(left, right Expr) Expr

BvAndExpr returns an Expr of bit length bitWidth between two Exprs left and right which are bitwise or

func (*Solver) BvPlusExpr

func (s *Solver) BvPlusExpr(bitWidth int, left Expr, right Expr) Expr

BVPlusExpr returns an Expr of bit length bitWidth between two Exprs left and right which are added

func (*Solver) BvRShiftExpr

func (s *Solver) BvRShiftExpr(bitWidth int, left Expr, right Expr) Expr

BvRShiftExpr returns an Expr of bit length bitWidth where left >> right

func (*Solver) BvType

func (s *Solver) BvType(no_bits int) Type

BITVECTOR RELATED FUNCTIONS BvType returns a type of bitwidth no_bits that could be used in VarExpr

func (*Solver) BvUMinusExpr

func (s *Solver) BvUMinusExpr(child Expr) Expr

BvUMinusExpr returns the arithmetic negation of Expr child

func (*Solver) BvXorExpr

func (s *Solver) BvXorExpr(left, right Expr) Expr

BvAndExpr returns an Expr of bit length bitWidth between two Exprs left and right which are bitwise xor

func (*Solver) Destroy

func (s *Solver) Destroy()

/Destroy tells the solver to sleep

func (*Solver) EqExpr

func (s *Solver) EqExpr(child0 Expr, child1 Expr) Expr

LOGIC RELATED FUNCTIONS EqExpr returns an Expr where child0 == child1

func (*Solver) Eval

func (s *Solver) Eval(exp ast.Expr) Expr

Eval recursively traverses the ast and returns the associated Expr form of the ast

func (*Solver) EvalBinaryExpr

func (s *Solver) EvalBinaryExpr(exp *ast.BinaryExpr) Expr

EvalBinaryExpr returns an associated Expr which is representive of the BinaryExpr within an ast

func (*Solver) EvalUnaryExpr

func (s *Solver) EvalUnaryExpr(exp *ast.UnaryExpr) Expr

EvalUnaryExpr returns an associated Expr which is representive of the UnaryExpr within an ast

func (*Solver) FalseExpr

func (s *Solver) FalseExpr() Expr

FalseExpr returns an expression which has a value of False

func (*Solver) GetTermFromCounterExample

func (s *Solver) GetTermFromCounterExample(e Expr, c WholeCounterExample) Expr

GetTermFromCounterExample returns an Expr that is associated with Expr e from the WholeCounterExample c

func (*Solver) GetWholeCounterExample

func (s *Solver) GetWholeCounterExample() WholeCounterExample

GetWholeCounterExample returns the full CounterExample that invalidates the Queried Expr

func (*Solver) H2i

func (s *Solver) H2i(in string) uint64

H2i turns a string 0x00000 to its base 10 counterpart in uint64

func (*Solver) ImpliesExpr

func (s *Solver) ImpliesExpr(hyp Expr, conc Expr) Expr

ImpliesExpr returns an Expr where hyp implies conc

func (*Solver) NotExpr

func (s *Solver) NotExpr(child Expr) Expr

NotExpr flips the boolean expression of Expr and returns the flipped Expr

func (*Solver) OrExpr

func (s *Solver) OrExpr(left, right Expr) Expr

OrExpr returns an Expr where left || right

func (*Solver) PrintAsserts

func (s *Solver) PrintAsserts(simplify_print int)

PrintAsserts prints to stdout the assertions made to the checker

func (*Solver) PrintCounterExample

func (s *Solver) PrintCounterExample()

PrintCounterExample prints to stdout the CounterExample which invalidates the Queried Expr

func (*Solver) PrintQuery

func (s *Solver) PrintQuery()

PrintQuery prints to stdout the most recent Query

func (*Solver) Query

func (s *Solver) Query(e Expr) int

Query tells the solver to validate an Expr e

func (*Solver) SH2i

func (s *Solver) SH2i(in string) int64

SH2i turns a string 0x00000 to its base 10 counterpart in int64

func (*Solver) SSolve

func (s *Solver) SSolve(vars ...Expr) []int64

Signed solve evaluates the assertions which returns values of symbollic inputs vars in int form

func (*Solver) Solve

func (s *Solver) Solve(vars ...Expr) []uint64

Solve evaluates the assertions which returns values of symbollic inputs vars in int form

func (*Solver) TrueExpr

func (s *Solver) TrueExpr() Expr

TrueExpr returns an expression which has a value of True

func (*Solver) VarExpr

func (s *Solver) VarExpr(name string, typ Type) Expr

VarExpr returns an Expr that is initialized from a Type and a symbollic handle name

func (*Solver) XorExpr

func (s *Solver) XorExpr(left, right Expr) Expr

XorExpr returns an Expr where left ^ right

type Type

type Type C.Type

type VC

type VC C.VC

type WholeCounterExample

type WholeCounterExample C.WholeCounterExample

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL