commit 46f7ea655c0f4f25e851b9197487269529eb5641
parent 408fe0b905d854c979a98e9600f5671b7001f008
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 10 Dec 2024 09:42:31 +0100
cc2: Add genasm()
Different targets will need additional and different things,
so having a function that can be customized helps to avoid
things like the current basic block calculation that only
makes sense from the point of view of qbe.
Diffstat:
10 files changed, 25 insertions(+), 24 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/amd64-sysv/cgen.c b/src/cmd/scc-cc/cc2/amd64-sysv/cgen.c
@@ -2,8 +2,8 @@
#include <scc/scc.h>
#include "../cc2.h"
-Node *
-cgen(Node *np)
+void
+genasm(void)
{
}
diff --git a/src/cmd/scc-cc/cc2/amd64-sysv/code.c b/src/cmd/scc-cc/cc2/amd64-sysv/code.c
@@ -202,8 +202,3 @@ void
endinit(void)
{
}
-
-void
-getbblocks(void)
-{
-}
diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h
@@ -222,7 +222,7 @@ extern Node *optm_dep(Node *np), *optm_ind(Node *np);
/* cgen.c */
extern Node *sethi(Node *np);
-extern Node *cgen(Node *np);
+extern void genasm(void);
/* peep.c */
extern void peephole(void);
@@ -232,7 +232,7 @@ extern void data(Node *np);
extern void writeout(void), endinit(void);
extern void code(int op, Node *to, Node *from1, Node *from2);
extern void defvar(Symbol *), defpar(Symbol *), defglobal(Symbol *);
-extern void setlabel(Symbol *sym), getbblocks(void);
+extern void setlabel(Symbol *);
extern Node *label2node(Node *np, Symbol *sym);
extern Node *constnode(Node *np, TUINT n, Type *tp);
extern Node *tmpnode(Type *);
diff --git a/src/cmd/scc-cc/cc2/i386-sysv/cgen.c b/src/cmd/scc-cc/cc2/i386-sysv/cgen.c
@@ -3,8 +3,8 @@
#include "arch.h"
#include "../cc2.h"
-Node *
-cgen(Node *np)
+void
+genasm(void)
{
}
diff --git a/src/cmd/scc-cc/cc2/i386-sysv/code.c b/src/cmd/scc-cc/cc2/i386-sysv/code.c
@@ -201,8 +201,3 @@ void
endinit(void)
{
}
-
-void
-getbblocks(void)
-{
-}
diff --git a/src/cmd/scc-cc/cc2/main.c b/src/cmd/scc-cc/cc2/main.c
@@ -60,8 +60,7 @@ main(int argc, char *argv[])
apply(optm_ind);
apply(optm_dep);
apply(sethi);
- apply(cgen);
- getbblocks(); /* TODO: run apply over asm ins too */
+ genasm();
peephole();
writeout();
}
diff --git a/src/cmd/scc-cc/cc2/qbe/arch.h b/src/cmd/scc-cc/cc2/qbe/arch.h
@@ -145,3 +145,5 @@ enum asmop {
ASVSTAR,
ASVARG,
};
+
+extern void getbblocks(void);
diff --git a/src/cmd/scc-cc/cc2/qbe/cgen.c b/src/cmd/scc-cc/cc2/qbe/cgen.c
@@ -12,6 +12,8 @@
#define I4BYTES 2
#define I8BYTES 3
+static Node *cgen(Node *);
+
static unsigned char opasmw[][2] = {
[OADD] = {ASADDW, ASADDW},
[OSUB] = {ASSUBW, ASSUBW},
@@ -753,7 +755,7 @@ rhs(Node *np)
abort();
}
-Node *
+static Node *
cgen(Node *np)
{
Node aux, *p, *next;
@@ -784,3 +786,10 @@ cgen(Node *np)
}
return NULL;
}
+
+void
+genasm(void)
+{
+ apply(cgen);
+ getbblocks();
+}
diff --git a/src/cmd/scc-cc/cc2/z80-scc/cgen.c b/src/cmd/scc-cc/cc2/z80-scc/cgen.c
@@ -98,6 +98,12 @@ cgen(Node *np)
return NULL;
}
+void
+genasm(void)
+{
+ apply(cgen);
+}
+
/*
* This is strongly influenced by
* http://plan9.bell-labs.com/sys/doc/compiler.ps (/sys/doc/compiler.ps)
diff --git a/src/cmd/scc-cc/cc2/z80-scc/code.c b/src/cmd/scc-cc/cc2/z80-scc/code.c
@@ -221,8 +221,3 @@ void
endinit(void)
{
}
-
-void
-getbblocks(void)
-{
-}