diff options
Diffstat (limited to 'csim/sim.h')
-rw-r--r-- | csim/sim.h | 75 |
1 files changed, 34 insertions, 41 deletions
@@ -6,16 +6,14 @@ #include <stdio.h> // Gate types -#define C_ARG 0 -#define C_REG 1 -#define C_NOT 2 -#define C_BINOP 3 -#define C_MUX 4 -#define C_ROM 5 -#define C_RAM 6 -#define C_CONCAT 7 -#define C_SLICE 8 -#define C_SELECT 9 +#define C_COPY 0 +#define C_NOT 1 +#define C_BINOP 2 +#define C_MUX 3 +#define C_ROM 4 +#define C_CONCAT 5 +#define C_SLICE 6 +#define C_SELECT 7 // Binary operators #define OP_OR 0 @@ -25,7 +23,6 @@ // Data structures - // Use 64-bit ints as bit arrays. Bit index 0 is bitmask 1, bit index 1 is bitmask 2, etc. typedef unsigned long long int t_value; // Identifier for the variables of the circuit. @@ -38,51 +35,47 @@ typedef struct { // a variable in the simulator } t_variable; typedef struct { - t_value mask; // if direct value, mask = all possible bits. Else mask = 0 - union { - t_value Val; - t_id SrcVar; // if source_var == -1 then it's a direct value, else it's that variable - }; -} t_arg; + t_id dest, source; +} t_reg; + +typedef struct { + t_id dest; + int addr_size, word_size; + t_id read_addr, write_enable, write_addr, data; +} t_ram; typedef struct { int type; t_id dest_var; union { struct { - t_arg a; - } Arg; - struct { - t_id var; - } Reg; + t_id a; + } Copy; struct { - t_arg a; + t_id a; } Not; struct { int op; - t_arg a, b; + t_id a, b; } Binop; struct { - t_arg a, b, c; + t_id a, b, c; } Mux; struct { int addr_size, word_size; - t_arg read_addr; + t_id read_addr; } Rom; struct { - int addr_size, word_size; - t_arg read_addr, write_enable, write_addr, data; - } Ram; - struct { - t_arg a, b; + t_id a, b; + int shift; } Concat; struct { int begin, end; - t_arg source; + t_id source; } Slice; struct { int i; - t_arg source; + t_id source; } Select; }; } t_equation; @@ -90,31 +83,31 @@ typedef struct { typedef struct { int n_vars, n_inputs, n_outputs; + t_variable *vars; t_id *inputs, *outputs; + int n_regs, n_rams; + t_reg *regs; + t_ram *rams; + int n_eqs; t_equation *eqs; } t_program; // machine = execution instance -typedef union { - t_value RegVal; - t_value *RamData; -} t_mem_reg_data; - typedef struct { t_program *prog; t_value *var_values; // indexed by variable ID - t_mem_reg_data *mem_data; // indexed by equation number + + t_value *reg_data; // indexed by number in register list + t_value **ram_data; // indexed by number in ram list } t_machine; // The functions for doing stuff with these data structures -t_value read_bool(FILE *stream, t_value* mask); - t_program *load_dumb_netlist(FILE *stream); t_machine *init_machine(t_program *p); |