home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
messroms.de
/
2007-01-13_www.messroms.de.zip
/
VZ200
/
TOOLS
/
ZCCSRC.ZIP
/
scc
/
main.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-03-06
|
5KB
|
307 lines
/* File main.c: 2.7 (84/11/28,10:14:56) */
/*% cc -O -c %
*
*/
#include <stdio.h>
#include "defs.h"
#include "data.h"
#include "proto.h"
int main(int argc, char **argv)
{
char *p, *bp;
int smacptr;
macptr = 0;
ctext = 0;
argc--;
argv++;
errs = 0;
aflag = 1;
#ifdef FRAME_IX
frameix = 0;
#endif
while (NULL!=(p = *argv++))
{
if (*p == '-')
while (*++p)
switch (*p)
{
case 't':
case 'T':
ctext = 1;
break;
case 's':
case 'S':
sflag = 1;
break;
case 'c':
case 'C':
cflag = 1;
break;
case 'a':
case 'A':
aflag = 0;
break;
case 'd':
case 'D':
bp = ++p;
if (!*p)
usage();
while (*p && *p != '=')
p++;
if (*p == '=')
*p = '\t';
while (*p)
p++;
p--;
defmac(bp);
break;
#ifdef FRAME_IX
case 'x':
case 'X':
frameix = 1;
break;
#endif
default:
usage();
}
else
break;
}
smacptr = macptr;
if (!p)
usage();
while (p)
{
errfile = 0;
if (xtypeof(p) == 'c' || xtypeof(p) == 'i')
{
glbptr = STARTGLB;
locptr = STARTLOC;
wsptr = ws;
inclsp = 0;
iflevel = 0;
skiplevel = 0;
swstp = 0;
litptr = 0;
stkp = 0;
errcnt = 0;
ncmp = 0;
lastst = 0;
macptr = smacptr;
input2 = NULL;
quote[0] = '"';
quote[1] = 0;
cmode = 1;
glbflag = 1;
nxtlab = 0;
litlab = getlabel();
defmac("end\tmemory");
addglb("memory", ARRAY, CCHAR, 0, EXTERN);
addglb("stack", ARRAY, CCHAR, 0, EXTERN);
rglbptr = glbptr;
addglb("etext", ARRAY, CCHAR, 0, EXTERN);
addglb("edata", ARRAY, CCHAR, 0, EXTERN);
defmac("short\tint");
initmac();
/* compiler body */
if (!openin(p))
return (1);
if (!openout())
return (1);
header(p);
gtext();
parse();
fclose(input);
gdata();
dumplits();
gbss();
dumpglbs();
errorsummary();
trailer();
fclose(output);
errs = errs || errfile;
}
else
{
fputs("Don't understand file ", stderr);
fputs(p, stderr);
fputs("\n", stderr);
errs = 1;
}
p = *argv++;
}
exit(errs != 0);
}
void FEvers(void)
{
outstr("\tFront End (2.7,84/11/28)");
}
void usage(void)
{
fputs("usage: sccXXXX [-tcsa] [-dSYM[=VALUE]] files\n", stderr);
exit(1);
}
/* Process all input text
*
* At this level, only static declarations, defines,
* includes, and function definitions are legal.
*/
void parse(void)
{
while (!feof(input))
{
if (amatch("extern", 6))
dodcls(EXTERN);
else
if (amatch("static", 6))
dodcls(STATIC);
else
if (dodcls(PUBLIC))
;
else
if (match("#asm"))
doasm();
else
if (match("#include"))
doinclude();
else
if (match("#define"))
dodefine();
else
if (match("#undef"))
doundef();
else
if (match("#line") || match("#"))
kill();
else
newfunc();
blanks();
}
}
/* Parse top level declarations */
int dodcls(int stclass)
{
blanks();
if (amatch("char", 4))
declglb(CCHAR, stclass);
else
if (amatch("int", 3))
declglb(CINT, stclass);
else
if (stclass == PUBLIC)
return (0);
else
declglb(CINT, stclass);
ns();
return (1);
}
/* Dump the literal pool */
void dumplits(void)
{
int j, k;
if (litptr == 0)
return;
printlabel(litlab);
col();
k = 0;
while (k < litptr)
{
defbyte();
j = 8;
while (j--)
{
/* HJB 03/03/00 I want 8 bit string support */
/* outdec(litq[k++] & 127); */
outdec(litq[k++]);
if ((j == 0) | (k >= litptr))
{
nl();
break;
}
outbyte(',');
}
}
}
/* Dump all static variables */
void dumpglbs(void)
{
int j;
if (!glbflag)
return;
cptr = rglbptr;
while (cptr < glbptr)
{
if (cptr[IDENT] != FUNCTION)
{
ppubext(cptr);
if (cptr[STORAGE] != EXTERN)
{
prefix();
outstr(cptr);
col();
defstorage();
j = glint(cptr);
if ((cptr[TYPE] == CINT) ||
(cptr[IDENT] == POINTER))
j = j * intsize();
onum(j);
nl();
}
}
else
{
fpubext(cptr);
}
cptr = cptr + SYMSIZ;
}
}
/* Report errors */
void errorsummary(void)
{
if (ncmp)
error("missing closing bracket");
nl();
comment();
outdec(errcnt);
if (errcnt)
errfile = YES;
outstr(" error(s) in compilation");
nl();
comment();
ot("Literal pool:");
outdec(litptr);
nl();
comment();
ot("Global pool :");
outdec(glbptr - rglbptr);
nl();
comment();
ot("Macro pool :");
outdec(macptr);
nl();
if (errcnt)
pl("Error(s)\n");
}
char xtypeof(char *s)
{
s += strlen(s) - 2;
if (*s == '.')
return (*(s + 1));
return (' ');
}