isomatch
Classes | Functions
isomatch.cpp File Reference
#include "isomatch.h"
#include "../isomatch.h"
#include <exception>
#include <type_traits>
#include <set>
#include <cstring>

Classes

struct  MarkSweepState
 
class  IsomError
 

Functions

CircuitTreecomponentRootOf (CircuitTree *circ)
 
isom_rc isom_last_error ()
 Return the error code of the last error that occurred. More...
 
const char * isom_strerror (isom_rc err_code)
 
int free_circuit (circuit_handle circuit)
 
int isom_unplug_circuit (circuit_handle circuit)
 
circuit_handle build_assert (circuit_handle parent, const char *name, expr_handle expr)
 Build an assert gate. More...
 
int build_assert_add_input (circuit_handle self, wire_handle wire)
 
circuit_handle build_comb (circuit_handle parent)
 Build a comb gate, which will need to be edited with the functions below. More...
 
int build_comb_add_input (circuit_handle self, wire_handle wire)
 
int build_comb_add_output (circuit_handle self, wire_handle wire, expr_handle expr)
 
circuit_handle build_delay (circuit_handle parent, wire_handle input, wire_handle output)
 Build a delay gate. More...
 
circuit_handle build_group (const char *name)
 
int build_group_add_child (circuit_handle self, circuit_handle child)
 
int build_group_add_input (circuit_handle self, wire_handle actual, wire_handle formal)
 
int build_group_add_output (circuit_handle self, wire_handle actual, wire_handle formal)
 
circuit_handle build_tristate (circuit_handle parent, wire_handle from, wire_handle to, wire_handle enable)
 Build a tristate gate. More...
 
expr_handle build_expr_const (unsigned val)
 Build a constant expression node. More...
 
expr_handle build_expr_longconst (const char *value)
 
expr_handle build_expr_var (int input_pin)
 Build a variable expression node referring to the nth input of the gate. More...
 
expr_handle build_expr_binop (enum isom_expr_binop op, expr_handle left, expr_handle right)
 Build a binary operator expression node. More...
 
expr_handle build_expr_unop (enum isom_expr_unop op, expr_handle expr)
 Build a unary operator expression node. More...
 
expr_handle build_expr_unop_cst (enum isom_expr_unop_cst op, int param, expr_handle expr)
 Build a unary operator with constant parameter expression node. More...
 
expr_handle build_expr_slice (expr_handle expr, unsigned beg, unsigned end)
 Build a slice expression node (beginning inclusive, end exclusive) More...
 
expr_handle build_expr_merge (expr_handle left, expr_handle right)
 Build a merge expression node. More...
 
int free_expression (expr_handle expr)
 Free the given previously created expression. More...
 
int isom_input_count (circuit_handle circuit)
 Returns the number of inputs of a given circuit. Returns -1 on error. More...
 
int isom_output_count (circuit_handle circuit)
 Returns the number of outputs of a given circuit. Returns -1 on error. More...
 
wire_handle isom_nth_input (circuit_handle circuit, size_t wireId)
 Returns the handle of the nth input wire (starting with 0) of circuit More...
 
wire_handle isom_nth_output (circuit_handle circuit, size_t wireId)
 Returns the handle of the nth output wire (starting with 0) of circuit More...
 
sign_t sign (circuit_handle circuit)
 
sign_t sign_with_precision (circuit_handle circuit, unsigned precision_level)
 
match_resultssubcircuit_find (circuit_handle needle, circuit_handle haystack)
 
void free_circuit_list (circuit_list *list)
 
void free_wire_list (wire_list *list)
 
void free_match_results (match_results *res)
 
void isom_clear_marks ()
 
void isom_mark_circuit (circuit_handle handle)
 
void isom_sweep ()
 

Function Documentation

◆ build_assert()

circuit_handle build_assert ( circuit_handle  parent,
const char *  name,
expr_handle  expr 
)

Build an assert gate.

◆ build_assert_add_input()

int build_assert_add_input ( circuit_handle  self,
wire_handle  wire 
)

Add an input wire to a given gate (order matters!)

Returns
0 on success, > 0 on failure

◆ build_comb()

circuit_handle build_comb ( circuit_handle  parent)

Build a comb gate, which will need to be edited with the functions below.

◆ build_comb_add_input()

int build_comb_add_input ( circuit_handle  self,
wire_handle  wire 
)

Add an input wire to a given combinator gate

Returns
0 on success, > 0 on failure

◆ build_comb_add_output()

int build_comb_add_output ( circuit_handle  self,
wire_handle  wire,
expr_handle  expr 
)

Add an output wire, alongside with an expression, to a given comb gate

Returns
0 on success, > 0 on failure

◆ build_delay()

circuit_handle build_delay ( circuit_handle  parent,
wire_handle  input,
wire_handle  output 
)

Build a delay gate.

◆ build_expr_binop()

expr_handle build_expr_binop ( enum isom_expr_binop  op,
expr_handle  left,
expr_handle  right 
)

Build a binary operator expression node.

◆ build_expr_const()

expr_handle build_expr_const ( unsigned  val)

Build a constant expression node.

◆ build_expr_longconst()

expr_handle build_expr_longconst ( const char *  value)

Build a long constant expression node

Parameters
valueHexadecimal string [0-9a-fA-F]+

