Merge branch 'master' into codesourcery.
All Matt's advices applied.
This commit is contained in:
@@ -55,7 +55,7 @@ int fgethdr (text, h)
|
||||
register FILE *text;
|
||||
register struct exec *h;
|
||||
{
|
||||
h->a_magic = fgetword (text);
|
||||
h->a_midmag = fgetword (text);
|
||||
h->a_text = fgetword (text);
|
||||
h->a_data = fgetword (text);
|
||||
h->a_bss = fgetword (text);
|
||||
@@ -235,7 +235,7 @@ void disasm (fname)
|
||||
return;
|
||||
}
|
||||
if (rflag) {
|
||||
if (hdr.a_magic != RMAGIC) {
|
||||
if (N_GETMAGIC(hdr) != RMAGIC) {
|
||||
fprintf (stderr, "aout: %s is not relocatable\n",
|
||||
fname);
|
||||
rflag = 0;
|
||||
@@ -250,9 +250,9 @@ void disasm (fname)
|
||||
}
|
||||
printf ("File %s:\n", fname);
|
||||
printf (" a_magic = %08x (%s)\n", hdr.a_magic,
|
||||
hdr.a_magic == RMAGIC ? "relocatable" :
|
||||
hdr.a_magic == OMAGIC ? "OMAGIC" :
|
||||
hdr.a_magic == NMAGIC ? "NMAGIC" : "unknown");
|
||||
N_GETMAGIC(hdr) == RMAGIC ? "relocatable" :
|
||||
N_GETMAGIC(hdr) == OMAGIC ? "OMAGIC" :
|
||||
N_GETMAGIC(hdr) == NMAGIC ? "NMAGIC" : "unknown");
|
||||
printf (" a_text = %08x (%u bytes)\n", hdr.a_text, hdr.a_text);
|
||||
printf (" a_data = %08x (%u bytes)\n", hdr.a_data, hdr.a_data);
|
||||
printf (" a_bss = %08x (%u bytes)\n", hdr.a_bss, hdr.a_bss);
|
||||
@@ -261,7 +261,7 @@ void disasm (fname)
|
||||
printf (" a_syms = %08x (%u bytes)\n", hdr.a_syms, hdr.a_syms);
|
||||
printf (" a_entry = %08x\n", hdr.a_entry);
|
||||
|
||||
addr = (hdr.a_magic == RMAGIC) ? 0 : USER_CODE_START;
|
||||
addr = ((hdr.a_magic) == RMAGIC) ? 0 : USER_CODE_START;
|
||||
|
||||
if (hdr.a_text > 0) {
|
||||
printf ("\nSection .text:\n");
|
||||
|
||||
@@ -1242,7 +1242,7 @@ void emitword (w, r, clobber_reg)
|
||||
reorder_word = w;
|
||||
reorder_rel = *r;
|
||||
reorder_full = 1;
|
||||
reorder_clobber = clobber_reg;
|
||||
reorder_clobber = clobber_reg & 15;
|
||||
} else {
|
||||
fputword (w, sfile[segm]);
|
||||
fputrel (r, rfile[segm]);
|
||||
@@ -1321,10 +1321,9 @@ void makecmd (opcode, type, emitfunc)
|
||||
unsigned opcode;
|
||||
void (*emitfunc) (unsigned, struct reloc*);
|
||||
{
|
||||
register int clex;
|
||||
register unsigned offset;
|
||||
unsigned offset, orig_opcode = 0;
|
||||
struct reloc relinfo;
|
||||
int cval, segment, clobber_reg, negate_literal;
|
||||
int clex, cval, segment, clobber_reg, negate_literal;
|
||||
|
||||
offset = 0;
|
||||
relinfo.flags = RABS;
|
||||
@@ -1484,6 +1483,7 @@ frs1: clex = getlex (&cval);
|
||||
cval = (opcode >> 11) & 31; /* get 1-st register */
|
||||
newop |= cval << 16; /* set 1-st register */
|
||||
newop |= opcode & (31 << 21); /* set 2-nd register */
|
||||
orig_opcode = opcode;
|
||||
opcode = newop;
|
||||
type = FRT1 | FRS2 | FOFF16 | FMOD;
|
||||
goto foff16;
|
||||
@@ -1576,24 +1576,65 @@ fsa: offset = getexpr (&segment);
|
||||
}
|
||||
} else if (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) {
|
||||
/* Relocatable offset */
|
||||
int valid_range;
|
||||
|
||||
if ((type & (FOFF16 | FOFF18 | FHIGH16)) && getlex (&cval) != ',')
|
||||
uerror ("comma expected");
|
||||
foff16: expr_flags = 0;
|
||||
offset = getexpr (&segment);
|
||||
relinfo.flags = segmrel [segment];
|
||||
if (negate_literal) {
|
||||
// Negate literal arg for sub and subu
|
||||
offset = -offset;
|
||||
if (relinfo.flags != RABS)
|
||||
uerror ("cannot negate relocatable literal");
|
||||
}
|
||||
if (relinfo.flags == REXT)
|
||||
relinfo.index = extref;
|
||||
if (expr_flags & EXPR_GPREL)
|
||||
relinfo.flags |= RGPREL;
|
||||
switch (type & (FOFF16 | FOFF18 | FAOFF18 | FAOFF28 | FHIGH16)) {
|
||||
case FOFF16: /* low 16-bit byte address */
|
||||
opcode |= offset & 0xffff;
|
||||
/* Test whether the immediate is in valid range
|
||||
* for the opcode. */
|
||||
if (negate_literal) {
|
||||
// Negate literal arg for sub and subu
|
||||
offset = -offset;
|
||||
if (relinfo.flags != RABS)
|
||||
uerror ("cannot negate relocatable literal");
|
||||
}
|
||||
switch (opcode & 0xfc000000) {
|
||||
default: /* addi, addiu, slti, sltiu, lw, sw */
|
||||
/* 16-bit signed value. */
|
||||
valid_range = (offset >= -0x8000) || (offset <= 0x7fff);
|
||||
break;
|
||||
case 0x30000000: /* andi */
|
||||
case 0x34000000: /* ori */
|
||||
case 0x38000000: /* xori */
|
||||
/* 16-bit unsigned value. */
|
||||
valid_range = (offset <= 0xffff);
|
||||
break;
|
||||
}
|
||||
if (valid_range) {
|
||||
opcode |= offset & 0xffff;
|
||||
} else if (orig_opcode == 0 || ! mode_at) {
|
||||
uerror ("value out of range");
|
||||
} else {
|
||||
/* Convert back to 3-reg opcode.
|
||||
* Insert an extra LI instruction. */
|
||||
if (segment != SABS)
|
||||
uerror ("absolute value required");
|
||||
if (negate_literal)
|
||||
offset = -offset;
|
||||
|
||||
if (offset <= 0xffff) {
|
||||
/* ori $1, $zero, value */
|
||||
emitword (0x34010000 | offset, &relabs, 1);
|
||||
} else if (offset >= -0x8000) {
|
||||
/* addiu $1, $zero, value */
|
||||
emitword (0x24010000 | (offset & 0xffff), &relabs, 1);
|
||||
} else {
|
||||
/* lui $1, value[31:16]
|
||||
* ori $1, $1, value[15:0]) */
|
||||
emitword (0x3c010000 | (offset >> 16), &relabs, 1);
|
||||
emitword (0x34210000 | (offset & 0xffff), &relabs, 1);
|
||||
}
|
||||
opcode = orig_opcode | 0x10000;
|
||||
}
|
||||
break;
|
||||
case FHIGH16: /* high 16-bit byte address */
|
||||
if (expr_flags & EXPR_HI) {
|
||||
@@ -2351,7 +2392,7 @@ void makeheader (rtsize, rdsize)
|
||||
{
|
||||
struct exec hdr;
|
||||
|
||||
hdr.a_magic = RMAGIC;
|
||||
hdr.a_midmag = RMAGIC;
|
||||
hdr.a_text = count [STEXT];
|
||||
hdr.a_data = count [SDATA] + count [SSTRNG];
|
||||
hdr.a_bss = count [SBSS];
|
||||
|
||||
@@ -26,4 +26,4 @@ clean:
|
||||
install: all
|
||||
install cc $(DESTDIR)/bin/
|
||||
install cc $(DESTDIR)/bin/scc
|
||||
install cc $(DESTDIR)/bin/srcc
|
||||
install cc $(DESTDIR)/bin/lcc
|
||||
|
||||
@@ -449,17 +449,16 @@ main(int argc, char *argv[])
|
||||
pass0 = LIBEXECDIR "/smallc";
|
||||
incdir = STDINC "/smallc";
|
||||
|
||||
} else if (strcmp ("srcc", progname) == 0) {
|
||||
/* Smaller C. */
|
||||
mode = MODE_SMALLERC;
|
||||
cppadd[0] = "-D__SMALLER_C__";
|
||||
pass0 = LIBEXECDIR "/smlrc";
|
||||
incdir = STDINC "/smallerc";
|
||||
} else {
|
||||
} else if (strcmp ("lcc", progname) == 0) {
|
||||
/* LCC: retargetable C compiler. */
|
||||
mode = MODE_LCC;
|
||||
cppadd[0] = "-D__LCC__";
|
||||
pass0 = LIBEXECDIR "/lccom";
|
||||
} else {
|
||||
/* Smaller C. */
|
||||
mode = MODE_SMALLERC;
|
||||
cppadd[0] = "-D__SMALLER_C__";
|
||||
pass0 = LIBEXECDIR "/smlrc";
|
||||
}
|
||||
|
||||
if (argc == 1)
|
||||
|
||||
@@ -24,7 +24,7 @@ $(MAN): ${MANSRC}
|
||||
${MANROFF} $< > $@
|
||||
|
||||
clean:
|
||||
rm -f *.o *.0 *.elf cpp *.elf *.dis tags *~ lex.yy.c y.tab.[ch] tests/run*
|
||||
rm -f *.o *.0 *.elf cpp *.dis tags *~ lex.yy.c y.tab.[ch] tests/run*
|
||||
|
||||
install: all
|
||||
install cpp $(DESTDIR)/bin/
|
||||
@@ -41,23 +41,23 @@ cpy.o y.tab.h: cpy.y
|
||||
$(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c -o cpy.o y.tab.c
|
||||
|
||||
test:
|
||||
./cpp.elf < tests/test1 > tests/run1
|
||||
./cpp < tests/test1 > tests/run1
|
||||
cmp tests/run1 tests/res1
|
||||
./cpp.elf < tests/test2 > tests/run2
|
||||
./cpp < tests/test2 > tests/run2
|
||||
cmp tests/run2 tests/res2
|
||||
./cpp.elf < tests/test3 > tests/run3
|
||||
./cpp < tests/test3 > tests/run3
|
||||
cmp tests/run3 tests/res3
|
||||
./cpp.elf < tests/test4 > tests/run4
|
||||
./cpp < tests/test4 > tests/run4
|
||||
cmp tests/run4 tests/res4
|
||||
./cpp.elf < tests/test5 > tests/run5
|
||||
./cpp < tests/test5 > tests/run5
|
||||
cmp tests/run5 tests/res5
|
||||
./cpp.elf < tests/test6 > tests/run6
|
||||
./cpp < tests/test6 > tests/run6
|
||||
cmp tests/run6 tests/res6
|
||||
./cpp.elf < tests/test7 > tests/run7
|
||||
./cpp < tests/test7 > tests/run7
|
||||
cmp tests/run7 tests/res7
|
||||
./cpp.elf < tests/test8 > tests/run8
|
||||
./cpp < tests/test8 > tests/run8
|
||||
cmp tests/run8 tests/res8
|
||||
./cpp.elf < tests/test9 > tests/run9
|
||||
./cpp < tests/test9 > tests/run9
|
||||
cmp tests/run9 tests/res9
|
||||
./cpp.elf < tests/test10 > tests/run10
|
||||
./cpp < tests/test10 > tests/run10
|
||||
cmp tests/run10 tests/res10
|
||||
|
||||
@@ -350,7 +350,8 @@ addidir(char *idir, struct incs **ww)
|
||||
return;
|
||||
ww = &w->next;
|
||||
}
|
||||
if ((w = calloc(sizeof(struct incs), 1)) == NULL)
|
||||
w = calloc(sizeof(struct incs), 1);
|
||||
if (w == NULL)
|
||||
error("couldn't add path %s", idir);
|
||||
w->dir = (uchar *)idir;
|
||||
w->dev = st.st_dev;
|
||||
@@ -1310,14 +1311,18 @@ expdef(const uchar *vp, struct recur *rp, int gotwarn)
|
||||
int ellips = 0, shot = gotwarn;
|
||||
|
||||
DPRINT(("expdef rp %s\n", (rp ? (const char *)rp->sp->namep : "")));
|
||||
if ((c = sloscan()) != '(')
|
||||
c = sloscan();
|
||||
if (c != '(')
|
||||
error("got %c, expected (", c);
|
||||
|
||||
if (vp[1] == VARG) {
|
||||
narg = *vp--;
|
||||
ellips = 1;
|
||||
} else
|
||||
narg = vp[1];
|
||||
if ((args = malloc(sizeof(uchar *) * (narg+ellips))) == NULL)
|
||||
|
||||
args = malloc(sizeof(uchar *) * (narg+ellips));
|
||||
if (args == NULL)
|
||||
error("expdef: out of mem");
|
||||
|
||||
/*
|
||||
|
||||
@@ -58,7 +58,7 @@ extern int ofd;
|
||||
#define ENTER 1
|
||||
|
||||
/* buffer used internally */
|
||||
#define CPPBUF BUFSIZ
|
||||
#define CPPBUF 512
|
||||
|
||||
#define NAMEMAX CPPBUF /* currently pushbackbuffer */
|
||||
|
||||
@@ -138,13 +138,8 @@ void line(void);
|
||||
uchar *sheap(const char *fmt, ...);
|
||||
void xwarning(uchar *);
|
||||
void xerror(uchar *);
|
||||
#ifdef HAVE_CPP_VARARG_MACRO_GCC
|
||||
#define warning(...) xwarning(sheap(__VA_ARGS__))
|
||||
#define error(...) xerror(sheap(__VA_ARGS__))
|
||||
#else
|
||||
#define warning printf
|
||||
#define error printf
|
||||
#endif
|
||||
#define warning(args...) xwarning(sheap(args))
|
||||
#define error(args...) xerror(sheap(args))
|
||||
void expmac(struct recur *);
|
||||
int cinput(void);
|
||||
void getcmnt(void);
|
||||
|
||||
@@ -1,932 +0,0 @@
|
||||
%{
|
||||
/*
|
||||
* Copyright (c) 2004 Anders Magnusson. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "compat.h"
|
||||
#include "cpp.h"
|
||||
#include "y.tab.h"
|
||||
%}
|
||||
|
||||
%{
|
||||
static void cvtdig(int rad);
|
||||
static int charcon(uchar *);
|
||||
static void elsestmt(void);
|
||||
static void ifdefstmt(void);
|
||||
static void ifndefstmt(void);
|
||||
static void endifstmt(void);
|
||||
static void ifstmt(void);
|
||||
static void cpperror(void);
|
||||
static void pragmastmt(void);
|
||||
static void undefstmt(void);
|
||||
static void cpperror(void);
|
||||
static void elifstmt(void);
|
||||
static void storepb(void);
|
||||
static void badop(const char *);
|
||||
void include(void);
|
||||
void define(void);
|
||||
|
||||
extern int yyget_lineno (void);
|
||||
extern void yyset_lineno (int);
|
||||
|
||||
static int inch(void);
|
||||
|
||||
static int scale, gotdef, contr;
|
||||
int inif;
|
||||
|
||||
#ifdef FLEX_SCANNER /* should be set by autoconf instead */
|
||||
static int
|
||||
yyinput(char *b, int m)
|
||||
{
|
||||
int c, i;
|
||||
|
||||
for (i = 0; i < m; i++) {
|
||||
if ((c = inch()) < 0)
|
||||
break;
|
||||
*b++ = c;
|
||||
if (c == '\n') {
|
||||
i++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
#undef YY_INPUT
|
||||
#undef YY_BUF_SIZE
|
||||
#define YY_BUF_SIZE (8*65536)
|
||||
#define YY_INPUT(b,r,m) (r = yyinput(b, m))
|
||||
#ifdef HAVE_CPP_VARARG_MACRO_GCC
|
||||
#define fprintf(x, ...) error(__VA_ARGS__)
|
||||
#endif
|
||||
#define ECHO putstr((uchar *)yytext)
|
||||
#undef fileno
|
||||
#define fileno(x) 0
|
||||
|
||||
#if YY_FLEX_SUBMINOR_VERSION >= 31
|
||||
/* Hack to avoid unnecessary warnings */
|
||||
FILE *yyget_in (void);
|
||||
FILE *yyget_out (void);
|
||||
int yyget_leng (void);
|
||||
char *yyget_text (void);
|
||||
void yyset_in (FILE * in_str );
|
||||
void yyset_out (FILE * out_str );
|
||||
int yyget_debug (void);
|
||||
void yyset_debug (int bdebug );
|
||||
int yylex_destroy (void);
|
||||
#endif
|
||||
#else /* Assume lex here */
|
||||
#undef input
|
||||
#undef unput
|
||||
#define input() inch()
|
||||
#define unput(ch) unch(ch)
|
||||
#endif
|
||||
#define PRTOUT(x) if (YYSTATE || slow) return x; if (!flslvl) putstr((uchar *)yytext);
|
||||
/* protection against recursion in #include */
|
||||
#define MAX_INCLEVEL 100
|
||||
static int inclevel;
|
||||
%}
|
||||
|
||||
D [0-9]
|
||||
L [a-zA-Z_]
|
||||
H [a-fA-F0-9]
|
||||
E [Ee][+-]?{D}+
|
||||
FS (f|F|l|L)
|
||||
IS (u|U|l|L)*
|
||||
WS [\t ]
|
||||
|
||||
%s IFR CONTR DEF COMMENT
|
||||
|
||||
%%
|
||||
|
||||
"\n" { int os = YYSTATE;
|
||||
if (os != IFR)
|
||||
BEGIN 0;
|
||||
ifiles->lineno++;
|
||||
if (flslvl == 0) {
|
||||
if (ifiles->lineno == 1)
|
||||
prtline();
|
||||
else
|
||||
putch('\n');
|
||||
}
|
||||
if ((os != 0 || slow) && !contr)
|
||||
return '\n';
|
||||
contr = 0;
|
||||
}
|
||||
|
||||
"\r" { ; /* Ignore CR's */ }
|
||||
|
||||
<IFR>"++" { badop("++"); }
|
||||
<IFR>"--" { badop("--"); }
|
||||
<IFR>"==" { return EQ; }
|
||||
<IFR>"!=" { return NE; }
|
||||
<IFR>"<=" { return LE; }
|
||||
<IFR>"<<" { return LS; }
|
||||
<IFR>">>" { return RS; }
|
||||
<IFR>">=" { return GE; }
|
||||
<IFR>"||" { return OROR; }
|
||||
<IFR>"&&" { return ANDAND; }
|
||||
<IFR>"defined" { int p, c;
|
||||
gotdef = 1;
|
||||
if ((p = c = yylex()) == '(')
|
||||
c = yylex();
|
||||
if (c != IDENT || (p != IDENT && p != '('))
|
||||
error("syntax error");
|
||||
if (p == '(' && yylex() != ')')
|
||||
error("syntax error");
|
||||
return NUMBER;
|
||||
}
|
||||
|
||||
<IFR>{WS}+ { ; }
|
||||
<IFR>{L}({L}|{D})* {
|
||||
yylval.node.op = NUMBER;
|
||||
if (gotdef) {
|
||||
yylval.node.nd_val
|
||||
= lookup((uchar *)yytext, FIND) != 0;
|
||||
gotdef = 0;
|
||||
return IDENT;
|
||||
}
|
||||
yylval.node.nd_val = 0;
|
||||
return NUMBER;
|
||||
}
|
||||
|
||||
[0-9][0-9]* {
|
||||
if (slow && !YYSTATE)
|
||||
return IDENT;
|
||||
scale = yytext[0] == '0' ? 8 : 10;
|
||||
goto num;
|
||||
}
|
||||
|
||||
0[xX]{H}+{IS}? { scale = 16;
|
||||
num: if (YYSTATE == IFR)
|
||||
cvtdig(scale);
|
||||
PRTOUT(NUMBER);
|
||||
}
|
||||
0{D}+{IS}? { scale = 8; goto num; }
|
||||
{D}+{IS}? { scale = 10; goto num; }
|
||||
'(\\.|[^\\'])+' {
|
||||
if (YYSTATE || slow) {
|
||||
yylval.node.op = NUMBER;
|
||||
yylval.node.nd_val = charcon((uchar *)yytext);
|
||||
return (NUMBER);
|
||||
}
|
||||
if (tflag)
|
||||
yyless(1);
|
||||
if (!flslvl)
|
||||
putstr((uchar *)yytext);
|
||||
}
|
||||
|
||||
<IFR>. { return yytext[0]; }
|
||||
|
||||
{D}+{E}{FS}? { PRTOUT(FPOINT); }
|
||||
{D}*"."{D}+({E})?{FS}? { PRTOUT(FPOINT); }
|
||||
{D}+"."{D}*({E})?{FS}? { PRTOUT(FPOINT); }
|
||||
|
||||
^{WS}*#{WS}* { extern int inmac;
|
||||
|
||||
if (inmac)
|
||||
error("preprocessor directive found "
|
||||
"while expanding macro");
|
||||
contr = 1;
|
||||
BEGIN CONTR;
|
||||
}
|
||||
{WS}+ { PRTOUT(WSPACE); }
|
||||
|
||||
<CONTR>"ifndef" { contr = 0; ifndefstmt(); }
|
||||
<CONTR>"ifdef" { contr = 0; ifdefstmt(); }
|
||||
<CONTR>"if" { contr = 0; storepb(); BEGIN IFR; ifstmt(); BEGIN 0; }
|
||||
<CONTR>"include" { contr = 0; BEGIN 0; include(); prtline(); }
|
||||
<CONTR>"else" { contr = 0; elsestmt(); }
|
||||
<CONTR>"endif" { contr = 0; endifstmt(); }
|
||||
<CONTR>"error" { contr = 0; if (slow) return IDENT; cpperror(); BEGIN 0; }
|
||||
<CONTR>"define" { contr = 0; BEGIN DEF; define(); BEGIN 0; }
|
||||
<CONTR>"undef" { contr = 0; if (slow) return IDENT; undefstmt(); }
|
||||
<CONTR>"line" { contr = 0; storepb(); BEGIN 0; line(); }
|
||||
<CONTR>"pragma" { contr = 0; pragmastmt(); BEGIN 0; }
|
||||
<CONTR>"elif" { contr = 0; storepb(); BEGIN IFR; elifstmt(); BEGIN 0; }
|
||||
|
||||
|
||||
|
||||
"//".*$ { /* if (tflag) yyless(..) */
|
||||
if (Cflag && !flslvl && !slow)
|
||||
putstr((uchar *)yytext);
|
||||
else if (!flslvl)
|
||||
putch(' ');
|
||||
}
|
||||
"/*" { int c, wrn;
|
||||
int prtcm = Cflag && !flslvl && !slow;
|
||||
extern int readmac;
|
||||
|
||||
if (Cflag && !flslvl && readmac)
|
||||
return CMNT;
|
||||
|
||||
if (prtcm)
|
||||
putstr((uchar *)yytext);
|
||||
wrn = 0;
|
||||
more: while ((c = input()) && c != '*') {
|
||||
if (c == '\n')
|
||||
putch(c), ifiles->lineno++;
|
||||
else if (c == 1) /* WARN */
|
||||
wrn = 1;
|
||||
else if (prtcm)
|
||||
putch(c);
|
||||
}
|
||||
if (c == 0)
|
||||
return 0;
|
||||
if (prtcm)
|
||||
putch(c);
|
||||
if ((c = input()) && c != '/') {
|
||||
unput(c);
|
||||
goto more;
|
||||
}
|
||||
if (prtcm)
|
||||
putch(c);
|
||||
if (c == 0)
|
||||
return 0;
|
||||
if (!tflag && !Cflag && !flslvl)
|
||||
unput(' ');
|
||||
if (wrn)
|
||||
unput(1);
|
||||
}
|
||||
|
||||
<DEF>"##" { return CONCAT; }
|
||||
<DEF>"#" { return MKSTR; }
|
||||
<DEF>"..." { return ELLIPS; }
|
||||
<DEF>"__VA_ARGS__" { return VA_ARGS; }
|
||||
|
||||
L?\"(\\.|[^\\"])*\" { PRTOUT(STRING); }
|
||||
[a-zA-Z_0-9]+ { /* {L}({L}|{D})* */
|
||||
struct symtab *nl;
|
||||
if (slow)
|
||||
return IDENT;
|
||||
if (YYSTATE == CONTR) {
|
||||
if (flslvl == 0) {
|
||||
/*error("undefined control");*/
|
||||
while (input() != '\n')
|
||||
;
|
||||
unput('\n');
|
||||
BEGIN 0;
|
||||
goto xx;
|
||||
} else {
|
||||
BEGIN 0; /* do nothing */
|
||||
}
|
||||
}
|
||||
if (flslvl) {
|
||||
; /* do nothing */
|
||||
} else if (isdigit((int)yytext[0]) == 0 &&
|
||||
(nl = lookup((uchar *)yytext, FIND)) != 0) {
|
||||
uchar *op = stringbuf;
|
||||
putstr(gotident(nl));
|
||||
stringbuf = op;
|
||||
} else
|
||||
putstr((uchar *)yytext);
|
||||
xx: ;
|
||||
}
|
||||
|
||||
. {
|
||||
if (contr) {
|
||||
while (input() != '\n')
|
||||
;
|
||||
unput('\n');
|
||||
BEGIN 0;
|
||||
contr = 0;
|
||||
goto yy;
|
||||
}
|
||||
if (YYSTATE || slow)
|
||||
return yytext[0];
|
||||
if (yytext[0] == 6) { /* PRAGS */
|
||||
uchar *obp = stringbuf;
|
||||
extern uchar *prtprag(uchar *);
|
||||
*stringbuf++ = yytext[0];
|
||||
do {
|
||||
*stringbuf = input();
|
||||
} while (*stringbuf++ != 14);
|
||||
prtprag(obp);
|
||||
stringbuf = obp;
|
||||
} else {
|
||||
PRTOUT(yytext[0]);
|
||||
}
|
||||
yy:;
|
||||
}
|
||||
|
||||
%%
|
||||
|
||||
uchar *yyp, yybuf[CPPBUF];
|
||||
|
||||
int yylex(void);
|
||||
int yywrap(void);
|
||||
|
||||
static int
|
||||
inpch(void)
|
||||
{
|
||||
int len;
|
||||
|
||||
if (ifiles->curptr < ifiles->maxread)
|
||||
return *ifiles->curptr++;
|
||||
|
||||
if ((len = read(ifiles->infil, ifiles->buffer, CPPBUF)) < 0)
|
||||
error("read error on file %s", ifiles->orgfn);
|
||||
if (len == 0)
|
||||
return -1;
|
||||
ifiles->curptr = ifiles->buffer;
|
||||
ifiles->maxread = ifiles->buffer + len;
|
||||
return inpch();
|
||||
}
|
||||
|
||||
#define unch(c) *--ifiles->curptr = c
|
||||
|
||||
static int
|
||||
inch(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
again: switch (c = inpch()) {
|
||||
case '\\': /* continued lines */
|
||||
msdos: if ((c = inpch()) == '\n') {
|
||||
ifiles->lineno++;
|
||||
putch('\n');
|
||||
goto again;
|
||||
} else if (c == '\r')
|
||||
goto msdos;
|
||||
unch(c);
|
||||
return '\\';
|
||||
case '?': /* trigraphs */
|
||||
if ((c = inpch()) != '?') {
|
||||
unch(c);
|
||||
return '?';
|
||||
}
|
||||
switch (c = inpch()) {
|
||||
case '=': c = '#'; break;
|
||||
case '(': c = '['; break;
|
||||
case ')': c = ']'; break;
|
||||
case '<': c = '{'; break;
|
||||
case '>': c = '}'; break;
|
||||
case '/': c = '\\'; break;
|
||||
case '\'': c = '^'; break;
|
||||
case '!': c = '|'; break;
|
||||
case '-': c = '~'; break;
|
||||
default:
|
||||
unch(c);
|
||||
unch('?');
|
||||
return '?';
|
||||
}
|
||||
unch(c);
|
||||
goto again;
|
||||
default:
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Let the command-line args be faked defines at beginning of file.
|
||||
*/
|
||||
static void
|
||||
prinit(struct initar *it, struct includ *ic)
|
||||
{
|
||||
char *a, *pre, *post;
|
||||
|
||||
if (it->next)
|
||||
prinit(it->next, ic);
|
||||
pre = post = NULL; /* XXX gcc */
|
||||
switch (it->type) {
|
||||
case 'D':
|
||||
pre = "#define ";
|
||||
if ((a = strchr(it->str, '=')) != NULL) {
|
||||
*a = ' ';
|
||||
post = "\n";
|
||||
} else
|
||||
post = " 1\n";
|
||||
break;
|
||||
case 'U':
|
||||
pre = "#undef ";
|
||||
post = "\n";
|
||||
break;
|
||||
case 'i':
|
||||
pre = "#include \"";
|
||||
post = "\"\n";
|
||||
break;
|
||||
default:
|
||||
error("prinit");
|
||||
}
|
||||
strlcat((char *)ic->buffer, pre, CPPBUF+1);
|
||||
strlcat((char *)ic->buffer, it->str, CPPBUF+1);
|
||||
if (strlcat((char *)ic->buffer, post, CPPBUF+1) >= CPPBUF+1)
|
||||
error("line exceeds buffer size");
|
||||
|
||||
ic->lineno--;
|
||||
while (*ic->maxread)
|
||||
ic->maxread++;
|
||||
}
|
||||
|
||||
/*
|
||||
* A new file included.
|
||||
* If ifiles == NULL, this is the first file and already opened (stdin).
|
||||
* Return 0 on success, -1 if file to be included is not found.
|
||||
*/
|
||||
int
|
||||
pushfile(uchar *file)
|
||||
{
|
||||
extern struct initar *initar;
|
||||
struct includ ibuf;
|
||||
struct includ *ic;
|
||||
int c, otrulvl;
|
||||
|
||||
ic = &ibuf;
|
||||
ic->next = ifiles;
|
||||
|
||||
slow = 0;
|
||||
if (file != NULL) {
|
||||
if ((ic->infil = open((char *)file, O_RDONLY)) < 0)
|
||||
return -1;
|
||||
ic->orgfn = ic->fname = file;
|
||||
if (++inclevel > MAX_INCLEVEL)
|
||||
error("Limit for nested includes exceeded");
|
||||
} else {
|
||||
ic->infil = 0;
|
||||
ic->orgfn = ic->fname = (uchar *)"<stdin>";
|
||||
}
|
||||
ic->buffer = ic->bbuf+NAMEMAX;
|
||||
ic->curptr = ic->buffer;
|
||||
ifiles = ic;
|
||||
ic->lineno = 1;
|
||||
ic->maxread = ic->curptr;
|
||||
prtline();
|
||||
if (initar) {
|
||||
*ic->maxread = 0;
|
||||
prinit(initar, ic);
|
||||
if (dMflag)
|
||||
write(ofd, ic->buffer, strlen((char *)ic->buffer));
|
||||
initar = NULL;
|
||||
}
|
||||
|
||||
otrulvl = trulvl;
|
||||
|
||||
if ((c = yylex()) != 0)
|
||||
error("yylex returned %d", c);
|
||||
|
||||
if (otrulvl != trulvl || flslvl)
|
||||
error("unterminated conditional");
|
||||
|
||||
ifiles = ic->next;
|
||||
close(ic->infil);
|
||||
inclevel--;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Print current position to output file.
|
||||
*/
|
||||
void
|
||||
prtline()
|
||||
{
|
||||
uchar *s, *os = stringbuf;
|
||||
|
||||
if (Mflag) {
|
||||
if (dMflag)
|
||||
return; /* no output */
|
||||
if (ifiles->lineno == 1) {
|
||||
s = sheap("%s: %s\n", Mfile, ifiles->fname);
|
||||
write(ofd, s, strlen((char *)s));
|
||||
}
|
||||
} else if (!Pflag)
|
||||
putstr(sheap("# %d \"%s\"\n", ifiles->lineno, ifiles->fname));
|
||||
stringbuf = os;
|
||||
}
|
||||
|
||||
void
|
||||
cunput(int c)
|
||||
{
|
||||
#ifdef CPP_DEBUG
|
||||
extern int dflag;
|
||||
if (dflag)printf(": '%c'(%d)", c > 31 ? c : ' ', c);
|
||||
#endif
|
||||
unput(c);
|
||||
}
|
||||
|
||||
int yywrap(void) { return 1; }
|
||||
|
||||
static int
|
||||
dig2num(int c)
|
||||
{
|
||||
if (c >= 'a')
|
||||
c = c - 'a' + 10;
|
||||
else if (c >= 'A')
|
||||
c = c - 'A' + 10;
|
||||
else
|
||||
c = c - '0';
|
||||
return c;
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert string numbers to unsigned long long and check overflow.
|
||||
*/
|
||||
static void
|
||||
cvtdig(int rad)
|
||||
{
|
||||
unsigned long long rv = 0;
|
||||
unsigned long long rv2 = 0;
|
||||
char *y = yytext;
|
||||
int c;
|
||||
|
||||
c = *y++;
|
||||
if (rad == 16)
|
||||
y++;
|
||||
while (isxdigit(c)) {
|
||||
rv = rv * rad + dig2num(c);
|
||||
/* check overflow */
|
||||
if (rv / rad < rv2)
|
||||
error("Constant \"%s\" is out of range", yytext);
|
||||
rv2 = rv;
|
||||
c = *y++;
|
||||
}
|
||||
y--;
|
||||
while (*y == 'l' || *y == 'L')
|
||||
y++;
|
||||
yylval.node.op = *y == 'u' || *y == 'U' ? UNUMBER : NUMBER;
|
||||
yylval.node.nd_uval = rv;
|
||||
if ((rad == 8 || rad == 16) && yylval.node.nd_val < 0)
|
||||
yylval.node.op = UNUMBER;
|
||||
if (yylval.node.op == NUMBER && yylval.node.nd_val < 0)
|
||||
/* too large for signed */
|
||||
error("Constant \"%s\" is out of range", yytext);
|
||||
}
|
||||
|
||||
static int
|
||||
charcon(uchar *p)
|
||||
{
|
||||
int val, c;
|
||||
|
||||
p++; /* skip first ' */
|
||||
val = 0;
|
||||
if (*p++ == '\\') {
|
||||
switch (*p++) {
|
||||
case 'a': val = '\a'; break;
|
||||
case 'b': val = '\b'; break;
|
||||
case 'f': val = '\f'; break;
|
||||
case 'n': val = '\n'; break;
|
||||
case 'r': val = '\r'; break;
|
||||
case 't': val = '\t'; break;
|
||||
case 'v': val = '\v'; break;
|
||||
case '\"': val = '\"'; break;
|
||||
case '\'': val = '\''; break;
|
||||
case '\\': val = '\\'; break;
|
||||
case 'x':
|
||||
while (isxdigit(c = *p)) {
|
||||
val = val * 16 + dig2num(c);
|
||||
p++;
|
||||
}
|
||||
break;
|
||||
case '0': case '1': case '2': case '3': case '4':
|
||||
case '5': case '6': case '7':
|
||||
p--;
|
||||
while (isdigit(c = *p)) {
|
||||
val = val * 8 + (c - '0');
|
||||
p++;
|
||||
}
|
||||
break;
|
||||
default: val = p[-1];
|
||||
}
|
||||
|
||||
} else
|
||||
val = p[-1];
|
||||
return val;
|
||||
}
|
||||
|
||||
static void
|
||||
chknl(int ignore)
|
||||
{
|
||||
int t;
|
||||
|
||||
slow = 1;
|
||||
while ((t = yylex()) == WSPACE)
|
||||
;
|
||||
if (t != '\n') {
|
||||
if (ignore) {
|
||||
warning("newline expected, got \"%s\"", yytext);
|
||||
/* ignore rest of line */
|
||||
while ((t = yylex()) && t != '\n')
|
||||
;
|
||||
}
|
||||
else
|
||||
error("newline expected, got \"%s\"", yytext);
|
||||
}
|
||||
slow = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
elsestmt(void)
|
||||
{
|
||||
if (flslvl) {
|
||||
if (elflvl > trulvl)
|
||||
;
|
||||
else if (--flslvl!=0) {
|
||||
flslvl++;
|
||||
} else {
|
||||
trulvl++;
|
||||
prtline();
|
||||
}
|
||||
} else if (trulvl) {
|
||||
flslvl++;
|
||||
trulvl--;
|
||||
} else
|
||||
error("If-less else");
|
||||
if (elslvl==trulvl+flslvl)
|
||||
error("Too many else");
|
||||
elslvl=trulvl+flslvl;
|
||||
chknl(1);
|
||||
}
|
||||
|
||||
static void
|
||||
ifdefstmt(void)
|
||||
{
|
||||
int t;
|
||||
|
||||
if (flslvl) {
|
||||
/* just ignore the rest of the line */
|
||||
while (input() != '\n')
|
||||
;
|
||||
unput('\n');
|
||||
yylex();
|
||||
flslvl++;
|
||||
return;
|
||||
}
|
||||
slow = 1;
|
||||
do
|
||||
t = yylex();
|
||||
while (t == WSPACE);
|
||||
if (t != IDENT)
|
||||
error("bad ifdef");
|
||||
slow = 0;
|
||||
if (flslvl == 0 && lookup((uchar *)yytext, FIND) != 0)
|
||||
trulvl++;
|
||||
else
|
||||
flslvl++;
|
||||
chknl(0);
|
||||
}
|
||||
|
||||
static void
|
||||
ifndefstmt(void)
|
||||
{
|
||||
int t;
|
||||
|
||||
slow = 1;
|
||||
do
|
||||
t = yylex();
|
||||
while (t == WSPACE);
|
||||
if (t != IDENT)
|
||||
error("bad ifndef");
|
||||
slow = 0;
|
||||
if (flslvl == 0 && lookup((uchar *)yytext, FIND) == 0)
|
||||
trulvl++;
|
||||
else
|
||||
flslvl++;
|
||||
chknl(0);
|
||||
}
|
||||
|
||||
static void
|
||||
endifstmt(void)
|
||||
{
|
||||
if (flslvl) {
|
||||
flslvl--;
|
||||
if (flslvl == 0)
|
||||
prtline();
|
||||
} else if (trulvl)
|
||||
trulvl--;
|
||||
else
|
||||
error("If-less endif");
|
||||
if (flslvl == 0)
|
||||
elflvl = 0;
|
||||
elslvl = 0;
|
||||
chknl(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note! Ugly!
|
||||
* Walk over the string s and search for defined, and replace it with
|
||||
* spaces and a 1 or 0.
|
||||
*/
|
||||
static void
|
||||
fixdefined(uchar *s)
|
||||
{
|
||||
uchar *bc, oc;
|
||||
|
||||
for (; *s; s++) {
|
||||
if (*s != 'd')
|
||||
continue;
|
||||
if (memcmp(s, "defined", 7))
|
||||
continue;
|
||||
/* Ok, got defined, can scratch it now */
|
||||
memset(s, ' ', 7);
|
||||
s += 7;
|
||||
#define WSARG(x) (x == ' ' || x == '\t')
|
||||
if (*s != '(' && !WSARG(*s))
|
||||
continue;
|
||||
while (WSARG(*s))
|
||||
s++;
|
||||
if (*s == '(')
|
||||
s++;
|
||||
while (WSARG(*s))
|
||||
s++;
|
||||
#define IDARG(x) ((x>= 'A' && x <= 'Z') || (x >= 'a' && x <= 'z') || (x == '_'))
|
||||
#define NUMARG(x) (x >= '0' && x <= '9')
|
||||
if (!IDARG(*s))
|
||||
error("bad defined arg");
|
||||
bc = s;
|
||||
while (IDARG(*s) || NUMARG(*s))
|
||||
s++;
|
||||
oc = *s;
|
||||
*s = 0;
|
||||
*bc = (lookup(bc, FIND) != 0) + '0';
|
||||
memset(bc+1, ' ', s-bc-1);
|
||||
*s = oc;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* get the full line of identifiers after an #if, pushback a WARN and
|
||||
* the line and prepare for expmac() to expand.
|
||||
* This is done before switching state. When expmac is finished,
|
||||
* pushback the expanded line, change state and call yyparse.
|
||||
*/
|
||||
static void
|
||||
storepb(void)
|
||||
{
|
||||
uchar *opb = stringbuf;
|
||||
int c;
|
||||
|
||||
while ((c = input()) != '\n') {
|
||||
if (c == '/') {
|
||||
if ((c = input()) == '*') {
|
||||
/* ignore comments here whatsoever */
|
||||
uchar *g = stringbuf;
|
||||
getcmnt();
|
||||
stringbuf = g;
|
||||
continue;
|
||||
} else if (c == '/') {
|
||||
while ((c = input()) && c != '\n')
|
||||
;
|
||||
break;
|
||||
}
|
||||
unput(c);
|
||||
c = '/';
|
||||
}
|
||||
savch(c);
|
||||
}
|
||||
cunput('\n');
|
||||
savch(0);
|
||||
fixdefined(opb); /* XXX can fail if #line? */
|
||||
cunput(1); /* WARN XXX */
|
||||
unpstr(opb);
|
||||
stringbuf = opb;
|
||||
slow = 1;
|
||||
expmac(NULL);
|
||||
slow = 0;
|
||||
/* line now expanded */
|
||||
while (stringbuf > opb)
|
||||
cunput(*--stringbuf);
|
||||
}
|
||||
|
||||
static void
|
||||
ifstmt(void)
|
||||
{
|
||||
if (flslvl == 0) {
|
||||
slow = 1;
|
||||
if (yyparse())
|
||||
++trulvl;
|
||||
else
|
||||
++flslvl;
|
||||
slow = 0;
|
||||
} else
|
||||
++flslvl;
|
||||
}
|
||||
|
||||
static void
|
||||
elifstmt(void)
|
||||
{
|
||||
if (flslvl == 0)
|
||||
elflvl = trulvl;
|
||||
if (flslvl) {
|
||||
if (elflvl > trulvl)
|
||||
;
|
||||
else if (--flslvl!=0)
|
||||
++flslvl;
|
||||
else {
|
||||
slow = 1;
|
||||
if (yyparse()) {
|
||||
++trulvl;
|
||||
prtline();
|
||||
} else
|
||||
++flslvl;
|
||||
slow = 0;
|
||||
}
|
||||
} else if (trulvl) {
|
||||
++flslvl;
|
||||
--trulvl;
|
||||
} else
|
||||
error("If-less elif");
|
||||
}
|
||||
|
||||
static uchar *
|
||||
svinp(void)
|
||||
{
|
||||
int c;
|
||||
uchar *cp = stringbuf;
|
||||
|
||||
while ((c = input()) && c != '\n')
|
||||
savch(c);
|
||||
savch('\n');
|
||||
savch(0);
|
||||
BEGIN 0;
|
||||
return cp;
|
||||
}
|
||||
|
||||
static void
|
||||
cpperror(void)
|
||||
{
|
||||
uchar *cp;
|
||||
int c;
|
||||
|
||||
if (flslvl)
|
||||
return;
|
||||
c = yylex();
|
||||
if (c != WSPACE && c != '\n')
|
||||
error("bad error");
|
||||
cp = svinp();
|
||||
if (flslvl)
|
||||
stringbuf = cp;
|
||||
else
|
||||
error("%s", cp);
|
||||
}
|
||||
|
||||
static void
|
||||
undefstmt(void)
|
||||
{
|
||||
struct symtab *np;
|
||||
|
||||
slow = 1;
|
||||
if (yylex() != WSPACE || yylex() != IDENT)
|
||||
error("bad undef");
|
||||
if (flslvl == 0 && (np = lookup((uchar *)yytext, FIND)))
|
||||
np->value = 0;
|
||||
slow = 0;
|
||||
chknl(0);
|
||||
}
|
||||
|
||||
static void
|
||||
pragmastmt(void)
|
||||
{
|
||||
int c;
|
||||
|
||||
slow = 1;
|
||||
if (yylex() != WSPACE)
|
||||
error("bad pragma");
|
||||
if (!flslvl)
|
||||
putstr((uchar *)"#pragma ");
|
||||
do {
|
||||
c = input();
|
||||
if (!flslvl)
|
||||
putch(c); /* Do arg expansion instead? */
|
||||
} while (c && c != '\n');
|
||||
ifiles->lineno++;
|
||||
prtline();
|
||||
slow = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
badop(const char *op)
|
||||
{
|
||||
error("invalid operator in preprocessor expression: %s", op);
|
||||
}
|
||||
|
||||
int
|
||||
cinput()
|
||||
{
|
||||
return input();
|
||||
}
|
||||
@@ -767,8 +767,10 @@ pushfile(const uchar *file, const uchar *fn, int idx, void *incs)
|
||||
|
||||
if (file != NULL) {
|
||||
ic->infil = open((const char *)file, O_RDONLY);
|
||||
if (ic->infil < 0)
|
||||
if (ic->infil < 0) {
|
||||
free(ic);
|
||||
return -1;
|
||||
}
|
||||
ic->orgfn = ic->fname = file;
|
||||
if (++inclevel > MAX_INCLEVEL)
|
||||
error("Limit for nested includes exceeded");
|
||||
|
||||
@@ -172,7 +172,7 @@ int fgethdr (text, h)
|
||||
register FILE *text;
|
||||
register struct exec *h;
|
||||
{
|
||||
h->a_magic = fgetword (text);
|
||||
h->a_midmag = fgetword (text);
|
||||
h->a_text = fgetword (text);
|
||||
h->a_data = fgetword (text);
|
||||
h->a_bss = fgetword (text);
|
||||
@@ -860,7 +860,7 @@ void readhdr (loc)
|
||||
fseek (text, loc, 0);
|
||||
if (! fgethdr (text, &filhdr))
|
||||
error (2, "bad format");
|
||||
if (filhdr.a_magic != RMAGIC)
|
||||
if (N_GETMAGIC(filhdr) != RMAGIC)
|
||||
error (2, "bad magic");
|
||||
if (filhdr.a_text % W)
|
||||
error (2, "bad length of text");
|
||||
@@ -880,7 +880,7 @@ int load1 (loc, libflg, nloc)
|
||||
int savindex, ndef, type, symlen, nsymbol;
|
||||
|
||||
readhdr (loc);
|
||||
if (filhdr.a_magic != RMAGIC) {
|
||||
if (N_GETMAGIC(filhdr) != RMAGIC) {
|
||||
error (1, "file not relocatable");
|
||||
return (0);
|
||||
}
|
||||
@@ -1293,7 +1293,7 @@ void setupout ()
|
||||
} else {
|
||||
close(fd);
|
||||
}
|
||||
|
||||
|
||||
tcreat (&toutb, 1);
|
||||
tcreat (&doutb, 1);
|
||||
|
||||
@@ -1494,7 +1494,7 @@ void finishout ()
|
||||
while (ssize++ % W)
|
||||
putc (0, outb);
|
||||
}
|
||||
filhdr.a_magic = output_relinfo ? RMAGIC : OMAGIC;
|
||||
filhdr.a_midmag = output_relinfo ? RMAGIC : OMAGIC;
|
||||
filhdr.a_text = tsize;
|
||||
filhdr.a_data = dsize;
|
||||
filhdr.a_bss = bsize;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
TOPSRC = $(shell cd ../../..; pwd)
|
||||
include $(TOPSRC)/target.mk
|
||||
#include $(TOPSRC)/cross.mk
|
||||
|
||||
CFLAGS = -Os -Wall -DMIPS -DNO_ANNOTATIONS -DNO_PREPROCESSOR \
|
||||
-DNO_PPACK -D_RETROBSD -D__SMALLER_C_SCHAR__ \
|
||||
-D__SMALLER_C__ -D__SMALLER_C_32__
|
||||
|
||||
# For cross compile
|
||||
#include $(TOPSRC)/cross.mk
|
||||
#CFLAGS = -Os -Wall -DMIPS -m32
|
||||
#LDFLAGS = -m32
|
||||
|
||||
|
||||
@@ -3,13 +3,13 @@ Copyright (c) 2012-2014, Alexey Frunze
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
@@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
@@ -63,6 +63,10 @@ int GenInitParams(int argc, char** argv, int* idx)
|
||||
UseGp = 1;
|
||||
return 1;
|
||||
}
|
||||
else if (!strcmp(argv[*idx], "-v"))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -131,15 +135,19 @@ void GenStartAsciiString(void)
|
||||
printf2("\t.ascii\t");
|
||||
}
|
||||
|
||||
void GenAddrData(int Size, char* Label)
|
||||
void GenAddrData(int Size, char* Label, int ofs)
|
||||
{
|
||||
ofs = truncInt(ofs);
|
||||
if (Size == 1)
|
||||
printf2("\t.byte\t");
|
||||
else if (Size == 2)
|
||||
printf2("\t.half\t");
|
||||
else if (Size == 4)
|
||||
printf2("\t.word\t");
|
||||
GenPrintLabel(Label); puts2("");
|
||||
GenPrintLabel(Label);
|
||||
if (ofs)
|
||||
printf2(" %+d", ofs);
|
||||
puts2("");
|
||||
}
|
||||
|
||||
#define MipsInstrNop 0x00
|
||||
|
||||
@@ -3,13 +3,13 @@ Copyright (c) 2012-2014, Alexey Frunze
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
@@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
@@ -237,8 +237,9 @@ void GenStartAsciiString(void)
|
||||
printf2("\tdb\t");
|
||||
}
|
||||
|
||||
void GenAddrData(int Size, char* Label)
|
||||
void GenAddrData(int Size, char* Label, int ofs)
|
||||
{
|
||||
ofs = truncInt(ofs);
|
||||
#ifdef CAN_COMPILE_32BIT
|
||||
if (OutputFormat == FormatSegHuge)
|
||||
{
|
||||
@@ -256,7 +257,10 @@ void GenAddrData(int Size, char* Label)
|
||||
else if (Size == 4)
|
||||
printf2("\tdd\t");
|
||||
#endif
|
||||
GenPrintLabel(Label); puts2("");
|
||||
GenPrintLabel(Label);
|
||||
if (ofs)
|
||||
printf2(" %+d", ofs);
|
||||
puts2("");
|
||||
if (!isdigit(*Label))
|
||||
GenAddGlobal(Label, 2);
|
||||
}
|
||||
|
||||
@@ -3,13 +3,13 @@ Copyright (c) 2012-2014, Alexey Frunze
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
@@ -23,7 +23,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
The views and conclusions contained in the software and documentation are those
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
of the authors and should not be interpreted as representing official policies,
|
||||
either expressed or implied, of the FreeBSD Project.
|
||||
*/
|
||||
|
||||
@@ -331,13 +331,6 @@ int truncInt(int);
|
||||
int GetToken(void);
|
||||
char* GetTokenName(int token);
|
||||
|
||||
int GetTokenValueInt(void);
|
||||
|
||||
char* GetTokenValueString(void);
|
||||
int GetTokenValueStringLength(void);
|
||||
|
||||
char* GetTokenIdentName(void);
|
||||
|
||||
#ifndef NO_PREPROCESSOR
|
||||
#ifndef NO_ANNOTATIONS
|
||||
void DumpMacroTable(void);
|
||||
@@ -366,7 +359,7 @@ void GenNumLabel(int Label);
|
||||
void GenZeroData(unsigned Size);
|
||||
void GenIntData(int Size, int Val);
|
||||
void GenStartAsciiString(void);
|
||||
void GenAddrData(int Size, char* Label);
|
||||
void GenAddrData(int Size, char* Label, int ofs);
|
||||
|
||||
void GenJumpUncond(int Label);
|
||||
void GenJumpIfZero(int Label);
|
||||
@@ -577,8 +570,19 @@ int CurFxnNameLabel = 0;
|
||||
int ParseLevel = 0; // Parse level/scope (file:0, fxn:1+)
|
||||
int ParamLevel = 0; // 1+ if parsing params, 0 otherwise
|
||||
|
||||
int SyntaxStack[SYNTAX_STACK_MAX][2];
|
||||
int SyntaxStackCnt = 0;
|
||||
int SyntaxStack[SYNTAX_STACK_MAX][2] =
|
||||
{
|
||||
{ tokVoid }, // SymVoidSynPtr
|
||||
{ tokInt }, // SymIntSynPtr
|
||||
{ tokUnsigned }, // SymUintSynPtr
|
||||
{ tokIdent }, // SymFuncPtr
|
||||
{ '[' },
|
||||
{ tokNumUint },
|
||||
{ ']' },
|
||||
{ tokChar }
|
||||
};
|
||||
|
||||
int SyntaxStackCnt = 8; // number of explicitly initialized elements in SyntaxStack[][2]
|
||||
|
||||
// all code
|
||||
|
||||
@@ -586,7 +590,7 @@ int uint2int(unsigned n)
|
||||
{
|
||||
int r;
|
||||
// Convert n to (int)n in such a way that (unsigned)(int)n == n,
|
||||
// IOW, avoid signed overflows in (int)n.
|
||||
// IOW, avoid signed overflows in (int)n that result in an implementation-defined value/signal.
|
||||
// We're assuming ints are 2's complement.
|
||||
|
||||
// "n < INT_MAX + 1u" is equivalent to "n <= INT_MAX" without the
|
||||
@@ -1039,26 +1043,6 @@ char* GetTokenName(int token)
|
||||
return "";
|
||||
}
|
||||
|
||||
int GetTokenValueInt(void)
|
||||
{
|
||||
return TokenValueInt;
|
||||
}
|
||||
|
||||
char* GetTokenValueString(void)
|
||||
{
|
||||
return TokenValueString;
|
||||
}
|
||||
|
||||
int GetTokenValueStringLength(void)
|
||||
{
|
||||
return TokenStringLen;
|
||||
}
|
||||
|
||||
char* GetTokenIdentName(void)
|
||||
{
|
||||
return TokenIdentName;
|
||||
}
|
||||
|
||||
int GetNextChar(void)
|
||||
{
|
||||
int ch = EOF;
|
||||
@@ -1732,9 +1716,9 @@ int GetToken(void)
|
||||
#endif
|
||||
|
||||
// treat keywords auto, const, register, restrict and volatile as white space for now
|
||||
if (tok == tokConst || tok == tokVolatile ||
|
||||
tok == tokAuto || tok == tokRegister ||
|
||||
tok == tokRestrict)
|
||||
if ((tok == tokConst) | (tok == tokVolatile) |
|
||||
(tok == tokAuto) | (tok == tokRegister) |
|
||||
(tok == tokRestrict))
|
||||
continue;
|
||||
|
||||
return tok;
|
||||
@@ -1788,7 +1772,7 @@ int GetToken(void)
|
||||
if (GetNumber() != tokNumInt)
|
||||
//error("Invalid line number in preprocessor output\n");
|
||||
errorDirective();
|
||||
line = GetTokenValueInt();
|
||||
line = TokenValueInt;
|
||||
|
||||
SkipSpace(0);
|
||||
|
||||
@@ -1799,16 +1783,16 @@ int GetToken(void)
|
||||
else
|
||||
GetString('>', 0);
|
||||
|
||||
if (strlen(GetTokenValueString()) > MAX_FILE_NAME_LEN)
|
||||
if (strlen(TokenValueString) > MAX_FILE_NAME_LEN)
|
||||
//error("File name too long in preprocessor output\n");
|
||||
errorFileName();
|
||||
strcpy(FileNames[FileCnt - 1], GetTokenValueString());
|
||||
strcpy(FileNames[FileCnt - 1], TokenValueString);
|
||||
}
|
||||
|
||||
// Ignore gcc-style #line's flags, if any
|
||||
while (!strchr("\r\n", *p))
|
||||
ShiftCharN(1);
|
||||
|
||||
|
||||
LineNo = line - 1; // "line" is the number of the next line
|
||||
LinePos = 1;
|
||||
|
||||
@@ -1877,7 +1861,7 @@ int GetToken(void)
|
||||
|
||||
if (hadNumber)
|
||||
{
|
||||
PragmaPackValue = GetTokenValueInt();
|
||||
PragmaPackValue = TokenValueInt;
|
||||
if (PragmaPackValue <= 0 ||
|
||||
PragmaPackValue > SizeOfWord ||
|
||||
PragmaPackValue & (PragmaPackValue - 1))
|
||||
@@ -2163,6 +2147,7 @@ int popop()
|
||||
|
||||
int isop(int tok)
|
||||
{
|
||||
/*
|
||||
switch (tok)
|
||||
{
|
||||
case '!':
|
||||
@@ -2190,11 +2175,41 @@ int isop(int tok)
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
static unsigned char toks[] =
|
||||
{
|
||||
'!',
|
||||
'~',
|
||||
'&',
|
||||
'*',
|
||||
'/', '%',
|
||||
'+', '-',
|
||||
'|', '^',
|
||||
'<', '>',
|
||||
'=',
|
||||
tokLogOr, tokLogAnd,
|
||||
tokEQ, tokNEQ,
|
||||
tokLEQ, tokGEQ,
|
||||
tokLShift, tokRShift,
|
||||
tokInc, tokDec,
|
||||
tokSizeof,
|
||||
tokAssignMul, tokAssignDiv, tokAssignMod,
|
||||
tokAssignAdd, tokAssignSub,
|
||||
tokAssignLSh, tokAssignRSh,
|
||||
tokAssignAnd, tokAssignXor, tokAssignOr,
|
||||
tokComma,
|
||||
'?'
|
||||
};
|
||||
unsigned i;
|
||||
for (i = 0; i < sizeof toks / sizeof toks[0]; i++)
|
||||
if (toks[i] == tok)
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int isunary(int tok)
|
||||
{
|
||||
return tok == '!' || tok == '~' || tok == tokInc || tok == tokDec || tok == tokSizeof;
|
||||
return (tok == '!') | (tok == '~') | (tok == tokInc) | (tok == tokDec) | (tok == tokSizeof);
|
||||
}
|
||||
|
||||
int preced(int tok)
|
||||
@@ -2298,7 +2313,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
||||
|
||||
if (tok == tokNumInt || tok == tokNumUint)
|
||||
{
|
||||
push2(tok, GetTokenValueInt());
|
||||
push2(tok, TokenValueInt);
|
||||
*gotUnary = 1;
|
||||
tok = GetToken();
|
||||
}
|
||||
@@ -2311,7 +2326,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
||||
|
||||
// imitate definition: char #[len] = "...";
|
||||
|
||||
AddString(lbl, GetTokenValueString(), len = 1 + GetTokenValueStringLength());
|
||||
AddString(lbl, TokenValueString, len = 1 + TokenStringLen);
|
||||
|
||||
*--p = '\0';
|
||||
p = lab2str(p, lbl);
|
||||
@@ -2329,7 +2344,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
||||
}
|
||||
else if (tok == tokIdent)
|
||||
{
|
||||
push2(tok, AddIdent(GetTokenIdentName()));
|
||||
push2(tok, AddIdent(TokenIdentName));
|
||||
*gotUnary = 1;
|
||||
tok = GetToken();
|
||||
}
|
||||
@@ -2488,7 +2503,7 @@ int exprUnary(int tok, int* gotUnary, int commaSeparator, int argOfSizeOf)
|
||||
tok = GetToken();
|
||||
if (tok != tokIdent)
|
||||
errorUnexpectedToken(tok);
|
||||
push2(tok, AddIdent(GetTokenIdentName()));
|
||||
push2(tok, AddIdent(TokenIdentName));
|
||||
// "->" in "a->b" will function as "+" in "*(type_of_b*)((char*)a + offset_of_b_in_a)"
|
||||
push(tokArrow);
|
||||
push(tokUnaryStar);
|
||||
@@ -4681,7 +4696,7 @@ int TokenStartsDeclaration(int t, int params)
|
||||
#ifndef NO_TYPEDEF_ENUM
|
||||
t == tokEnum ||
|
||||
(t == tokIdent &&
|
||||
FindTypedef(GetTokenIdentName(), &CurScope, 1) >= 0) ||
|
||||
FindTypedef(TokenIdentName, &CurScope, 1) >= 0) ||
|
||||
#endif
|
||||
(!params && (t == tokExtern ||
|
||||
#ifndef NO_TYPEDEF_ENUM
|
||||
@@ -5315,8 +5330,8 @@ int ParseBase(int tok, int base[2])
|
||||
{
|
||||
// this is a structure/union/enum tag
|
||||
gotTag = 1;
|
||||
declPtr = FindTaggedDecl(GetTokenIdentName(), SyntaxStackCnt - 1, &curScope);
|
||||
tagIdent = AddIdent(GetTokenIdentName());
|
||||
declPtr = FindTaggedDecl(TokenIdentName, SyntaxStackCnt - 1, &curScope);
|
||||
tagIdent = AddIdent(TokenIdentName);
|
||||
|
||||
if (declPtr >= 0)
|
||||
{
|
||||
@@ -5382,7 +5397,7 @@ int ParseBase(int tok, int base[2])
|
||||
if (tok != tokIdent)
|
||||
errorUnexpectedToken(tok);
|
||||
|
||||
s = GetTokenIdentName();
|
||||
s = TokenIdentName;
|
||||
if (FindTypedef(s, &CurScope, 0) >= 0 && CurScope)
|
||||
errorRedef(s);
|
||||
|
||||
@@ -5533,7 +5548,7 @@ int ParseBase(int tok, int base[2])
|
||||
}
|
||||
#ifndef NO_TYPEDEF_ENUM
|
||||
else if (tok == tokIdent &&
|
||||
(base[1] = FindTypedef(GetTokenIdentName(), &CurScope, 1)) >= 0)
|
||||
(base[1] = FindTypedef(TokenIdentName, &CurScope, 1)) >= 0)
|
||||
{
|
||||
base[0] = tokTypedef;
|
||||
tok = GetToken();
|
||||
@@ -5610,7 +5625,7 @@ int ParseDerived(int tok)
|
||||
}
|
||||
else if (tok == tokIdent)
|
||||
{
|
||||
PushSyntax2(tok, AddIdent(GetTokenIdentName()));
|
||||
PushSyntax2(tok, AddIdent(TokenIdentName));
|
||||
tok = GetToken();
|
||||
}
|
||||
else
|
||||
@@ -5793,6 +5808,7 @@ int InitScalar(int synPtr, int tok)
|
||||
int gotUnary, synPtr2, constExpr, exprVal;
|
||||
int oldssp = SyntaxStackCnt;
|
||||
int undoIdents = IdentTableLen;
|
||||
int ttop;
|
||||
|
||||
tok = ParseExpr(tok, &gotUnary, &synPtr2, &constExpr, &exprVal, ',', 0);
|
||||
|
||||
@@ -5801,15 +5817,39 @@ int InitScalar(int synPtr, int tok)
|
||||
|
||||
scalarTypeCheck(synPtr2);
|
||||
|
||||
if (stack[sp - 1][0] == tokNumInt || stack[sp - 1][0] == tokNumUint)
|
||||
ttop = stack[sp - 1][0];
|
||||
if (ttop == tokNumInt || ttop == tokNumUint)
|
||||
{
|
||||
// TBD??? truncate values for types smaller than int (e.g. char and short),
|
||||
// so they are always in range?
|
||||
GenIntData(elementSz, stack[0][1]);
|
||||
}
|
||||
else if (elementSz == SizeOfWord + 0u && stack[sp - 1][0] == tokIdent)
|
||||
else if (elementSz == SizeOfWord + 0u)
|
||||
{
|
||||
GenAddrData(elementSz, IdentTable + stack[sp - 1][1]);
|
||||
if (ttop == tokIdent)
|
||||
{
|
||||
GenAddrData(elementSz, IdentTable + stack[sp - 1][1], 0);
|
||||
}
|
||||
else if (ttop == '+' || ttop == '-')
|
||||
{
|
||||
int tleft = stack[sp - 3][0];
|
||||
int tright = stack[sp - 2][0];
|
||||
if (tleft == tokIdent &&
|
||||
(tright == tokNumInt || tright == tokNumUint))
|
||||
{
|
||||
GenAddrData(elementSz, IdentTable + stack[sp - 3][1], (ttop == '+') ? stack[sp - 2][1] : -stack[sp - 2][1]);
|
||||
}
|
||||
else if (ttop == '+' &&
|
||||
tright == tokIdent &&
|
||||
(tleft == tokNumInt || tleft == tokNumUint))
|
||||
{
|
||||
GenAddrData(elementSz, IdentTable + stack[sp - 2][1], stack[sp - 3][1]);
|
||||
}
|
||||
else
|
||||
errorNotConst();
|
||||
}
|
||||
else
|
||||
errorNotConst();
|
||||
// Defer storage of string literal data (if any) until the end.
|
||||
// This will let us generate the contiguous array of pointers to
|
||||
// string literals unperturbed by the string literal data
|
||||
@@ -6082,7 +6122,7 @@ int ParseDecl(int tok, unsigned structInfo[4], int cast, int label)
|
||||
#ifndef NO_TYPEDEF_ENUM
|
||||
typeDef |
|
||||
#endif
|
||||
Static) &&
|
||||
Static) &&
|
||||
!strcmp(IdentTable + SyntaxStack[lastSyntaxPtr][1], "<something>") &&
|
||||
tok == ';')
|
||||
{
|
||||
@@ -7386,7 +7426,7 @@ int ParseStatement(int tok, int BrkCntSwchTarget[4], int switchBody)
|
||||
//error("ParseStatement(): string literal expression expected in 'asm ( expression )'\n");
|
||||
errorUnexpectedToken(tok);
|
||||
|
||||
puts2(GetTokenValueString());
|
||||
puts2(TokenValueString);
|
||||
|
||||
tok = GetToken();
|
||||
if (tok != ')')
|
||||
@@ -7405,9 +7445,9 @@ int ParseStatement(int tok, int BrkCntSwchTarget[4], int switchBody)
|
||||
if ((tok = GetToken()) != tokIdent)
|
||||
errorUnexpectedToken(tok);
|
||||
#ifndef NO_ANNOTATIONS
|
||||
GenStartCommentLine(); printf2("goto %s\n", GetTokenIdentName());
|
||||
GenStartCommentLine(); printf2("goto %s\n", TokenIdentName);
|
||||
#endif
|
||||
GenJumpUncond(AddGotoLabel(GetTokenIdentName(), 0));
|
||||
GenJumpUncond(AddGotoLabel(TokenIdentName, 0));
|
||||
if ((tok = GetToken()) != ';')
|
||||
errorUnexpectedToken(tok);
|
||||
tok = GetToken();
|
||||
@@ -7463,9 +7503,9 @@ int ParseBlock(int BrkCntSwchTarget[4], int switchBody)
|
||||
{
|
||||
// found a label
|
||||
#ifndef NO_ANNOTATIONS
|
||||
GenStartCommentLine(); printf2("%s:\n", GetTokenIdentName());
|
||||
GenStartCommentLine(); printf2("%s:\n", TokenIdentName);
|
||||
#endif
|
||||
GenNumLabel(AddGotoLabel(GetTokenIdentName(), 1));
|
||||
GenNumLabel(AddGotoLabel(TokenIdentName, 1));
|
||||
tok = GetToken();
|
||||
// a statement is needed after "label:"
|
||||
tok = ParseStatement(tok, BrkCntSwchTarget, switchBody);
|
||||
@@ -7621,7 +7661,7 @@ int main(int argc, char** argv)
|
||||
LinePoss[0] = LinePos;
|
||||
FileCnt++;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
else if (FileCnt == 1 && OutFile == NULL)
|
||||
{
|
||||
// This should be the output file name
|
||||
@@ -7629,7 +7669,7 @@ int main(int argc, char** argv)
|
||||
//error("Cannot open output file \"%s\"\n", argv[i]);
|
||||
errorFile(argv[i]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
error("Invalid or unsupported command line option\n");
|
||||
}
|
||||
@@ -7639,16 +7679,6 @@ int main(int argc, char** argv)
|
||||
|
||||
GenInitFinalize();
|
||||
|
||||
// some manual initialization because there's no 2d array initialization yet
|
||||
PushSyntax(tokVoid); // SymVoidSynPtr
|
||||
PushSyntax(tokInt); // SymIntSynPtr
|
||||
PushSyntax(tokUnsigned); // SymUintSynPtr
|
||||
PushSyntax(tokIdent); // SymFuncPtr
|
||||
PushSyntax('[');
|
||||
PushSyntax(tokNumUint);
|
||||
PushSyntax(']');
|
||||
PushSyntax(tokChar);
|
||||
|
||||
#ifndef NO_PREPROCESSOR
|
||||
// Define a few macros useful for conditional compilation
|
||||
DefineMacro("__SMALLER_C__", "0x0100");
|
||||
|
||||
@@ -35,7 +35,7 @@ strip(name)
|
||||
status = 1;
|
||||
goto out;
|
||||
}
|
||||
if (head.a_syms == 0 && head.a_magic != RMAGIC)
|
||||
if (head.a_syms == 0 && (head.a_magic) != RMAGIC)
|
||||
goto out;
|
||||
|
||||
size = N_DATOFF(head) + head.a_data;
|
||||
@@ -45,7 +45,7 @@ strip(name)
|
||||
status = 1;
|
||||
goto out;
|
||||
}
|
||||
head.a_magic = OMAGIC;
|
||||
head.a_midmag = OMAGIC;
|
||||
head.a_reltext = 0;
|
||||
head.a_reldata = 0;
|
||||
head.a_syms = 0;
|
||||
|
||||
@@ -120,6 +120,8 @@ main(argc, argv)
|
||||
char **argv;
|
||||
{
|
||||
long vect;
|
||||
/* extern FILE *f_log; */
|
||||
/* register char opencode; */
|
||||
int prio;
|
||||
register int ac;
|
||||
register char **av;
|
||||
@@ -130,6 +132,7 @@ main(argc, argv)
|
||||
av++;
|
||||
time(&vect);
|
||||
srand(vect);
|
||||
/* opencode = 'w'; */
|
||||
prio = PRIO;
|
||||
if (ioctl(1, TIOCGETP, &argp) == 0)
|
||||
{
|
||||
@@ -140,6 +143,10 @@ main(argc, argv)
|
||||
{
|
||||
switch (av[0][1])
|
||||
{
|
||||
case 'a': /* append to log file */
|
||||
/* opencode = 'a'; */
|
||||
break;
|
||||
|
||||
case 'f': /* set fast mode */
|
||||
Etc.fast++;
|
||||
break;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
char *
|
||||
getenv(name)
|
||||
char *name;
|
||||
const char *name;
|
||||
{
|
||||
int offset;
|
||||
char *_findenv();
|
||||
|
||||
@@ -43,7 +43,8 @@ char *suboptarg;
|
||||
|
||||
int
|
||||
getsubopt(optionp, tokens, valuep)
|
||||
register char **optionp, **valuep;
|
||||
register char **optionp;
|
||||
register char **valuep;
|
||||
register char **tokens;
|
||||
{
|
||||
register int cnt;
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
*/
|
||||
long
|
||||
strtol(nptr, endptr, base)
|
||||
char *nptr;
|
||||
const char *nptr;
|
||||
char **endptr;
|
||||
register int base;
|
||||
{
|
||||
register char *s = nptr;
|
||||
register const char *s = nptr;
|
||||
register unsigned long acc;
|
||||
register int c;
|
||||
register unsigned long cutoff;
|
||||
|
||||
@@ -43,11 +43,11 @@
|
||||
*/
|
||||
unsigned long
|
||||
strtoul(nptr, endptr, base)
|
||||
char *nptr;
|
||||
const char *nptr;
|
||||
char **endptr;
|
||||
register int base;
|
||||
{
|
||||
register char *s = nptr;
|
||||
register const char *s = nptr;
|
||||
register unsigned long acc;
|
||||
register int c;
|
||||
register unsigned long cutoff;
|
||||
|
||||
Reference in New Issue
Block a user