API Reference¶
Note
The full README is available on GitHub.
Enums
Functions
-
gate_t *gate_new(gate_kind_t kind, unsigned n)¶
Creates a new gate of the specified type with
ninputs.- Parameters:
kind – The type of gate to create (e.g.
NAND,AND,OR).n – The number of inputs for the gate.
- Returns:
Pointer to the created gate structure on success.
NULLif memory allocation fails (errnois set toENOMEM).
-
void gate_delete(gate_t *g)¶
Deletes the specified gate.
Disconnects all input and output signals from the gate and frees its allocated memory. Does nothing if
gisNULL. After deletion, the pointergbecomes invalid.- Parameters:
g – Pointer to the gate to delete.
-
int gate_connect_gate(gate_t *g_out, gate_t *g_in, unsigned k)¶
Connects the output of one gate to the input of another gate.
Connects the output of
g_outto thek-th input ofg_in. Any signal previously connected to thek-th input ofg_inwill be disconnected.- Parameters:
g_out – Pointer to the output gate.
g_in – Pointer to the input gate.
k – Index of the input in
g_into connect.
- Returns:
0 on success.
-1 if any pointer is
NULL,kis invalid, or memory allocation fails (errnois set toEINVALorENOMEM).
-
int gate_connect_signal(bool const *s, gate_t *g, unsigned k)¶
Connects a boolean signal to the input of a gate.
Connects a boolean signal
sto thek-th input of gateg. Any signal previously connected to thek-th input will be disconnected.- Parameters:
s – Pointer to the constant boolean signal.
g – Pointer to the gate.
k – Index of the input in
gto connect.
- Returns:
0 on success.
-1 if any pointer is
NULL,kis invalid, or memory allocation fails (errnois set toEINVALorENOMEM).
-
ssize_t gate_evaluate(gate_t **g, bool *s, size_t m)¶
Evaluates the output signals of the specified gates and calculates the critical path length.
Computes the output signals of the gates in
gand stores them in thesarray. Also calculates the maximum critical path length for the given gates.- Parameters:
g – Array of pointers to gates.
s – Array to store the output signals of the gates.
m – Size of the
gandsarrays.
- Returns:
Critical path length on success (also populates the
sarray). s[i] contains the value of the signal at the output of the gate pointed to by g[i].-1 if any pointer is
NULL,mis zero, operation failed or memory allocation fails (errnois set toEINVAL,ECANCELED, orENOMEM).
-
ssize_t gate_fan_out(gate_t const *g)¶
Returns the fan-out of the specified gate.
Calculates the number of inputs in other gates connected to the output of the given gate.
- Parameters:
g – Pointer to the gate.
- Returns:
The number of connected inputs on success.
-1 if
gisNULL(errnois set toEINVAL).
-
ssize_t gate_fan_in(gate_t const *g)¶
Returns the fan-in of the specified gate.
- Parameters:
g – Pointer to the gate.
- Returns:
The number of inputs of the gate.
-1 if
gisNULL(errnois set toEINVAL).
-
void *gate_input(gate_t const *g, unsigned k)¶
Retrieves the signal or gate connected to a specific input.
Returns a pointer to the boolean signal or gate connected to the
k-th input of the gateg. ReturnsNULLif nothing is connected to the input.- Parameters:
g – Pointer to the gate.
k – Index of the input.
- Returns:
Pointer to a
bool*orgate_t*on success.NULLif no connection exists (errno is set to 0) =NULLifgisNULL, orkis invalid (errnois set toEINVAL).
-
gate_t *gate_output(gate_t const *g, ssize_t k)¶
Retrieves a gate connected to the output of the specified gate.
- Parameters:
g – Pointer to the gate.
k – Index of the connection to retrieve (from 0 to
gate_fan_out(g) - 1).
- Returns:
Pointer to the connected gate.
NULLif parameters are invalid or the output is not connected to any gate.