summaryrefslogtreecommitdiff
path: root/ir.h
diff options
context:
space:
mode:
Diffstat (limited to 'ir.h')
-rw-r--r--ir.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/ir.h b/ir.h
index 8b963f7..b5992c8 100644
--- a/ir.h
+++ b/ir.h
@@ -100,7 +100,13 @@ typedef enum {
const char *node_type_name(NodeType t);
-typedef DYNARR(struct Node *) NodeList;
+typedef struct {
+ unsigned len, cap;
+ union {
+ struct Node *sbo;
+ struct Node **data;
+ };
+} NodeList;
typedef struct Node {
int id, refs;
@@ -122,8 +128,9 @@ typedef struct Node {
/* convenience macros (lisp-inspired lol) */
-#define IN(n, i) ((n)->in.data[i])
-#define OUT(n, i) ((n)->out.data[i])
+#define Ni(nl, i) (*nodelist_nth(&(nl), i))
+#define IN(n, i) Ni(n->in, i)
+#define OUT(n, i) Ni(n->out, i)
#define CTRL(n) IN(n, 0)
#define CAR(n) IN(n, 1)
@@ -187,4 +194,12 @@ int node_maybe_uninit(Node *n);
#define node_new(...) node_newv(__VA_ARGS__, NULL)
+static inline Node **nodelist_data(NodeList *l) {
+ return l->cap ? l->data : &l->sbo;
+}
+
+static inline Node **nodelist_nth(NodeList *l, uint32_t i) {
+ return nodelist_data(l) + i;
+}
+
#endif