summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-10-27 23:33:21 -0400
committerWormHeamer2025-10-27 23:33:21 -0400
commit40d164972423056e8302bd67db9494b6e4b076b3 (patch)
tree25ff78ade2fcef01cee7339037a0ae745c416d2b
parentdd62801133cddca25d94c9c59f8ca7d0748850c6 (diff)
fix a bunch of warnings
-rw-r--r--Makefile2
-rw-r--r--ir.c17
-rw-r--r--ir.h1
-rw-r--r--main.c16
-rw-r--r--peephole.c14
-rw-r--r--typ.h15
6 files changed, 40 insertions, 25 deletions
diff --git a/Makefile b/Makefile
index b77cd62..1130156 100644
--- a/Makefile
+++ b/Makefile
@@ -22,7 +22,7 @@ BINDIR = ${PREFIX}/bin
all: ${EXE}
run: ${EXE}
- ./${EXE} ${RUNARGS} | dot -Tpng | feh -
+ ./${EXE} ${RUNARGS} | dot -Tpng | feh -B white -Z -
debug: ${EXE}
${GDB} -ex start --args ./${EXE} ${RUNARGS}
diff --git a/ir.c b/ir.c
index b15e3a8..a91db1b 100644
--- a/ir.c
+++ b/ir.c
@@ -2,21 +2,22 @@
#include <assert.h>
#include "ir.h"
+#include "typ.h"
#include "strio.h"
/* node lists */
-void nodelist_fit(NodeList *l, uint32_t sz, Arena *a) {
+void nodelist_fit(NodeList *l, u32 sz, Arena *a) {
if (l->cap) {
if (sz > l->cap) {
- uint32_t c = l->cap;
+ u32 c = l->cap;
while (sz > c) c <<= 1;
l->data = resize(a, l->data, l->cap, c);
l->cap = c;
}
} else {
if (sz > 1) {
- uint32_t cap = 2;
+ u32 cap = 2;
while (cap < sz) cap <<= 1;
Node **data = new_arr(a, Node *, cap);
data[0] = l->sbo;
@@ -101,12 +102,10 @@ void node_kill(Node *n, Graph *p) {
}
void node_add_out(Graph *p, Node *a, Node *b) {
- assert(b > 0xfffff || !b);
nodelist_push(&a->out, b, p->pool->arena);
}
void node_add_in(Graph *p, Node *a, Node *b) {
- assert(b > 0xfffff || !b);
nodelist_push(&a->in, b, p->pool->arena);
}
@@ -179,7 +178,7 @@ Node *node_dedup_lit(Graph *p, Value v) {
/* TODO: this is probably real inefficient for large procedure graphs,
* but does it matter? how many nodes are direct children of the start node?
* how many literals even usually occur in a procedure? */
- for (int i = 0; i < p->start->out.len; i++) {
+ for (u32 i = 0; i < p->start->out.len; i++) {
Node *t = p->start->out.data[i];
if (t->op == N_LIT && type_eql(&t->type, &v.type) && t->val.i == v.i) {
return t;
@@ -242,7 +241,7 @@ Str type_desc(Type *t, Arena *arena) {
void type_err(Node *n, Lexer *l) {
Str s = S("");
- for (int i = 0; i < n->in.len; i++) {
+ for (u32 i = 0; i < n->in.len; i++) {
if (i > 0) str_cat(&s, S(", "), &l->arena);
str_cat(&s, type_desc(&IN(n, i)->type, &l->arena), &l->arena);
}
@@ -259,7 +258,7 @@ static int type_ok(Node *n) {
switch (n->op) {
case N_PHI:
n->type = (Type) { .lvl = T_TOP, .t = IN(n, 1)->type.t };
- for (int i = 2; i < n->in.len; i++) {
+ for (u32 i = 2; i < n->in.len; i++) {
if (!type_base_eql(&IN(n, i)->type, &n->type)) {
return 0;
}
@@ -304,7 +303,7 @@ int node_uninit(Node *n) {
int node_maybe_uninit(Node *n) {
if (node_uninit(n)) return 1;
- for (int i = 0; i < n->in.len; i++) {
+ for (u32 i = 0; i < n->in.len; i++) {
if (IN(n,i) && node_maybe_uninit(IN(n,i))) {
return 1;
}
diff --git a/ir.h b/ir.h
index b5992c8..d10005c 100644
--- a/ir.h
+++ b/ir.h
@@ -5,6 +5,7 @@
#include "dynarr.h"
#include "lex.h" /* for error reporting only */
#include "str.h"
+#include "typ.h"
/* types */
diff --git a/main.c b/main.c
index 9f807c1..a1736f1 100644
--- a/main.c
+++ b/main.c
@@ -340,7 +340,7 @@ void parse_args_list(Lexer *l, Proc *proc) {
Node *find_return(Node *n) {
if (n->op == N_RETURN) return n;
- for (int i = 0; i < n->out.len; i++) {
+ for (u32 i = 0; i < n->out.len; i++) {
Node *r = find_return(OUT(n, i));
if (r) return r;
}
@@ -353,7 +353,7 @@ void proc_opt_fwd(Proc *p, Lexer *l, Node *n) {
n->walked = 2;
switch (n->op) {
case N_START:
- for (int i = 0; i < n->out.len; i++) {
+ for (u32 i = 0; i < n->out.len; i++) {
proc_opt_fwd(p, l, OUT(n, i));
}
break;
@@ -361,7 +361,7 @@ void proc_opt_fwd(Proc *p, Lexer *l, Node *n) {
if (n->out.len < 2) {
//lex_error_at(l, n->src_pos, LE_ERROR, S("not all codepaths return"));
}
- for (int i = 0; i < n->out.len; i++) {
+ for (u32 i = 0; i < n->out.len; i++) {
Node *r = find_return(OUT(n, i));
if (!r) {
lex_error_at(l, OUT(n, i)->src_pos, LE_ERROR, S("not all codepaths return"));
@@ -387,7 +387,7 @@ void proc_opt_fwd(Proc *p, Lexer *l, Node *n) {
proc_opt_fwd(p, l, new_ctrl);
return;
}
- for (int i = 0; i < n->out.len; i++) {
+ for (u32 i = 0; i < n->out.len; i++) {
if (OUT(n, i)->op != N_PHI) {
proc_opt_fwd(p, l, OUT(n, i));
}
@@ -405,7 +405,7 @@ void proc_opt(Proc *p, Lexer *l) {
lex_error(l, LE_ERROR, str_fmt(&p->scratch, "no return statement in function expecting %S", type_desc(&p->ret_type, &p->scratch)));
}
}
- for (int i = 0; i < g->start->out.len; i++) {
+ for (u32 i = 0; i < g->start->out.len; i++) {
Node *n = OUT(g->start, i);
if (n->op == N_LIT && n->out.len < 1) {
node_kill(n, g);
@@ -622,12 +622,12 @@ void node_print(Node *n, Proc *p) {
printf("\t%d [label=\"%s\", shape=record]", n->id, node_type_name(n->op));
}
printf("\n");
- for (int i = 0; i < n->out.len; i++) {
+ for (u32 i = 0; i < n->out.len; i++) {
Node *o = OUT(n, i);
if (o->op == N_LIT) {
printf("\t%d -> %d [style=dashed]\n", n->id, o->id);
} else {
- int j;
+ u32 j;
for (j = 0; j < o->in.len && IN(o, j) != n; j++);
if (j == 0) {
printf("\t%d -> %d [color=red,headlabel=%d]\n", n->id, o->id, j);
@@ -636,7 +636,7 @@ void node_print(Node *n, Proc *p) {
}
}
}
- for (int i = 0; i < n->out.len; i++) {
+ for (u32 i = 0; i < n->out.len; i++) {
node_print(OUT(n, i), p);
}
}
diff --git a/peephole.c b/peephole.c
index a0fd339..06ded1a 100644
--- a/peephole.c
+++ b/peephole.c
@@ -59,7 +59,7 @@ static inline int node_cmp_incompat(NodeType a, NodeType b) {
Value node_compute(Node *n, Lexer *l) {
Type lit_type = { .lvl = T_BOT };
- for (int i = 1; i < n->in.len; i++) {
+ for (u32 i = 1; i < n->in.len; i++) {
Node *p = IN(n, i);
if (p->type.lvl != T_CONST) {
lit_type.lvl = T_BOT;
@@ -203,7 +203,7 @@ static int node_equiv(Node *a, Node *b) {
if (a->op != b->op) return 0;
if (a->in.len != b->in.len) return 0;
if (!value_eql(&a->val, &b->val)) return 0;
- for (int i = 1; i < a->in.len; i++) {
+ for (u32 i = 1; i < a->in.len; i++) {
if (!node_equiv(IN(a, i), IN(b, i))) return 0;
}
return 1;
@@ -234,7 +234,7 @@ static int node_equiv_input(Node *a, Node *b) {
fprintf(stderr, "equiv\n");
return 1;
}
- for (int i = 1; i < a->in.len; i++) {
+ for (u32 i = 1; i < a->in.len; i++) {
if (!node_equiv(IN(a, i), IN(b, i))) return 0;
}
return 1;
@@ -294,7 +294,7 @@ Node *node_idealize(Node *n, Graph *p, Lexer *l) {
/* try to trim duplicate inputs from the graph */
int same = 1, same_ptr = 1;
- for (int i = 1; i < n->in.len; i++) {
+ for (u32 i = 1; i < n->in.len; i++) {
if (IN(n, i) == CAR(n)) continue;
same_ptr = 0;
if (!node_equiv(IN(n, i), CAR(n))) {
@@ -305,7 +305,7 @@ Node *node_idealize(Node *n, Graph *p, Lexer *l) {
if (n->in.len > 2 && same && !same_ptr) {
Node *r = node_new(p, n->op, NULL);
- for (int i = 0; i < n->in.len; i++) {
+ for (u32 i = 0; i < n->in.len; i++) {
node_add(p, CAR(n), r);
}
return node_peephole(r, p, l);
@@ -552,11 +552,11 @@ zero_no_effect: if (node_eql_i64(CAR(n), 0)) return CDR(n);
case N_REGION: {
int live_in = 0;
- for (int i = 0; i < n->in.len; i++) {
+ for (u32 i = 0; i < n->in.len; i++) {
if (IN(n, i)->type.lvl != T_XCTRL) live_in++;
}
if (live_in == 1) {
- for (int i = 0; i < n->in.len; i++) {
+ for (u32 i = 0; i < n->in.len; i++) {
if (IN(n, i)->type.lvl != T_XCTRL) {
return IN(n, i);
}
diff --git a/typ.h b/typ.h
new file mode 100644
index 0000000..9ed65ea
--- /dev/null
+++ b/typ.h
@@ -0,0 +1,15 @@
+#ifndef TYP_H
+#define TYP_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+typedef int16_t i16;
+typedef int32_t i32;
+typedef int64_t i64;
+typedef uint16_t u16;
+typedef uint32_t u32;
+typedef uint64_t u64;
+typedef size_t usize;
+
+#endif