commit f9abdd7888869258a99de6ce8e1f894035a1d9e3
parent 199aaf23b5da8b9c77351d861fa37aa3f4f172e6
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Fri, 27 Dec 2024 23:04:14 +0100
cc2: Add range() and delrange()
The range datatype enables making operations over specific
ranges of statements that will fit very well in operations
over basic blocks.
Diffstat:
2 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h
@@ -276,6 +276,8 @@ extern Node *addstmt(Node *np, int flags);
extern Node *delstmt(void);
extern Node *nextstmt(void);
extern Node *insstmt(Node *, Node *, int);
+extern void delrange(Range *);
+extern Range range(Node *, Node *);
/* symbol.c */
#define TMPSYM 0
diff --git a/src/cmd/scc-cc/cc2/node.c b/src/cmd/scc-cc/cc2/node.c
@@ -185,6 +185,37 @@ newfun(Symbol *sym)
}
void
+delrange(Range *rp)
+{
+ Node *lprev, *rnext, *next, *np;
+
+ lprev = rp->begin->prev;
+ rnext = rp->end->next;
+
+ if (lprev)
+ lprev->next = rnext;
+ if (rnext)
+ rnext->prev = lprev;
+
+ for (np = rp->begin; np != rnext; np = next) {
+ next = np->next;
+ deltree(np);
+ }
+
+ rp->begin = rp->end = rp->cur = NULL;
+}
+
+Range
+range(Node *begin, Node *end)
+{
+ Range r;
+
+ r.cur = r.begin = begin;
+ r.end = end;
+ return r;
+}
+
+void
apply(Node *(*fun)(Node *))
{
if (!curfun)