summaryrefslogtreecommitdiff
path: root/type.c
diff options
context:
space:
mode:
Diffstat (limited to 'type.c')
-rw-r--r--type.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/type.c b/type.c
new file mode 100644
index 0000000..6c72a38
--- /dev/null
+++ b/type.c
@@ -0,0 +1,40 @@
+#include "type.h"
+#include "parse.h"
+#include <string.h>
+
+const struct type *type_find(const struct fn *fn, const char *s)
+{
+ static const struct type builtins[] =
+ {
+ {.type = BUILTIN, .u.b.name = "void"},
+ {.type = BUILTIN, .u.b.name = "byte", .sz = 1, .sign = 1},
+ {.type = BUILTIN, .u.b.name = "halfword", .sz = 2, .sign = 1},
+ {.type = BUILTIN, .u.b.name = "word", .sz = 4, .sign = 1},
+ {.type = BUILTIN, .u.b.name = "long", .sz = 8, .sign = 1},
+ {.type = BUILTIN, .u.b.name = "ubyte", .sz = 1},
+ {.type = BUILTIN, .u.b.name = "uhalfword", .sz = 2},
+ {.type = BUILTIN, .u.b.name = "uword", .sz = 4},
+ {.type = BUILTIN, .u.b.name = "ulong", .sz = 8}
+ };
+
+ const struct td *td = fn->td;
+
+ for (size_t i = 0; i < sizeof builtins / sizeof *builtins; i++)
+ {
+ const struct type *t = &builtins[i];
+
+ if (!strcmp(t->u.b.name, s))
+ return t;
+ }
+
+ if (td)
+ for (size_t i = 0; i < td->ntypes; i++)
+ {
+ const struct type *t = &td->types[i];
+
+ if (!strcmp(t->tk->s, s))
+ return t;
+ }
+
+ return NULL;
+}