summaryrefslogtreecommitdiff
path: root/c/libdietc.h
diff options
context:
space:
mode:
Diffstat (limited to 'c/libdietc.h')
-rw-r--r--c/libdietc.h83
1 files changed, 83 insertions, 0 deletions
diff --git a/c/libdietc.h b/c/libdietc.h
new file mode 100644
index 0000000..14b7ad2
--- /dev/null
+++ b/c/libdietc.h
@@ -0,0 +1,83 @@
+#pragma once
+
+static char *strchrnul(char *s, char c) {
+ while (*s && *s != c) s++;
+ return s;
+}
+
+enum TYPE {
+ TYPE_BASIC,
+ TYPE_POINTER,
+ TYPE_ARRAY,
+ TYPE_STRUCT,
+ TYPE_UNION,
+ TYPE_FUNCTION,
+};
+
+struct type {
+ char *typedef_line;
+ enum TYPE kind;
+ unsigned long id;
+
+ // basic type
+ char *basic;
+
+ // pointer & array types
+ struct type *base;
+ unsigned long length;
+
+ // struct & union types
+ struct type *members;
+ struct type *next_member;
+ char *field_name;
+
+ // function types
+ struct type *return_type;
+ struct type *params;
+ struct type *next_param;
+ unsigned long is_variadic;
+};
+
+struct instruction {
+ char *line;
+ struct instruction *next;
+};
+
+struct function {
+ char *start_line;
+ struct type *type;
+ struct instruction *instructions;
+ struct function *next;
+};
+
+struct object {
+ char *name;
+ struct type *type;
+};
+
+struct program {
+ char *original;
+
+ // all lines before the function definitions
+ char *preamble;
+
+ // id -> type table
+ struct type **id2type;
+ unsigned long n_types;
+
+ // hash map of objects
+ struct object **objects;
+ unsigned long cap_objects;
+ unsigned long n_objects;
+
+ struct function *functions;
+};
+
+struct identifiers {
+ char *token;
+ struct identifier *next;
+};
+
+char *libdietc_tokdup(char *tok);
+struct program libdietc_parse(char *filename);
+void libdietc_print(struct program program);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback