Initial EM-ification; start threading word size stuff through the code.
This commit is contained in:
parent
a69045c0e4
commit
cfc723250f
7 changed files with 65 additions and 27 deletions
|
@ -36,6 +36,7 @@ installable {
|
||||||
"lang/cem/cemcom.ansi+pkg",
|
"lang/cem/cemcom.ansi+pkg",
|
||||||
"lang/m2/comp+pkg",
|
"lang/m2/comp+pkg",
|
||||||
"lang/pc/comp+pkg",
|
"lang/pc/comp+pkg",
|
||||||
|
"lang/b/compiler+pkg",
|
||||||
"util/ack+pkg",
|
"util/ack+pkg",
|
||||||
"util/amisc+pkg",
|
"util/amisc+pkg",
|
||||||
"util/arch+pkg",
|
"util/arch+pkg",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define NCPS 8 /* chars per symbol */
|
#define NCPS 8 /* chars per symbol */
|
||||||
#define NCPW 4 /* chars per word */
|
#define NCPW 4 /* chars per word */
|
||||||
|
@ -38,6 +39,7 @@ struct swtab {
|
||||||
int swval;
|
int swval;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern int wordsize;
|
||||||
struct hshtab hshtab[HSHSIZ];
|
struct hshtab hshtab[HSHSIZ];
|
||||||
int hshused;
|
int hshused;
|
||||||
int eof;
|
int eof;
|
|
@ -14,6 +14,8 @@ int peeksym = -1, peeksym2 = -1;;
|
||||||
int contlab = -1;
|
int contlab = -1;
|
||||||
int brklab = -1;
|
int brklab = -1;
|
||||||
|
|
||||||
|
int wordsize = 4;
|
||||||
|
|
||||||
void
|
void
|
||||||
init(char *s, int val)
|
init(char *s, int val)
|
||||||
{
|
{
|
||||||
|
@ -32,24 +34,37 @@ init(char *s, int val)
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
if (argc < 3) {
|
|
||||||
error("Arg count");
|
for (;;) {
|
||||||
exit(1);
|
int opt = getopt(argc, argv, "-w:i:o:");
|
||||||
}
|
if (opt == -1)
|
||||||
if (freopen(argv[1], "r", stdin) == NULL) {
|
break;
|
||||||
error("Can't find %s", argv[1]);
|
|
||||||
exit(1);
|
switch (opt) {
|
||||||
}
|
case 'w':
|
||||||
if ((sbufp=fopen(argv[2], "w")) == NULL) {
|
wordsize = atoi(optarg);
|
||||||
error("Can't create %s", argv[2]);
|
break;
|
||||||
exit(1);
|
|
||||||
}
|
case 'i':
|
||||||
if (argc > 3) {
|
if (freopen(optarg, "r", stdin) == NULL) {
|
||||||
if (freopen(argv[3], "w", stdout) == NULL) {
|
error("Can't find %s", optarg);
|
||||||
error("Can't create %s", argv[2]);
|
exit(1);
|
||||||
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("auto", AUTO);
|
||||||
init("extrn", EXTERN);
|
init("extrn", EXTERN);
|
||||||
init("case", CASE);
|
init("case", CASE);
|
||||||
|
@ -61,7 +76,6 @@ main(int argc, char *argv[])
|
||||||
init("return", RETURN);
|
init("return", RETURN);
|
||||||
init("default", DEFAULT);
|
init("default", DEFAULT);
|
||||||
init("break", BREAK);
|
init("break", BREAK);
|
||||||
fprintf(sbufp, "\t.data\n");
|
|
||||||
while (!eof) {
|
while (!eof) {
|
||||||
extdef();
|
extdef();
|
||||||
blkend();
|
blkend();
|
||||||
|
@ -191,16 +205,16 @@ getstr(void)
|
||||||
int c;
|
int c;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
fprintf(sbufp, "\t.align 4\n");
|
printf("\t.align %d\n", wordsize);
|
||||||
fprintf(sbufp, "L%d:", cval = isn++);
|
printf("L%d:", cval = isn++);
|
||||||
if ((c = mapch('"')) >= 0)
|
if ((c = mapch('"')) >= 0)
|
||||||
fprintf(sbufp, "\t.byte %04o", c);
|
printf("\t.byte %04o", c);
|
||||||
for (i = 2; (c = mapch('"')) >= 0; i++)
|
for (i = 2; (c = mapch('"')) >= 0; i++)
|
||||||
fprintf(sbufp, ",%04o", c);
|
printf(",%04o", c);
|
||||||
fprintf(sbufp, ",04");
|
printf(",04");
|
||||||
while ((i++%4) != 0)
|
while ((i++%4) != 0)
|
||||||
fprintf(sbufp, ",00");
|
printf(",00");
|
||||||
fprintf(sbufp, "\n");
|
printf("\n");
|
||||||
return STRING;
|
return STRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -525,7 +539,7 @@ extdef(void)
|
||||||
global(bs);
|
global(bs);
|
||||||
bsymb(bs,1);
|
bsymb(bs,1);
|
||||||
printf("_%s:\t.long 1f\n", bs);
|
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();
|
function();
|
||||||
done:
|
done:
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
@ -568,8 +582,8 @@ blkhed(void)
|
||||||
struct hshtab *bs;
|
struct hshtab *bs;
|
||||||
|
|
||||||
declist();
|
declist();
|
||||||
stack = al = -4;
|
stack = al = -wordsize;
|
||||||
pl = 8;
|
pl = wordsize*2;
|
||||||
while (paraml) {
|
while (paraml) {
|
||||||
paraml = (bs = paraml)->next;
|
paraml = (bs = paraml)->next;
|
||||||
bs->offset = pl;
|
bs->offset = pl;
|
21
lang/b/compiler/build.lua
Normal file
21
lang/b/compiler/build.lua
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue