Initial EM-ification; start threading word size stuff through the code.
authorDavid Given <dg@cowlark.com>
Sun, 27 Nov 2016 10:58:59 +0000 (11:58 +0100)
committerDavid Given <dg@cowlark.com>
Sun, 27 Nov 2016 10:58:59 +0000 (11:58 +0100)
build.lua
lang/b/LICENSE [moved from lang/b/distr/LICENSE with 100% similarity]
lang/b/README.md [moved from lang/b/distr/README.md with 100% similarity]
lang/b/compiler/b.h [moved from lang/b/distr/b.h with 98% similarity]
lang/b/compiler/b0.c [moved from lang/b/distr/b0.c with 96% similarity]
lang/b/compiler/b1.c [moved from lang/b/distr/b1.c with 100% similarity]
lang/b/compiler/build.lua [new file with mode: 0644]

index 607a83a..dc9c0e0 100644 (file)
--- a/build.lua
+++ b/build.lua
@@ -36,6 +36,7 @@ installable {
                "lang/cem/cemcom.ansi+pkg",
                "lang/m2/comp+pkg",
                "lang/pc/comp+pkg",
+               "lang/b/compiler+pkg",
                "util/ack+pkg",
                "util/amisc+pkg",
                "util/arch+pkg",
similarity index 100%
rename from lang/b/distr/LICENSE
rename to lang/b/LICENSE
similarity index 100%
rename from lang/b/distr/README.md
rename to lang/b/README.md
similarity index 98%
rename from lang/b/distr/b.h
rename to lang/b/compiler/b.h
index 9aae946..9e10832 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <unistd.h>
 
 #define        NCPS    8       /* chars per symbol */
 #define        NCPW    4       /* chars per word */
@@ -38,6 +39,7 @@ struct        swtab {
        int     swval;
 };
 
+extern int wordsize;
 struct hshtab hshtab[HSHSIZ];
 int    hshused;
 int    eof;
similarity index 96%
rename from lang/b/distr/b0.c
rename to lang/b/compiler/b0.c
index 424e1af..25aa59c 100644 (file)
@@ -14,6 +14,8 @@ int   peeksym = -1, peeksym2 = -1;;
 int    contlab = -1;
 int    brklab = -1;
 
+int wordsize = 4;
+
 void
 init(char *s, int val)
 {
@@ -32,24 +34,37 @@ init(char *s, int val)
 int
 main(int argc, char *argv[])
 {
-       if (argc < 3) {
-               error("Arg count");
-               exit(1);
-       }
-       if (freopen(argv[1], "r", stdin) == NULL) {
-               error("Can't find %s", argv[1]);
-               exit(1);
-       }
-       if ((sbufp=fopen(argv[2], "w")) == NULL) {
-               error("Can't create %s", argv[2]);
-               exit(1);
-       }
-       if (argc > 3) {
-               if (freopen(argv[3], "w", stdout) == NULL) {
-                       error("Can't create %s", argv[2]);
-                       exit(1);
+
+       for (;;) {
+               int opt = getopt(argc, argv, "-w:i:o:");
+               if (opt == -1)
+                       break;
+
+               switch (opt) {
+                       case 'w':
+                               wordsize = atoi(optarg);
+                               break;
+
+                       case 'i':
+                               if (freopen(optarg, "r", stdin) == NULL) {
+                                       error("Can't find %s", optarg);
+                                       exit(1);
+                               }
+                               break;
+
+                       case 'o':
+                               if (freopen(optarg, "w", stdout) == NULL) {
+                                       error("Can't create %s", optarg);
+                                       exit(1);
+                               }
+                               break;
+
+                       derfault:
+                               error("Usage: em_b [-w wordsize] [-i inputfile] [-o outputfile]");
+                               exit(1);
                }
        }
+
        init("auto", AUTO);
        init("extrn", EXTERN);
        init("case", CASE);
@@ -61,7 +76,6 @@ main(int argc, char *argv[])
        init("return", RETURN);
        init("default", DEFAULT);
        init("break", BREAK);
-       fprintf(sbufp, "\t.data\n");
        while (!eof) {
                extdef();
                blkend();
@@ -191,16 +205,16 @@ getstr(void)
        int c;
        int i;
 
-       fprintf(sbufp, "\t.align 4\n");
-       fprintf(sbufp, "L%d:", cval = isn++);
+       printf("\t.align %d\n", wordsize);
+       printf("L%d:", cval = isn++);
        if ((c = mapch('"')) >= 0)
-               fprintf(sbufp, "\t.byte %04o", c);
+               printf("\t.byte %04o", c);
        for (i = 2; (c = mapch('"')) >= 0; i++)
-               fprintf(sbufp, ",%04o", c);
-       fprintf(sbufp, ",04");
+               printf(",%04o", c);
+       printf(",04");
        while ((i++%4) != 0)
-               fprintf(sbufp, ",00");
-       fprintf(sbufp, "\n");
+               printf(",00");
+       printf("\n");
        return STRING;
 }
 
@@ -525,7 +539,7 @@ extdef(void)
                global(bs);
                bsymb(bs,1);
                printf("_%s:\t.long 1f\n", bs);
-               printf("\t.text\n\t.align 4\n1:");
+               printf("\t.text\n\t.align %s\n1:", wordsize);
                function();
        done:
                printf("\n");
@@ -568,8 +582,8 @@ blkhed(void)
        struct hshtab *bs;
 
        declist();
-       stack = al = -4;
-       pl = 8;
+       stack = al = -wordsize;
+       pl = wordsize*2;
        while (paraml) {
                paraml = (bs = paraml)->next;
                bs->offset = pl;
similarity index 100%
rename from lang/b/distr/b1.c
rename to lang/b/compiler/b1.c
diff --git a/lang/b/compiler/build.lua b/lang/b/compiler/build.lua
new file mode 100644 (file)
index 0000000..76fac39
--- /dev/null
@@ -0,0 +1,21 @@
+
+cprogram {
+       name = "em_b",
+       srcs = {
+               "./*.c",
+       },
+       deps = {
+               "modules+headers",
+               "modules/src/em_code+lib_k",
+               "modules/src/em_data+lib",
+               "modules/src/em_mes+lib",
+       }
+}
+
+installable {
+       name = "pkg",
+       map = {
+               ["$(PLATDEP)/em_b"] = "+em_b"
+       }
+}
+