◆ build_expr_merge()

expr_handle build_expr_merge ( expr_handle  left,
expr_handle  right 
)

Build a merge expression node.

◆ build_expr_slice()

expr_handle build_expr_slice ( expr_handle  expr,
unsigned  beg,
unsigned  end 
)

Build a slice expression node (beginning inclusive, end exclusive)

◆ build_expr_unop()

expr_handle build_expr_unop ( enum isom_expr_unop  op,
expr_handle  expr 
)

Build a unary operator expression node.

◆ build_expr_unop_cst()

expr_handle build_expr_unop_cst ( enum isom_expr_unop_cst  op,
int  param,
expr_handle  expr 
)

Build a unary operator with constant parameter expression node.

◆ build_expr_var()

expr_handle build_expr_var ( int  input_pin)

Build a variable expression node referring to the nth input of the gate.

◆ build_group()

circuit_handle build_group ( const char *  name)

Build a hierarchy group gate, which will need to be edited with the functions below. A group does not necessarily belong to another group, thus there is no parent argument, and you must call build_group_add_child yourself.

◆ build_group_add_child()

int build_group_add_child ( circuit_handle  self,
circuit_handle  child 
)

Add the given circuit as a child of the given group.

Returns
0 on success, > 0 on failure

◆ build_group_add_input()

int build_group_add_input ( circuit_handle  self,
wire_handle  actual,
wire_handle  formal 
)

Add an input pin to the given circuit group.

Parameters
selfThe group to work on
actualThe name of the pin when accessed from inside the group
formalThe name of the pin when accessed from outside the group
Returns
0 on success, > 0 on failure

◆ build_group_add_output()

int build_group_add_output ( circuit_handle  self,
wire_handle  actual,
wire_handle  formal 
)

Add an output pin to the given circuit group.

Parameters
selfThe group to work on
actualThe name of the pin when accessed from inside the group
formalThe name of the pin when accessed from outside the group
Returns
0 on success, > 0 on failure

◆ build_tristate()

circuit_handle build_tristate ( circuit_handle  parent,
wire_handle  from,
wire_handle  to,
wire_handle  enable 
)

Build a tristate gate.

◆ componentRootOf()

CircuitTree* componentRootOf ( CircuitTree circ)

Finds the root of a component, iterating ancestor().

◆ free_circuit()

int free_circuit ( circuit_handle  circuit)

Free the given previously created circuit's component (that is, including its ancestors and descendants).

Returns
0 on success, > 0 on failure

◆ free_circuit_list()

void free_circuit_list ( circuit_list list)

◆ free_expression()

int free_expression ( expr_handle  expr)

Free the given previously created expression.

◆ free_match_results()

void free_match_results ( match_results res)

Free a match_results. This DOES NOT free the needle and haystack circuits used during the match!

◆ free_wire_list()

void free_wire_list ( wire_list list)

◆ isom_clear_marks()

void isom_clear_marks ( )

This mark and sweep algorithm works on whole components only. This means that if you mark a circuit, every descendant and ancestor of this circuit will be marked as well. Clears all the mark and sweep's marks. This is automatically done by isom_sweep after a pass, but can also be done manually.

◆ isom_input_count()

int isom_input_count ( circuit_handle  circuit)

Returns the number of inputs of a given circuit. Returns -1 on error.

◆ isom_last_error()

isom_rc isom_last_error ( )

Return the error code of the last error that occurred.

◆ isom_mark_circuit()

void isom_mark_circuit ( circuit_handle  handle)

Marks the given circuit handle, all its ancestors and its descendants (circuits and expressions)as "in use" for the next isom_sweep pass

◆ isom_nth_input()

wire_handle isom_nth_input ( circuit_handle  circuit,
size_t  wireId 
)

Returns the handle of the nth input wire (starting with 0) of circuit

◆ isom_nth_output()

wire_handle isom_nth_output ( circuit_handle  circuit,
size_t  wireId 
)

Returns the handle of the nth output wire (starting with 0) of circuit

◆ isom_output_count()

int isom_output_count ( circuit_handle  circuit)

Returns the number of outputs of a given circuit. Returns -1 on error.

◆ isom_strerror()

const char* isom_strerror ( isom_rc  err_code)

Return a human-friendly string describing the given error. Note that you don't have to free the returned string.

◆ isom_sweep()

void isom_sweep ( )

Sweeps (frees every value that is not marked, directly or recursively) the previously allocated values.

◆ isom_unplug_circuit()

int isom_unplug_circuit ( circuit_handle  circuit)

Disconnect the given circuit from its ancestor and wires, and calls free_circuit on it.

◆ sign()

sign_t sign ( circuit_handle  circuit)

Computes a signature for the given circuit handle

◆ sign_with_precision()

sign_t sign_with_precision ( circuit_handle  circuit,
unsigned  precision_level 
)

Computes a signature for the given circuit handle with a precision level of precision_level

◆ subcircuit_find()

match_results* subcircuit_find ( circuit_handle  needle,
circuit_handle  haystack 
)

Finds every disjoint occurrence of needle in haystack. If two possible occurrences of needle are overlapping in haystack, the match that will be returned is undefined (yet deterministic). The list structures, etc. are malloc'd and must be free'd on the caller's side whenever they're not needed anymore using free_match_result.