diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | gate.c | 7 | ||||
-rw-r--r-- | gate.h | 1 | ||||
-rw-r--r-- | logic.c | 2 | ||||
-rw-r--r-- | parser.c | 32 | ||||
-rw-r--r-- | simulator.c | 2 |
6 files changed, 20 insertions, 28 deletions
@@ -1,6 +1,6 @@ -CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 +CFLAGS += -std=c99 -D_XOPEN_SOURCE=500 -Wall -Wextra -all: simulator +all: simulator parser simulator: simulator.o gate.o logic.o @@ -10,11 +10,8 @@ static size_t gate_count; static size_t input_count; -static size_t output_count; static struct gate gates[GATE_MAX]; static struct gate inputs[INPUT_MAX]; -static struct gate outputs[OUTPUT_MAX]; - int count_guard(int c, int max, char *desc) { @@ -27,7 +24,7 @@ count_guard(int c, int max, char *desc) { int gate_add_generic(struct gate *array, size_t array_index, char *name, enum BINARY (*operation)(enum BINARY, enum BINARY), struct gate *in1, struct gate *in2) { - struct gate g = {0}; + struct gate g; if (name == NULL) { g.name = NULL; @@ -143,7 +140,7 @@ gate_set_input(char *name, enum BINARY value) { return 0; } -void gate_update() { +void gate_update(void) { size_t i = 0; struct gate *g = NULL; enum BINARY in1 = LOGIC_LOW; @@ -26,5 +26,6 @@ int tick(void); void gate_init(void); void gate_dump(void); int gate_set_input(char *name, enum BINARY value); +void gate_update(void); #endif @@ -1,5 +1,6 @@ #define NDEBUG #include <assert.h> +#include <stdlib.h> #include "logic.h" #include "error.h" @@ -13,6 +14,7 @@ logic_not(enum BINARY input) { return LOGIC_HIGH; default: emit_error("Severe: Invalid logic value found\n"); + abort(); } } @@ -7,6 +7,11 @@ #include "logic.h" #include "gate.h" + +int parse_input(char *); +int parse_module(char *); +int parse_expr(char *); + struct tok_lookup { char *str; int (*handler)(char*); @@ -29,6 +34,12 @@ static struct op_lookup bop_handlers[] = { {.str = "xor", .handler = logic_xor} }; +static struct tok_lookup tok_handlers[] = { + {.str = "input", .handler = parse_input}, + {.str = "module", .handler = parse_module}, + {.str = "expr", .handler = parse_expr} +}; + int expect(const char *expect, char *actual) { int min_len = 0; @@ -137,19 +148,6 @@ parse_module(char *str) { return 0; } - - - -static struct tok_lookup tok_handlers[] = { - {.str = "input", .handler = parse_input}, - {.str = "module", .handler = parse_module}, - {.str = "expr", .handler = parse_expr} -}; - - - - - int parse_line(char *line) { size_t i = 0; @@ -191,19 +189,11 @@ int main(void) { return 1; } } - gate_dump(); gate_set_input("a", LOGIC_LOW); gate_set_input("b", LOGIC_LOW); - gate_update(); - gate_dump(); - - return 0; } - - - diff --git a/simulator.c b/simulator.c index b8da648..d89ceb0 100644 --- a/simulator.c +++ b/simulator.c @@ -2,6 +2,8 @@ #include "logic.h" int main(int argc, char **argv) { + (void)argc; + (void)argv; logic_test(); gate_init(); return 0; |