summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-12-28 16:57:40 +1300
committerDavid Phillips <david@sighup.nz>2017-12-28 16:57:40 +1300
commit95e3d12b61d7ca89c978b22403e66df8656238ae (patch)
tree3ebc575f8326b03c12b041746e15f6a4bd4936db
parent9a836bd5c8bb688edee7bcfd5830349f3aa98d6b (diff)
downloadhence-95e3d12b61d7ca89c978b22403e66df8656238ae.tar.xz
Misc linting/tidy
-rw-r--r--Makefile4
-rw-r--r--gate.c7
-rw-r--r--gate.h1
-rw-r--r--logic.c2
-rw-r--r--parser.c32
-rw-r--r--simulator.c2
6 files changed, 20 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index 0f21fee..4d97506 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/gate.c b/gate.c
index 67d9c08..c196b91 100644
--- a/gate.c
+++ b/gate.c
@@ -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;
diff --git a/gate.h b/gate.h
index 86b2e48..bd5dc65 100644
--- a/gate.h
+++ b/gate.h
@@ -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
diff --git a/logic.c b/logic.c
index 8eabb65..83c4148 100644
--- a/logic.c
+++ b/logic.c
@@ -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();
}
}
diff --git a/parser.c b/parser.c
index 274f9a0..dc1e9a9 100644
--- a/parser.c
+++ b/parser.c
@@ -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;