isomatch
isomatch.h
Go to the documentation of this file.
1 #pragma once
2 
16 #include <stdint.h>
17 #include <stdlib.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 /*****************************************************************************/
24 /* Type declarations */
25 /*****************************************************************************/
26 typedef uint64_t sign_t;
27 typedef void* circuit_handle;
28 typedef void* expr_handle;
29 typedef const char* wire_handle;
30 
32 typedef struct circuit_list {
33  circuit_handle circ;
34  struct circuit_list* next;
35 } circuit_list;
36 
38 typedef struct wire_list {
39  wire_handle wire;
40  struct wire_list* next;
41 } wire_list;
42 
44 typedef struct {
48 } single_match;
49 
51 typedef struct match_results {
53  struct match_results* next;
55 
56 /*****************************************************************************/
57 /* Error handling */
58 /*****************************************************************************/
59 
60 /***********************************/
61 /* Return values (aka error codes) */
62 /***********************************/
63 
65 typedef enum isom_rc {
66  ISOM_RC_OK = 0,
70  ISOM_RC_BADHEX = 4,
75  ISOM_RC_ERROR = 255,
76 } isom_rc;
77 
78 /*****************************/
79 /* Error reporting functions */
80 /*****************************/
81 
84 
87 const char* isom_strerror(isom_rc err_code);
88 
89 /*****************************************************************************/
90 /* Enumerations */
91 /*****************************************************************************/
92 
93 /***************/
94 /* Expressions */
95 /***************/
96 
99  BAnd,
100  BOr,
110 };
111 
115 };
116 
122 };
123 
124 /*****************************************************************************/
125 /* Circuit construction */
126 /*****************************************************************************/
127 
128 /*********************/
129 /* Generic functions */
130 /*********************/
131 
136 int free_circuit(circuit_handle circuit);
137 
140 int isom_unplug_circuit(circuit_handle circuit);
141 
142 /****************/
143 /* Assert gates */
144 /****************/
145 
147 circuit_handle build_assert(circuit_handle parent,
148  const char* name,
149  expr_handle expr);
150 
154 int build_assert_add_input(circuit_handle self, wire_handle wire);
155 
156 /**************/
157 /* Comb gates */
158 /**************/
159 
161 circuit_handle build_comb(circuit_handle parent);
162 
166 int build_comb_add_input(circuit_handle self, wire_handle wire);
167 
171 int build_comb_add_output(circuit_handle self,
172  wire_handle wire,
173  expr_handle expr);
174 
175 /***************/
176 /* Delay gates */
177 /***************/
178 
180 circuit_handle build_delay(circuit_handle parent,
181  wire_handle input,
182  wire_handle output);
183 
184 /*************************/
185 /* Hierarchy group gates */
186 /*************************/
187 
192 circuit_handle build_group(const char* name);
193 
197 int build_group_add_child(circuit_handle self, circuit_handle child);
198 
205 int build_group_add_input(circuit_handle self,
206  wire_handle actual,
207  wire_handle formal);
208 
215 int build_group_add_output(circuit_handle self,
216  wire_handle actual,
217  wire_handle formal);
218 
219 /******************/
220 /* Tristate gates */
221 /******************/
222 
224 circuit_handle build_tristate(circuit_handle parent,
225  wire_handle from,
226  wire_handle to,
227  wire_handle enable);
228 
229 /***************/
230 /* Expressions */
231 /***************/
232 
234 expr_handle build_expr_const(unsigned val);
235 
239 expr_handle build_expr_longconst(const char* value);
240 
242 expr_handle build_expr_var(int input_pin);
243 
245 expr_handle build_expr_binop(enum isom_expr_binop op,
246  expr_handle left,
247  expr_handle right);
248 
250 expr_handle build_expr_unop(enum isom_expr_unop op, expr_handle expr);
251 
253 expr_handle build_expr_unop_cst(enum isom_expr_unop_cst op,
254  int param,
255  expr_handle expr);
256 
258 expr_handle build_expr_slice(expr_handle expr, unsigned beg, unsigned end);
259 
261 expr_handle build_expr_merge(expr_handle left, expr_handle right);
262 
264 int free_expression(expr_handle expr);
265 
266 /*****************************************************************************/
267 /* Accessors */
268 /*****************************************************************************/
269 
271 int isom_input_count(circuit_handle circuit);
272 
274 int isom_output_count(circuit_handle circuit);
275 
277 wire_handle isom_nth_input(circuit_handle circuit, size_t wireId);
278 
280 wire_handle isom_nth_output(circuit_handle circuit, size_t wireId);
281 
282 /*****************************************************************************/
283 /* Signature */
284 /*****************************************************************************/
285 
287 sign_t sign(circuit_handle circuit);
288 
291 sign_t sign_with_precision(circuit_handle circuit, unsigned precision_level);
292 
293 /*****************************************************************************/
294 /* Circuit matching */
295 /*****************************************************************************/
296 
303 match_results* subcircuit_find(circuit_handle needle, circuit_handle haystack);
304 
308 
309 /*****************************************************************************/
310 /* Mark and sweep */
311 /*****************************************************************************/
312 
319 void isom_clear_marks();
320 
323 void isom_mark_circuit(circuit_handle handle);
324 
327 void isom_sweep();
328 
329 
330 #ifdef __cplusplus
331 }
332 #endif
Logical shift right of fixed shift.
Definition: isomatch.h:119
struct wire_list wire_list
Linked list of wire_handle
single_match match
Data for this element.
Definition: isomatch.h:52
Linked list of wire_handle
Definition: isomatch.h:38
expr_handle build_expr_var(int input_pin)
Build a variable expression node referring to the nth input of the gate.
Definition: isomatch.cpp:379
wire_list * inputs
Definition: isomatch.h:46
Subcircuit-find match results.
Definition: isomatch.h:51
int build_comb_add_input(circuit_handle self, wire_handle wire)
Definition: isomatch.cpp:222
void isom_sweep()
Definition: isomatch.cpp:615
Result for a single subcircuit-find match.
Definition: isomatch.h:44
isom_expr_unop_cst
Definition: isomatch.h:118
circuit_handle build_group(const char *name)
Definition: isomatch.cpp:267
struct circuit_list * next
Next element in the list.
Definition: isomatch.h:34
A supplied (int) value was out of range.
Definition: isomatch.h:73
circuit_handle build_comb(circuit_handle parent)
Build a comb gate, which will need to be edited with the functions below.
Definition: isomatch.cpp:211
int build_group_add_input(circuit_handle self, wire_handle actual, wire_handle formal)
Definition: isomatch.cpp:292
int isom_input_count(circuit_handle circuit)
Returns the number of inputs of a given circuit. Returns -1 on error.
Definition: isomatch.cpp:458
const char * isom_strerror(isom_rc err_code)
Definition: isomatch.cpp:134
Division.
Definition: isomatch.h:105
struct circuit_list circuit_list
Linked list of circuit_handle
int free_expression(expr_handle expr)
Free the given previously created expression.
Definition: isomatch.cpp:447
Logical shift right.
Definition: isomatch.h:107
This pin is not connected to any wire.
Definition: isomatch.h:74
circuit_handle build_tristate(circuit_handle parent, wire_handle from, wire_handle to, wire_handle enable)
Build a tristate gate.
Definition: isomatch.cpp:336
One of the parameters was a null pointer.
Definition: isomatch.h:67
struct match_results * next
Next element in the list.
Definition: isomatch.h:53
Bitwise exclusive or.
Definition: isomatch.h:101
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.
Definition: isomatch.cpp:414
circuit_handle build_delay(circuit_handle parent, wire_handle input, wire_handle output)
Build a delay gate.
Definition: isomatch.cpp:248
Multiplication.
Definition: isomatch.h:104
Attempted to free an unregistered pointer.
Definition: isomatch.h:72
isom_expr_unop
Definition: isomatch.h:113
isom_rc isom_last_error()
Return the error code of the last error that occurred.
Definition: isomatch.cpp:130
int build_comb_add_output(circuit_handle self, wire_handle wire, expr_handle expr)
Definition: isomatch.cpp:232
circuit_list * parts
Definition: isomatch.h:45
int isom_output_count(circuit_handle circuit)
Returns the number of outputs of a given circuit. Returns -1 on error.
Definition: isomatch.cpp:468
wire_handle wire
Data for this element.
Definition: isomatch.h:39
isom_expr_binop
Definition: isomatch.h:98
expr_handle build_expr_const(unsigned val)
Build a constant expression node.
Definition: isomatch.cpp:357
Arithmetic shift right.
Definition: isomatch.h:109
int build_group_add_output(circuit_handle self, wire_handle actual, wire_handle formal)
Definition: isomatch.cpp:313
int isom_unplug_circuit(circuit_handle circuit)
Definition: isomatch.cpp:172
void * circuit_handle
Value representing a circuit.
Definition: isomatch.h:27
Non hexadecimal string was supplied.
Definition: isomatch.h:71
int build_group_add_child(circuit_handle self, circuit_handle child)
Definition: isomatch.cpp:278
Addition.
Definition: isomatch.h:102
circuit_handle circ
Data for this element.
Definition: isomatch.h:33
expr_handle build_expr_slice(expr_handle expr, unsigned beg, unsigned end)
Build a slice expression node (beginning inclusive, end exclusive)
Definition: isomatch.cpp:429
void free_match_results(match_results *res)
Definition: isomatch.cpp:594
Linked list of circuit_handle
Definition: isomatch.h:32
Definition: gateExpression.h:10
Logical shift left.
Definition: isomatch.h:108
wire_handle isom_nth_input(circuit_handle circuit, size_t wireId)
Returns the handle of the nth input wire (starting with 0) of circuit
Definition: isomatch.cpp:478
Subtraction.
Definition: isomatch.h:103
void isom_clear_marks()
Definition: isomatch.cpp:607
Unary bitwise not.
Definition: isomatch.h:114
struct wire_list * next
Next element in the list.
Definition: isomatch.h:40
Modulus.
Definition: isomatch.h:106
void * expr_handle
Value representing an expression.
Definition: isomatch.h:28
int free_circuit(circuit_handle circuit)
Definition: isomatch.cpp:163
sign_t sign_with_precision(circuit_handle circuit, unsigned precision_level)
Definition: isomatch.cpp:525
Everything went fine.
Definition: isomatch.h:66
expr_handle build_expr_binop(enum isom_expr_binop op, expr_handle left, expr_handle right)
Build a binary operator expression node.
Definition: isomatch.cpp:388
match_results * subcircuit_find(circuit_handle needle, circuit_handle haystack)
Definition: isomatch.cpp:535
expr_handle build_expr_merge(expr_handle left, expr_handle right)
Build a merge expression node.
Definition: isomatch.cpp:438
const char * wire_handle
A wire name.
Definition: isomatch.h:29
sign_t sign(circuit_handle circuit)
Definition: isomatch.cpp:516
expr_handle build_expr_unop(enum isom_expr_unop op, expr_handle expr)
Build a unary operator expression node.
Definition: isomatch.cpp:403
int build_assert_add_input(circuit_handle self, wire_handle wire)
Definition: isomatch.cpp:199
circuit_handle build_assert(circuit_handle parent, const char *name, expr_handle expr)
Build an assert gate.
Definition: isomatch.cpp:185
Bitwise or.
Definition: isomatch.h:100
Definition: isomatch.h:69
expr_handle build_expr_longconst(const char *value)
Definition: isomatch.cpp:366
void isom_mark_circuit(circuit_handle handle)
Definition: isomatch.cpp:611
wire_list * outputs
Definition: isomatch.h:47
isom_rc
Return codes of the int-returning functions in this API.
Definition: isomatch.h:65
Bitwise and.
Definition: isomatch.h:99
An undefined error occurred.
Definition: isomatch.h:75
uint64_t sign_t
Type of a circuit signature.
Definition: isomatch.h:26
Arithmetic shift right of fixed shift.
Definition: isomatch.h:121
wire_handle isom_nth_output(circuit_handle circuit, size_t wireId)
Returns the handle of the nth output wire (starting with 0) of circuit
Definition: isomatch.cpp:496
Logical shift left of fixed shift.
Definition: isomatch.h:120
One of the parameters has the wrong pointer type.
Definition: isomatch.h:68
struct match_results match_results
Subcircuit-find match results.