isomatch
Classes | Typedefs | Enumerations | Functions
isomatch.h File Reference

C API header file for the Isomatch library. More...

#include <stdint.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  circuit_list
 Linked list of circuit_handle More...
 
struct  wire_list
 Linked list of wire_handle More...
 
struct  single_match
 Result for a single subcircuit-find match. More...
 
struct  match_results
 Subcircuit-find match results. More...
 

Typedefs

typedef uint64_t sign_t
 Type of a circuit signature. More...
 
typedef void * circuit_handle
 Value representing a circuit. More...
 
typedef void * expr_handle
 Value representing an expression. More...
 
typedef const char * wire_handle
 A wire name. More...
 
typedef struct circuit_list circuit_list
 Linked list of circuit_handle More...
 
typedef struct wire_list wire_list
 Linked list of wire_handle More...
 
typedef struct match_results match_results
 Subcircuit-find match results. More...
 
typedef enum isom_rc isom_rc
 Return codes of the int-returning functions in this API. More...
 

Enumerations

enum  isom_rc {
  ISOM_RC_OK = 0, ISOM_RC_NULLPTR = 1, ISOM_RC_DOMAIN = 2, ISOM_RC_NO_PARENT = 3,
  ISOM_RC_BADHEX = 4, ISOM_RC_BAD_FREE = 5, ISOM_RC_OUT_OF_RANGE = 6, ISOM_RC_NOT_CONNECTED = 7,
  ISOM_RC_ERROR = 255
}
 Return codes of the int-returning functions in this API. More...
 
enum  isom_expr_binop {
  BAnd, BOr, BXor, BAdd,
  BSub, BMul, BDiv, BMod,
  BLsr, BLsl, BAsr
}
 
enum  isom_expr_unop { UNot }
 
enum  isom_expr_unop_cst { UCLsr, UCLsl, UCAsr }
 

Functions

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_match_results (match_results *res)
 
void isom_clear_marks ()
 
void isom_mark_circuit (circuit_handle handle)
 
void isom_sweep ()
 

Detailed Description

C API header file for the Isomatch library.

General purpose notes on this API:

Typedef Documentation

◆ circuit_handle

typedef void* circuit_handle

Value representing a circuit.

◆ circuit_list

typedef struct circuit_list circuit_list

Linked list of circuit_handle

◆ expr_handle

typedef void* expr_handle

Value representing an expression.

◆ isom_rc

typedef enum isom_rc isom_rc

Return codes of the int-returning functions in this API.

◆ match_results

typedef struct match_results match_results

Subcircuit-find match results.

◆ sign_t

typedef uint64_t sign_t

Type of a circuit signature.

◆ wire_handle

typedef const char* wire_handle

A wire name.

◆ wire_list

typedef struct wire_list wire_list

Linked list of wire_handle

Enumeration Type Documentation

◆ isom_expr_binop

Operator for ExprBinOp

Enumerator
BAnd 

Bitwise and.

BOr 

Bitwise or.

BXor 

Bitwise exclusive or.

BAdd 

Addition.

BSub 

Subtraction.

BMul 

Multiplication.

BDiv 

Division.

BMod 

Modulus.

BLsr 

Logical shift right.

BLsl 

Logical shift left.

BAsr 

Arithmetic shift right.

◆ isom_expr_unop

Operator for ExprUnOp

Enumerator
UNot 

Unary bitwise not.

◆ isom_expr_unop_cst

Operator for ExprUnOpCst

Enumerator
UCLsr 

Logical shift right of fixed shift.

UCLsl 

Logical shift left of fixed shift.

UCAsr 

Arithmetic shift right of fixed shift.

◆ isom_rc

enum isom_rc

Return codes of the int-returning functions in this API.

Enumerator
ISOM_RC_OK 

Everything went fine.

ISOM_RC_NULLPTR 

One of the parameters was a null pointer.

ISOM_RC_DOMAIN 

One of the parameters has the wrong pointer type.

ISOM_RC_NO_PARENT 

A circuit outside of a group was used, while it needed to be in a group

ISOM_RC_BADHEX 

Non hexadecimal string was supplied.

ISOM_RC_BAD_FREE 

Attempted to free an unregistered pointer.

ISOM_RC_OUT_OF_RANGE 

A supplied (int) value was out of range.

ISOM_RC_NOT_CONNECTED 

This pin is not connected to any wire.

ISOM_RC_ERROR 

An undefined error occurred.

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.

◆ 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_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!

◆ 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.