summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Phillips <david@sighup.nz>2017-12-28 16:43:49 +1300
committerDavid Phillips <david@sighup.nz>2017-12-28 16:43:49 +1300
commit9a836bd5c8bb688edee7bcfd5830349f3aa98d6b (patch)
tree5a4ea529e7ebb11495f42d4526ea43278b163b29
parentfb0483e872931d3a75e45be63be2169a6f07b835 (diff)
downloadhence-9a836bd5c8bb688edee7bcfd5830349f3aa98d6b.tar.xz
Implement unary operation in parser
-rw-r--r--parser.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/parser.c b/parser.c
index a34744a..274f9a0 100644
--- a/parser.c
+++ b/parser.c
@@ -43,12 +43,18 @@ expect(const char *expect, char *actual) {
}
-int parse_uop(char *str, enum BINARY (*handler)(enum BINARY, enum BINARY)) {
- (void)str;
- (void)handler;
- emit_error("uop unimplemented\n");
- /* FIXME add gate with specified handler, tie both inputs together */
- return 1;
+int parse_uop(char *str, char *name, enum BINARY (*handler)(enum BINARY, enum BINARY)) {
+ char *gate_name = str;
+
+ strtok(gate_name, " ");
+
+ /* FIXME allow input from other gates, not just inputs */
+ struct gate *in = gate_get_input_by_name(gate_name);
+
+ gate_add(name, handler, in, in);
+ return 0;
+
+
}
int parse_bop(char *str, char *name, enum BINARY (*handler)(enum BINARY, enum BINARY)) {
@@ -85,7 +91,7 @@ parse_op(char *str, char *name) {
for (i = 0; i < sizeof(uop_handlers)/sizeof(uop_handlers[0]); i++) {
if (strcmp(uop_handlers[i].str, str) == 0) {
match = 1;
- if (parse_uop("FIXME", uop_handlers[i].handler)) {
+ if (parse_uop(str+strlen(str)+1, name, uop_handlers[i].handler)) {
return 1;
}
}