diff options
Diffstat (limited to 'type.c')
| -rw-r--r-- | type.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -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; +} |
