aboutsummaryrefslogtreecommitdiff
path: root/src/primitives.gperf
diff options
context:
space:
mode:
Diffstat (limited to 'src/primitives.gperf')
-rw-r--r--src/primitives.gperf36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/primitives.gperf b/src/primitives.gperf
new file mode 100644
index 0000000..449a030
--- /dev/null
+++ b/src/primitives.gperf
@@ -0,0 +1,36 @@
+%compare-strncmp
+%includes
+%language=ANSI-C
+%readonly-tables
+%struct-type
+
+%{
+#include <stdbool.h>
+
+#include "analyzer.h"
+#include "types.h"
+
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+%}
+
+struct typeslot { char *name; struct type inner; };
+%%
+i8, { TYPE_I8, 1, true }
+i16, { TYPE_I16, 2, true }
+i32, { TYPE_I32, 4, true }
+i64, { TYPE_I64, 8, true }
+int, { TYPE_INT, 8, true }
+u8, { TYPE_U8, 1, false }
+u16, { TYPE_U16, 2, false }
+u32, { TYPE_U32, 4, false }
+u64, { TYPE_U64, 8, false }
+uint, { TYPE_UINT, 8, false }
+rune, { TYPE_RUNE, 4, true }
+%%
+const struct type *
+typelookup(const uchar *p, size_t len)
+{
+ const struct typeslot *tp = in_word_set(p, len);
+ return tp == NULL ? NULL : &tp->inner;
+}