scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit f9da346c95dfad26333b396bdc1e52b158131a42
parent 3fec6915074c2fb31d3e955ad9eee51c091df1cc
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  2 Jan 2025 08:37:17 +0100

cc2: Define a mach structure

There are decisions to be taken in common code that will
depend of different aspects of the machine, and  instead
of trying to guess what are the correct values based  in
tricks like the name is better to define a Mach   struct
that defines all the information.

Diffstat:
Msrc/cmd/scc-cc/cc2/cc2.h | 7++++++-
Msrc/cmd/scc-cc/cc2/main.c | 3---
Msrc/cmd/scc-cc/cc2/qbe/Makefile | 2+-
Asrc/cmd/scc-cc/cc2/qbe/mach.c | 9+++++++++
Msrc/cmd/scc-cc/cc2/swtch.c | 2+-
Msrc/cmd/scc-cc/cc2/z80-scc/Makefile | 1+
Asrc/cmd/scc-cc/cc2/z80-scc/mach.c | 5+++++
7 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/src/cmd/scc-cc/cc2/cc2.h b/src/cmd/scc-cc/cc2/cc2.h @@ -164,6 +164,11 @@ typedef struct addr Addr; typedef struct inst Inst; typedef struct block Block; typedef struct swtch Swtch; +typedef struct mach Mach; + +struct mach { + int swtchif; +}; struct swtch { int nr; @@ -315,7 +320,7 @@ extern Symbol *curfun; extern Symbol *locals; extern Inst *pc, *prog; extern Node *laststmt; -extern int noswtch; +extern Mach mach; /* target */ extern Type int8type, int16type, int32type, int64type, diff --git a/src/cmd/scc-cc/cc2/main.c b/src/cmd/scc-cc/cc2/main.c @@ -61,9 +61,6 @@ main(int argc, char *argv[]) if (argv[0] && !freopen(argv[0], "r", stdin)) die("cc2: %s: %s", argv[0], strerror(errno)); - if (strstr(argv0, "qbe")) - noswtch = 1; - while (moreinput()) { parse(); if (curfun) { diff --git a/src/cmd/scc-cc/cc2/qbe/Makefile b/src/cmd/scc-cc/cc2/qbe/Makefile @@ -3,10 +3,10 @@ PROJECTDIR = ../../../../.. include $(PROJECTDIR)/scripts/rules.mk - OBJS =\ cgen.o \ code.o \ + mach.o \ stubs.o \ all: builtin.o diff --git a/src/cmd/scc-cc/cc2/qbe/mach.c b/src/cmd/scc-cc/cc2/qbe/mach.c @@ -0,0 +1,9 @@ +#include <limits.h> + +#include <scc/scc.h> + +#include "../cc2.h" + +Mach mach = { + .swtchif = INT_MAX, +}; diff --git a/src/cmd/scc-cc/cc2/swtch.c b/src/cmd/scc-cc/cc2/swtch.c @@ -106,7 +106,7 @@ swtch(Node *np) range = max - min + 1; n = swt->nr; - if (n < 4 || noswtch) + if (n < mach.swtchif) return swtch_if(np); return swtch_dir(np, min, max); } diff --git a/src/cmd/scc-cc/cc2/z80-scc/Makefile b/src/cmd/scc-cc/cc2/z80-scc/Makefile @@ -7,6 +7,7 @@ include $(PROJECTDIR)/scripts/rules.mk OBJS =\ cgen.o \ code.o \ + mach.o \ peep.o \ types.o \ diff --git a/src/cmd/scc-cc/cc2/z80-scc/mach.c b/src/cmd/scc-cc/cc2/z80-scc/mach.c @@ -0,0 +1,5 @@ +#include <scc/scc.h> + +#include "../cc2.h" + +Mach mach;