* Dewarninged the lcc and q3asm source

* Removed traditional target platforms from the lcc build. This might break
  building lcc on Windows using nmake. Submit patches or be quiet :p
* Default target for lcc is now bytecode, so -Wf-target=bytecode is no longer
  needed on the lcc command line
This commit is contained in:
Tim Angus 2005-10-04 01:21:34 +00:00
parent 6797dcc705
commit c07dc8dbee
38 changed files with 390 additions and 390 deletions

View file

@ -100,7 +100,7 @@ control(Tokenrow *trp)
error(ERROR, "Unidentifiable control line"); error(ERROR, "Unidentifiable control line");
return; /* else empty line */ return; /* else empty line */
} }
if ((np = lookup(tp, 0))==NULL || (np->flag&ISKW)==0 && !skipping) { if ((np = lookup(tp, 0))==NULL || ((np->flag&ISKW)==0 && !skipping)) {
error(WARNING, "Unknown preprocessor control %t", tp); error(WARNING, "Unknown preprocessor control %t", tp);
return; return;
} }
@ -215,7 +215,7 @@ control(Tokenrow *trp)
tp = trp->bp+2; tp = trp->bp+2;
kline: kline:
if (tp+1>=trp->lp || tp->type!=NUMBER || tp+3<trp->lp if (tp+1>=trp->lp || tp->type!=NUMBER || tp+3<trp->lp
|| (tp+3==trp->lp && ((tp+1)->type!=STRING)||*(tp+1)->t=='L')){ || ((tp+3==trp->lp && ((tp+1)->type!=STRING))||*(tp+1)->t=='L')){
error(ERROR, "Syntax error in #line"); error(ERROR, "Syntax error in #line");
return; return;
} }

View file

@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <string.h>
#define EPR fprintf(stderr, #define EPR fprintf(stderr,
#define ERR(str, chr) if(opterr){EPR "%s%c\n", str, chr);} #define ERR(str, chr) if(opterr){EPR "%s%c\n", str, chr);}
int opterr = 1; int opterr = 1;
int optind = 1; int optind = 1;
int optopt; int optopt;
char *optarg; char *optarg;
char *strchr();
int int
getopt (int argc, char *const argv[], const char *opts) getopt (int argc, char *const argv[], const char *opts)
@ -14,7 +14,7 @@ getopt (int argc, char *const argv[], const char *opts)
int c; int c;
char *cp; char *cp;
if (sp == 1) if (sp == 1) {
if (optind >= argc || if (optind >= argc ||
argv[optind][0] != '-' || argv[optind][1] == '\0') argv[optind][0] != '-' || argv[optind][1] == '\0')
return -1; return -1;
@ -22,6 +22,7 @@ getopt (int argc, char *const argv[], const char *opts)
optind++; optind++;
return -1; return -1;
} }
}
optopt = c = argv[optind][sp]; optopt = c = argv[optind][sp];
if (c == ':' || (cp=strchr(opts, c)) == 0) { if (c == ':' || (cp=strchr(opts, c)) == 0) {
ERR (": illegal option -- ", c); ERR (": illegal option -- ", c);

View file

@ -59,7 +59,7 @@ doinclude(Tokenrow *trp)
if ((fd = open(iname, 0)) >= 0) if ((fd = open(iname, 0)) >= 0)
break; break;
} }
if ( Mflag>1 || !angled&&Mflag==1 ) { if ( Mflag>1 || (!angled&&Mflag==1) ) {
write(1,objname,strlen(objname)); write(1,objname,strlen(objname));
write(1,iname,strlen(iname)); write(1,iname,strlen(iname));
write(1,"\n",1); write(1,"\n",1);

View file

@ -52,183 +52,183 @@ struct fsm {
/*const*/ struct fsm fsm[] = { /*const*/ struct fsm fsm[] = {
/* start state */ /* start state */
START, { C_XX }, ACT(UNCLASS,S_SELF), {START, { C_XX }, ACT(UNCLASS,S_SELF)},
START, { ' ', '\t', '\v' }, WS1, {START, { ' ', '\t', '\v' }, WS1},
START, { C_NUM }, NUM1, {START, { C_NUM }, NUM1},
START, { '.' }, NUM3, {START, { '.' }, NUM3},
START, { C_ALPH }, ID1, {START, { C_ALPH }, ID1},
START, { 'L' }, ST1, {START, { 'L' }, ST1},
START, { '"' }, ST2, {START, { '"' }, ST2},
START, { '\'' }, CC1, {START, { '\'' }, CC1},
START, { '/' }, COM1, {START, { '/' }, COM1},
START, { EOFC }, S_EOF, {START, { EOFC }, S_EOF},
START, { '\n' }, S_NL, {START, { '\n' }, S_NL},
START, { '-' }, MINUS1, {START, { '-' }, MINUS1},
START, { '+' }, PLUS1, {START, { '+' }, PLUS1},
START, { '<' }, LT1, {START, { '<' }, LT1},
START, { '>' }, GT1, {START, { '>' }, GT1},
START, { '=' }, ASG1, {START, { '=' }, ASG1},
START, { '!' }, NOT1, {START, { '!' }, NOT1},
START, { '&' }, AND1, {START, { '&' }, AND1},
START, { '|' }, OR1, {START, { '|' }, OR1},
START, { '#' }, SHARP1, {START, { '#' }, SHARP1},
START, { '%' }, PCT1, {START, { '%' }, PCT1},
START, { '[' }, ACT(SBRA,S_SELF), {START, { '[' }, ACT(SBRA,S_SELF)},
START, { ']' }, ACT(SKET,S_SELF), {START, { ']' }, ACT(SKET,S_SELF)},
START, { '(' }, ACT(LP,S_SELF), {START, { '(' }, ACT(LP,S_SELF)},
START, { ')' }, ACT(RP,S_SELF), {START, { ')' }, ACT(RP,S_SELF)},
START, { '*' }, STAR1, {START, { '*' }, STAR1},
START, { ',' }, ACT(COMMA,S_SELF), {START, { ',' }, ACT(COMMA,S_SELF)},
START, { '?' }, ACT(QUEST,S_SELF), {START, { '?' }, ACT(QUEST,S_SELF)},
START, { ':' }, ACT(COLON,S_SELF), {START, { ':' }, ACT(COLON,S_SELF)},
START, { ';' }, ACT(SEMIC,S_SELF), {START, { ';' }, ACT(SEMIC,S_SELF)},
START, { '{' }, ACT(CBRA,S_SELF), {START, { '{' }, ACT(CBRA,S_SELF)},
START, { '}' }, ACT(CKET,S_SELF), {START, { '}' }, ACT(CKET,S_SELF)},
START, { '~' }, ACT(TILDE,S_SELF), {START, { '~' }, ACT(TILDE,S_SELF)},
START, { '^' }, CIRC1, {START, { '^' }, CIRC1},
/* saw a digit */ /* saw a digit */
NUM1, { C_XX }, ACT(NUMBER,S_SELFB), {NUM1, { C_XX }, ACT(NUMBER,S_SELFB)},
NUM1, { C_NUM, C_ALPH, '.' }, NUM1, {NUM1, { C_NUM, C_ALPH, '.' }, NUM1},
NUM1, { 'E', 'e' }, NUM2, {NUM1, { 'E', 'e' }, NUM2},
NUM1, { '_' }, ACT(NUMBER,S_SELFB), {NUM1, { '_' }, ACT(NUMBER,S_SELFB)},
/* saw possible start of exponent, digits-e */ /* saw possible start of exponent, digits-e */
NUM2, { C_XX }, ACT(NUMBER,S_SELFB), {NUM2, { C_XX }, ACT(NUMBER,S_SELFB)},
NUM2, { '+', '-' }, NUM1, {NUM2, { '+', '-' }, NUM1},
NUM2, { C_NUM, C_ALPH }, NUM1, {NUM2, { C_NUM, C_ALPH }, NUM1},
NUM2, { '_' }, ACT(NUMBER,S_SELFB), {NUM2, { '_' }, ACT(NUMBER,S_SELFB)},
/* saw a '.', which could be a number or an operator */ /* saw a '.', which could be a number or an operator */
NUM3, { C_XX }, ACT(DOT,S_SELFB), {NUM3, { C_XX }, ACT(DOT,S_SELFB)},
NUM3, { '.' }, DOTS1, {NUM3, { '.' }, DOTS1},
NUM3, { C_NUM }, NUM1, {NUM3, { C_NUM }, NUM1},
DOTS1, { C_XX }, ACT(UNCLASS, S_SELFB), {DOTS1, { C_XX }, ACT(UNCLASS, S_SELFB)},
DOTS1, { C_NUM }, NUM1, {DOTS1, { C_NUM }, NUM1},
DOTS1, { '.' }, ACT(ELLIPS, S_SELF), {DOTS1, { '.' }, ACT(ELLIPS, S_SELF)},
/* saw a letter or _ */ /* saw a letter or _ */
ID1, { C_XX }, ACT(NAME,S_NAME), {ID1, { C_XX }, ACT(NAME,S_NAME)},
ID1, { C_ALPH, C_NUM }, ID1, {ID1, { C_ALPH, C_NUM }, ID1},
/* saw L (start of wide string?) */ /* saw L (start of wide string?) */
ST1, { C_XX }, ACT(NAME,S_NAME), {ST1, { C_XX }, ACT(NAME,S_NAME)},
ST1, { C_ALPH, C_NUM }, ID1, {ST1, { C_ALPH, C_NUM }, ID1},
ST1, { '"' }, ST2, {ST1, { '"' }, ST2},
ST1, { '\'' }, CC1, {ST1, { '\'' }, CC1},
/* saw " beginning string */ /* saw " beginning string */
ST2, { C_XX }, ST2, {ST2, { C_XX }, ST2},
ST2, { '"' }, ACT(STRING, S_SELF), {ST2, { '"' }, ACT(STRING, S_SELF)},
ST2, { '\\' }, ST3, {ST2, { '\\' }, ST3},
ST2, { '\n' }, S_STNL, {ST2, { '\n' }, S_STNL},
ST2, { EOFC }, S_EOFSTR, {ST2, { EOFC }, S_EOFSTR},
/* saw \ in string */ /* saw \ in string */
ST3, { C_XX }, ST2, {ST3, { C_XX }, ST2},
ST3, { '\n' }, S_STNL, {ST3, { '\n' }, S_STNL},
ST3, { EOFC }, S_EOFSTR, {ST3, { EOFC }, S_EOFSTR},
/* saw ' beginning character const */ /* saw ' beginning character const */
CC1, { C_XX }, CC1, {CC1, { C_XX }, CC1},
CC1, { '\'' }, ACT(CCON, S_SELF), {CC1, { '\'' }, ACT(CCON, S_SELF)},
CC1, { '\\' }, CC2, {CC1, { '\\' }, CC2},
CC1, { '\n' }, S_STNL, {CC1, { '\n' }, S_STNL},
CC1, { EOFC }, S_EOFSTR, {CC1, { EOFC }, S_EOFSTR},
/* saw \ in ccon */ /* saw \ in ccon */
CC2, { C_XX }, CC1, {CC2, { C_XX }, CC1},
CC2, { '\n' }, S_STNL, {CC2, { '\n' }, S_STNL},
CC2, { EOFC }, S_EOFSTR, {CC2, { EOFC }, S_EOFSTR},
/* saw /, perhaps start of comment */ /* saw /, perhaps start of comment */
COM1, { C_XX }, ACT(SLASH, S_SELFB), {COM1, { C_XX }, ACT(SLASH, S_SELFB)},
COM1, { '=' }, ACT(ASSLASH, S_SELF), {COM1, { '=' }, ACT(ASSLASH, S_SELF)},
COM1, { '*' }, COM2, {COM1, { '*' }, COM2},
COM1, { '/' }, COM4, {COM1, { '/' }, COM4},
/* saw / then *, start of comment */ /* saw / then *, start of comment */
COM2, { C_XX }, COM2, {COM2, { C_XX }, COM2},
COM2, { '\n' }, S_COMNL, {COM2, { '\n' }, S_COMNL},
COM2, { '*' }, COM3, {COM2, { '*' }, COM3},
COM2, { EOFC }, S_EOFCOM, {COM2, { EOFC }, S_EOFCOM},
/* saw the * possibly ending a comment */ /* saw the * possibly ending a comment */
COM3, { C_XX }, COM2, {COM3, { C_XX }, COM2},
COM3, { '\n' }, S_COMNL, {COM3, { '\n' }, S_COMNL},
COM3, { '*' }, COM3, {COM3, { '*' }, COM3},
COM3, { '/' }, S_COMMENT, {COM3, { '/' }, S_COMMENT},
/* // comment */ /* // comment */
COM4, { C_XX }, COM4, {COM4, { C_XX }, COM4},
COM4, { '\n' }, S_NL, {COM4, { '\n' }, S_NL},
COM4, { EOFC }, S_EOFCOM, {COM4, { EOFC }, S_EOFCOM},
/* saw white space, eat it up */ /* saw white space, eat it up */
WS1, { C_XX }, S_WS, {WS1, { C_XX }, S_WS},
WS1, { ' ', '\t', '\v' }, WS1, {WS1, { ' ', '\t', '\v' }, WS1},
/* saw -, check --, -=, -> */ /* saw -, check --, -=, -> */
MINUS1, { C_XX }, ACT(MINUS, S_SELFB), {MINUS1, { C_XX }, ACT(MINUS, S_SELFB)},
MINUS1, { '-' }, ACT(MMINUS, S_SELF), {MINUS1, { '-' }, ACT(MMINUS, S_SELF)},
MINUS1, { '=' }, ACT(ASMINUS,S_SELF), {MINUS1, { '=' }, ACT(ASMINUS,S_SELF)},
MINUS1, { '>' }, ACT(ARROW,S_SELF), {MINUS1, { '>' }, ACT(ARROW,S_SELF)},
/* saw +, check ++, += */ /* saw +, check ++, += */
PLUS1, { C_XX }, ACT(PLUS, S_SELFB), {PLUS1, { C_XX }, ACT(PLUS, S_SELFB)},
PLUS1, { '+' }, ACT(PPLUS, S_SELF), {PLUS1, { '+' }, ACT(PPLUS, S_SELF)},
PLUS1, { '=' }, ACT(ASPLUS, S_SELF), {PLUS1, { '=' }, ACT(ASPLUS, S_SELF)},
/* saw <, check <<, <<=, <= */ /* saw <, check <<, <<=, <= */
LT1, { C_XX }, ACT(LT, S_SELFB), {LT1, { C_XX }, ACT(LT, S_SELFB)},
LT1, { '<' }, LT2, {LT1, { '<' }, LT2},
LT1, { '=' }, ACT(LEQ, S_SELF), {LT1, { '=' }, ACT(LEQ, S_SELF)},
LT2, { C_XX }, ACT(LSH, S_SELFB), {LT2, { C_XX }, ACT(LSH, S_SELFB)},
LT2, { '=' }, ACT(ASLSH, S_SELF), {LT2, { '=' }, ACT(ASLSH, S_SELF)},
/* saw >, check >>, >>=, >= */ /* saw >, check >>, >>=, >= */
GT1, { C_XX }, ACT(GT, S_SELFB), {GT1, { C_XX }, ACT(GT, S_SELFB)},
GT1, { '>' }, GT2, {GT1, { '>' }, GT2},
GT1, { '=' }, ACT(GEQ, S_SELF), {GT1, { '=' }, ACT(GEQ, S_SELF)},
GT2, { C_XX }, ACT(RSH, S_SELFB), {GT2, { C_XX }, ACT(RSH, S_SELFB)},
GT2, { '=' }, ACT(ASRSH, S_SELF), {GT2, { '=' }, ACT(ASRSH, S_SELF)},
/* = */ /* = */
ASG1, { C_XX }, ACT(ASGN, S_SELFB), {ASG1, { C_XX }, ACT(ASGN, S_SELFB)},
ASG1, { '=' }, ACT(EQ, S_SELF), {ASG1, { '=' }, ACT(EQ, S_SELF)},
/* ! */ /* ! */
NOT1, { C_XX }, ACT(NOT, S_SELFB), {NOT1, { C_XX }, ACT(NOT, S_SELFB)},
NOT1, { '=' }, ACT(NEQ, S_SELF), {NOT1, { '=' }, ACT(NEQ, S_SELF)},
/* & */ /* & */
AND1, { C_XX }, ACT(AND, S_SELFB), {AND1, { C_XX }, ACT(AND, S_SELFB)},
AND1, { '&' }, ACT(LAND, S_SELF), {AND1, { '&' }, ACT(LAND, S_SELF)},
AND1, { '=' }, ACT(ASAND, S_SELF), {AND1, { '=' }, ACT(ASAND, S_SELF)},
/* | */ /* | */
OR1, { C_XX }, ACT(OR, S_SELFB), {OR1, { C_XX }, ACT(OR, S_SELFB)},
OR1, { '|' }, ACT(LOR, S_SELF), {OR1, { '|' }, ACT(LOR, S_SELF)},
OR1, { '=' }, ACT(ASOR, S_SELF), {OR1, { '=' }, ACT(ASOR, S_SELF)},
/* # */ /* # */
SHARP1, { C_XX }, ACT(SHARP, S_SELFB), {SHARP1, { C_XX }, ACT(SHARP, S_SELFB)},
SHARP1, { '#' }, ACT(DSHARP, S_SELF), {SHARP1, { '#' }, ACT(DSHARP, S_SELF)},
/* % */ /* % */
PCT1, { C_XX }, ACT(PCT, S_SELFB), {PCT1, { C_XX }, ACT(PCT, S_SELFB)},
PCT1, { '=' }, ACT(ASPCT, S_SELF), {PCT1, { '=' }, ACT(ASPCT, S_SELF)},
/* * */ /* * */
STAR1, { C_XX }, ACT(STAR, S_SELFB), {STAR1, { C_XX }, ACT(STAR, S_SELFB)},
STAR1, { '=' }, ACT(ASSTAR, S_SELF), {STAR1, { '=' }, ACT(ASSTAR, S_SELF)},
/* ^ */ /* ^ */
CIRC1, { C_XX }, ACT(CIRC, S_SELFB), {CIRC1, { C_XX }, ACT(CIRC, S_SELFB)},
CIRC1, { '=' }, ACT(ASCIRC, S_SELF), {CIRC1, { '=' }, ACT(ASCIRC, S_SELF)},
-1 {-1}
}; };
/* first index is char, second is state */ /* first index is char, second is state */
@ -254,7 +254,7 @@ expandlex(void)
continue; continue;
case C_ALPH: case C_ALPH:
for (j=0; j<=256; j++) for (j=0; j<=256; j++)
if ('a'<=j&&j<='z' || 'A'<=j&&j<='Z' if (('a'<=j&&j<='z') || ('A'<=j&&j<='Z')
|| j=='_') || j=='_')
bigfsm[j][fp->state] = nstate; bigfsm[j][fp->state] = nstate;
continue; continue;
@ -305,7 +305,6 @@ gettokens(Tokenrow *trp, int reset)
int runelen; int runelen;
Source *s = cursource; Source *s = cursource;
int nmac = 0; int nmac = 0;
extern char outbuf[];
tp = trp->lp; tp = trp->lp;
ip = s->inp; ip = s->inp;

View file

@ -71,7 +71,7 @@ dodefine(Tokenrow *trp)
if (np->flag&ISDEFINED) { if (np->flag&ISDEFINED) {
if (comparetokens(def, np->vp) if (comparetokens(def, np->vp)
|| (np->ap==NULL) != (args==NULL) || (np->ap==NULL) != (args==NULL)
|| np->ap && comparetokens(args, np->ap)) || (np->ap && comparetokens(args, np->ap)))
error(ERROR, "Macro redefinition of %t", trp->bp+2); error(ERROR, "Macro redefinition of %t", trp->bp+2);
} }
if (args) { if (args) {
@ -141,7 +141,7 @@ expandrow(Tokenrow *trp, char *flag)
|| quicklook(tp->t[0], tp->len>1?tp->t[1]:0)==0 || quicklook(tp->t[0], tp->len>1?tp->t[1]:0)==0
|| (np = lookup(tp, 0))==NULL || (np = lookup(tp, 0))==NULL
|| (np->flag&(ISDEFINED|ISMAC))==0 || (np->flag&(ISDEFINED|ISMAC))==0
|| tp->hideset && checkhideset(tp->hideset, np)) { || (tp->hideset && checkhideset(tp->hideset, np))) {
tp++; tp++;
continue; continue;
} }
@ -300,7 +300,7 @@ gatherargs(Tokenrow *trp, Tokenrow **atr, int *narg)
parens--; parens--;
if (lp->type==DSHARP) if (lp->type==DSHARP)
lp->type = DSHARP1; /* ## not special in arg */ lp->type = DSHARP1; /* ## not special in arg */
if (lp->type==COMMA && parens==0 || parens<0 && (lp-1)->type!=LP) { if ((lp->type==COMMA && parens==0) || (parens<0 && (lp-1)->type!=LP)) {
if (*narg>=NARG-1) if (*narg>=NARG-1)
error(FATAL, "Sorry, too many macro arguments"); error(FATAL, "Sorry, too many macro arguments");
ttr.bp = ttr.tp = bp; ttr.bp = ttr.tp = bp;
@ -339,7 +339,7 @@ substargs(Nlist *np, Tokenrow *rtr, Tokenrow **atr)
if (rtr->tp->type==NAME if (rtr->tp->type==NAME
&& (argno = lookuparg(np, rtr->tp)) >= 0) { && (argno = lookuparg(np, rtr->tp)) >= 0) {
if ((rtr->tp+1)->type==DSHARP if ((rtr->tp+1)->type==DSHARP
|| rtr->tp!=rtr->bp && (rtr->tp-1)->type==DSHARP) || (rtr->tp!=rtr->bp && (rtr->tp-1)->type==DSHARP))
insertrow(rtr, 1, atr[argno]); insertrow(rtr, 1, atr[argno]);
else { else {
copytokenrow(&tatr, atr[argno]); copytokenrow(&tatr, atr[argno]);

View file

@ -20,26 +20,26 @@ struct kwtab {
int val; int val;
int flag; int flag;
} kwtab[] = { } kwtab[] = {
"if", KIF, ISKW, {"if", KIF, ISKW},
"ifdef", KIFDEF, ISKW, {"ifdef", KIFDEF, ISKW},
"ifndef", KIFNDEF, ISKW, {"ifndef", KIFNDEF, ISKW},
"elif", KELIF, ISKW, {"elif", KELIF, ISKW},
"else", KELSE, ISKW, {"else", KELSE, ISKW},
"endif", KENDIF, ISKW, {"endif", KENDIF, ISKW},
"include", KINCLUDE, ISKW, {"include", KINCLUDE, ISKW},
"define", KDEFINE, ISKW, {"define", KDEFINE, ISKW},
"undef", KUNDEF, ISKW, {"undef", KUNDEF, ISKW},
"line", KLINE, ISKW, {"line", KLINE, ISKW},
"error", KERROR, ISKW, {"error", KERROR, ISKW},
"pragma", KPRAGMA, ISKW, {"pragma", KPRAGMA, ISKW},
"eval", KEVAL, ISKW, {"eval", KEVAL, ISKW},
"defined", KDEFINED, ISDEFINED+ISUNCHANGE, {"defined", KDEFINED, ISDEFINED+ISUNCHANGE},
"__LINE__", KLINENO, ISMAC+ISUNCHANGE, {"__LINE__", KLINENO, ISMAC+ISUNCHANGE},
"__FILE__", KFILE, ISMAC+ISUNCHANGE, {"__FILE__", KFILE, ISMAC+ISUNCHANGE},
"__DATE__", KDATE, ISMAC+ISUNCHANGE, {"__DATE__", KDATE, ISMAC+ISUNCHANGE},
"__TIME__", KTIME, ISMAC+ISUNCHANGE, {"__TIME__", KTIME, ISMAC+ISUNCHANGE},
"__STDC__", KSTDC, ISUNCHANGE, {"__STDC__", KSTDC, ISUNCHANGE},
NULL {NULL}
}; };
unsigned long namebit[077+1]; unsigned long namebit[077+1];

View file

@ -154,14 +154,14 @@ makespace(Tokenrow *trp)
return; return;
if (tp->wslen) { if (tp->wslen) {
if (tp->flag&XPWS if (tp->flag&XPWS
&& (wstab[tp->type] || trp->tp>trp->bp && wstab[(tp-1)->type])) { && (wstab[tp->type] || (trp->tp>trp->bp && wstab[(tp-1)->type]))) {
tp->wslen = 0; tp->wslen = 0;
return; return;
} }
tp->t[-1] = ' '; tp->t[-1] = ' ';
return; return;
} }
if (wstab[tp->type] || trp->tp>trp->bp && wstab[(tp-1)->type]) if (wstab[tp->type] || (trp->tp>trp->bp && wstab[(tp-1)->type]))
return; return;
tt = newstring(tp->t, tp->len, 1); tt = newstring(tp->t, tp->len, 1);
*tt++ = ' '; *tt++ = ' ';

View file

@ -1 +0,0 @@
BUILDDIR=.obj

View file

@ -70,7 +70,7 @@ void *alloc(unsigned n) {
void emitdata(char *file) { void emitdata(char *file) {
FILE *fp; FILE *fp;
if (fp = fopen(file, "w")) { if ((fp = fopen(file, "w"))) {
struct file *p; struct file *p;
for (p = filelist; p; p = p->link) { for (p = filelist; p; p = p->link) {
int i; int i;
@ -78,7 +78,7 @@ void emitdata(char *file) {
struct caller *r; struct caller *r;
fprintf(fp, "1\n%s\n", p->name); fprintf(fp, "1\n%s\n", p->name);
for (i = 0, q = p->funcs; q; i++, q = q->link) for (i = 0, q = p->funcs; q; i++, q = q->link)
if (r = q->callers) if ((r = q->callers))
for (i--; r; r = r->link) for (i--; r; r = r->link)
i++; i++;
fprintf(fp, "%d\n", i); fprintf(fp, "%d\n", i);
@ -109,7 +109,7 @@ FILE *openfile(char *name) {
for (i = 0; dirs[i]; i++) { for (i = 0; dirs[i]; i++) {
char buf[200]; char buf[200];
sprintf(buf, "%s/%s", dirs[i], name); sprintf(buf, "%s/%s", dirs[i], name);
if (fp = fopen(buf, "r")) if ((fp = fopen(buf, "r")))
return fp; return fp;
} }
return fopen(name, "r"); return fopen(name, "r");
@ -297,9 +297,9 @@ int findcount(char *file, int x, int y) {
struct count *c = cursor->counts; struct count *c = cursor->counts;
for (l = 0, u = cursor->count - 1; l <= u; ) { for (l = 0, u = cursor->count - 1; l <= u; ) {
int k = (l + u)/2; int k = (l + u)/2;
if (c[k].y > y || c[k].y == y && c[k].x > x) if (c[k].y > y || (c[k].y == y && c[k].x > x))
u = k - 1; u = k - 1;
else if (c[k].y < y || c[k].y == y && c[k].x < x) else if (c[k].y < y || (c[k].y == y && c[k].x < x))
l = k + 1; l = k + 1;
else else
return c[k].count; return c[k].count;
@ -461,7 +461,7 @@ int main(int argc, char *argv[]) {
if (i < argc) { if (i < argc) {
int nf = i < argc - 1 ? 1 : 0; int nf = i < argc - 1 ? 1 : 0;
for ( ; i < argc; i++, nf ? nf++ : 0) for ( ; i < argc; i++, nf ? nf++ : 0)
if (p = findfile(string(argv[i]))) if ((p = findfile(string(argv[i]))))
(*f)(p, nf); (*f)(p, nf);
else else
fprintf(stderr, "%s: no data for `%s'\n", progname, argv[i]); fprintf(stderr, "%s: no data for `%s'\n", progname, argv[i]);

View file

@ -11,6 +11,7 @@ static char rcsid[] = "Id: dummy rcsid";
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#include <signal.h> #include <signal.h>
#include <unistd.h>
#ifndef TEMPDIR #ifndef TEMPDIR
#define TEMPDIR "/tmp" #define TEMPDIR "/tmp"
@ -47,7 +48,6 @@ extern char *stringf(const char *, ...);
extern int suffix(char *, char *[], int); extern int suffix(char *, char *[], int);
extern char *tempname(char *); extern char *tempname(char *);
extern int access(char *, int);
extern int getpid(void); extern int getpid(void);
extern char *cpp[], *include[], *com[], *as[],*ld[], inputs[], *suffixes[]; extern char *cpp[], *include[], *com[], *as[],*ld[], inputs[], *suffixes[];
@ -71,7 +71,7 @@ char *tempdir = TEMPDIR; /* directory for temporary files */
static char *progname; static char *progname;
static List lccinputs; /* list of input directories */ static List lccinputs; /* list of input directories */
main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
int i, j, nf; int i, j, nf;
progname = argv[0]; progname = argv[0];
@ -93,7 +93,7 @@ main(int argc, char *argv[]) {
tempdir = getenv("TMPDIR"); tempdir = getenv("TMPDIR");
assert(tempdir); assert(tempdir);
i = strlen(tempdir); i = strlen(tempdir);
for (; i > 0 && tempdir[i-1] == '/' || tempdir[i-1] == '\\'; i--) for (; (i > 0 && tempdir[i-1] == '/') || tempdir[i-1] == '\\'; i--)
tempdir[i-1] = '\0'; tempdir[i-1] = '\0';
if (argc <= 1) { if (argc <= 1) {
help(); help();
@ -149,7 +149,7 @@ main(int argc, char *argv[]) {
char *name = exists(argv[i]); char *name = exists(argv[i]);
if (name) { if (name) {
if (strcmp(name, argv[i]) != 0 if (strcmp(name, argv[i]) != 0
|| nf > 1 && suffix(name, suffixes, 3) >= 0) || (nf > 1 && suffix(name, suffixes, 3) >= 0))
fprintf(stderr, "%s:\n", name); fprintf(stderr, "%s:\n", name);
filename(name, 0); filename(name, 0);
} else } else
@ -214,7 +214,6 @@ char *basepath(char *name) {
#define _P_WAIT 0 #define _P_WAIT 0
extern int fork(void); extern int fork(void);
extern int wait(int *); extern int wait(int *);
extern void execv(const char *, char *[]);
static int _spawnvp(int mode, const char *cmdname, char *argv[]) { static int _spawnvp(int mode, const char *cmdname, char *argv[]) {
int pid, n, status; int pid, n, status;
@ -261,7 +260,7 @@ static int callsys(char **av) {
} }
for (i = 0; status == 0 && av[i] != NULL; ) { for (i = 0; status == 0 && av[i] != NULL; ) {
int j = 0; int j = 0;
char *s; char *s = NULL;
for ( ; av[i] != NULL && (s = strchr(av[i], '\n')) == NULL; i++) for ( ; av[i] != NULL && (s = strchr(av[i], '\n')) == NULL; i++)
argv[j++] = av[i]; argv[j++] = av[i];
if (s != NULL) { if (s != NULL) {
@ -319,7 +318,7 @@ static void compose(char *cmd[], List a, List b, List c) {
if (s && isdigit(s[1])) { if (s && isdigit(s[1])) {
int k = s[1] - '0'; int k = s[1] - '0';
assert(k >=1 && k <= 3); assert(k >=1 && k <= 3);
if (b = lists[k-1]) { if ((b = lists[k-1])) {
b = b->link; b = b->link;
av[j] = alloc(strlen(cmd[i]) + strlen(b->str) - 1); av[j] = alloc(strlen(cmd[i]) + strlen(b->str) - 1);
strncpy(av[j], cmd[i], s - cmd[i]); strncpy(av[j], cmd[i], s - cmd[i]);
@ -452,7 +451,7 @@ static int filename(char *name, char *base) {
static List find(char *str, List list) { static List find(char *str, List list) {
List b; List b;
if (b = list) if ((b = list))
do { do {
if (strcmp(str, b->str) == 0) if (strcmp(str, b->str) == 0)
return b; return b;
@ -508,7 +507,7 @@ static void help(void) {
if (strncmp("-tempdir", msgs[i], 8) == 0 && tempdir) if (strncmp("-tempdir", msgs[i], 8) == 0 && tempdir)
fprintf(stderr, "; default=%s", tempdir); fprintf(stderr, "; default=%s", tempdir);
} }
#define xx(v) if (s = getenv(#v)) fprintf(stderr, #v "=%s\n", s) #define xx(v) if ((s = getenv(#v))) fprintf(stderr, #v "=%s\n", s)
xx(LCCINPUTS); xx(LCCINPUTS);
xx(LCCDIR); xx(LCCDIR);
#ifdef WIN32 #ifdef WIN32
@ -521,13 +520,13 @@ static void help(void) {
/* initinputs - if LCCINPUTS or include is defined, use them to initialize various lists */ /* initinputs - if LCCINPUTS or include is defined, use them to initialize various lists */
static void initinputs(void) { static void initinputs(void) {
char *s = getenv("LCCINPUTS"); char *s = getenv("LCCINPUTS");
List list, b; List b;
if (s == 0 || (s = inputs)[0] == 0) if (s == 0 || (s = inputs)[0] == 0)
s = "."; s = ".";
if (s) { if (s) {
lccinputs = path2list(s); lccinputs = path2list(s);
if (b = lccinputs) if ((b = lccinputs))
do { do {
b = b->link; b = b->link;
if (strcmp(b->str, ".") != 0) { if (strcmp(b->str, ".") != 0) {
@ -701,7 +700,7 @@ static List path2list(const char *path) {
sep = ';'; sep = ';';
while (*path) { while (*path) {
char *p, buf[512]; char *p, buf[512];
if (p = strchr(path, sep)) { if ((p = strchr(path, sep))) {
assert(p - path < sizeof buf); assert(p - path < sizeof buf);
strncpy(buf, path, p - path); strncpy(buf, path, p - path);
buf[p-path] = '\0'; buf[p-path] = '\0';
@ -767,7 +766,7 @@ int suffix(char *name, char *tails[], int n) {
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
char *s = tails[i], *t; char *s = tails[i], *t;
for ( ; t = strchr(s, ';'); s = t + 1) { for ( ; (t = strchr(s, ';')); s = t + 1) {
int m = t - s; int m = t - s;
if (len > m && strncmp(&name[len-m], s, m) == 0) if (len > m && strncmp(&name[len-m], s, m) == 0)
return i; return i;

View file

@ -2,8 +2,6 @@
#include <string.h> #include <string.h>
static char rcsid[] = "Dummy rcsid";
/* /*
TTimo - 10-18-2001 TTimo - 10-18-2001
our binaries are named q3lcc q3rcc and q3cpp our binaries are named q3lcc q3rcc and q3cpp
@ -26,7 +24,7 @@ char *cpp[] = { LCCDIR "q3cpp",
"$1", "$2", "$3", 0 }; "$1", "$2", "$3", 0 };
char *include[] = {"-I" LCCDIR "include", "-I" LCCDIR "gcc/include", "-I/usr/include", char *include[] = {"-I" LCCDIR "include", "-I" LCCDIR "gcc/include", "-I/usr/include",
"-I" SYSTEM "include", 0 }; "-I" SYSTEM "include", 0 };
char *com[] = {LCCDIR "q3rcc", "-target=x86/linux", "$1", "$2", "$3", 0 }; char *com[] = {LCCDIR "q3rcc", "-target=bytecode", "$1", "$2", "$3", 0 };
char *as[] = { "/usr/bin/as", "-o", "$3", "$1", "$2", 0 }; char *as[] = { "/usr/bin/as", "-o", "$3", "$1", "$2", 0 };
// NOTE TTimo I don't think we have any use with the native linkage // NOTE TTimo I don't think we have any use with the native linkage
// our target is always bytecode.. // our target is always bytecode..

View file

@ -18,9 +18,9 @@ YYCONST static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley +Cygnus.28) 01/20/91
#ifndef YYDONT_INCLUDE_STDIO #ifndef YYDONT_INCLUDE_STDIO
#include <stdio.h> #include <stdio.h>
#endif #endif
#ifdef __cplusplus //#ifdef __cplusplus TA <tim@ngus.net> stdlib.h applies to C too
#include <stdlib.h> /* for malloc/realloc/free */ #include <stdlib.h> /* for malloc/realloc/free */
#endif //#endif
#line 2 "lburg/gram.y" #line 2 "lburg/gram.y"
#include <stdio.h> #include <stdio.h>
#include "lburg.h" #include "lburg.h"
@ -227,7 +227,9 @@ inline
#endif #endif
yygrow () yygrow ()
{ {
#if YYDEBUG
int old_stacksize = yystacksize; int old_stacksize = yystacksize;
#endif
short *new_yyss; short *new_yyss;
YYSTYPE *new_yyvs; YYSTYPE *new_yyvs;
@ -469,7 +471,7 @@ yypush:
*++yyvsp = yyval; *++yyvsp = yyval;
yyloop: yyloop:
if (yyn = yydefred[yystate]) goto yyreduce; if ((yyn = yydefred[yystate])) goto yyreduce;
yyn = yysindex[yystate]; yyn = yysindex[yystate];
if (yychar < 0) if (yychar < 0)
{ {
@ -509,13 +511,13 @@ yyloop:
if (yyerrflag) goto yyinrecovery; if (yyerrflag) goto yyinrecovery;
#ifdef lint #ifdef lint
goto yynewerror; goto yynewerror;
#endif
yynewerror: yynewerror:
#endif
yyerror("syntax error"); yyerror("syntax error");
#ifdef lint #ifdef lint
goto yyerrlab; goto yyerrlab;
#endif
yyerrlab: yyerrlab:
#endif
++yynerrs; ++yynerrs;
yyinrecovery: yyinrecovery:
if (yyerrflag < 3) if (yyerrflag < 3)

View file

@ -55,7 +55,7 @@ static void profout(struct _bbdata *p, FILE *fp) {
for (i = 0; p->files[i]; i++) for (i = 0; p->files[i]; i++)
fprintf(fp, "%s\n", p->files[i]); fprintf(fp, "%s\n", p->files[i]);
for (i = 0, f = p->funcs; f; i++, f = f->link) for (i = 0, f = p->funcs; f; i++, f = f->link)
if (q = f->callers) if ((q = f->callers))
for (i--; q; q = q->link) for (i--; q; q = q->link)
i++; i++;
fprintf(fp, "%d\n", i); fprintf(fp, "%d\n", i);

View file

@ -5,7 +5,7 @@ A=.a
O=.o O=.o
E= E=
CC=cc CC=cc
CFLAGS=-g -Wall CFLAGS=-O2 -Wall -fno-strict-aliasing
LDFLAGS= LDFLAGS=
LD=cc LD=cc
AR=ar ruv AR=ar ruv
@ -13,9 +13,8 @@ RANLIB=ranlib
DIFF=diff DIFF=diff
RM=rm -f RM=rm -f
RMDIR=rmdir RMDIR=rmdir
BUILDDIR=build
TSTDIR=$(BUILDDIR)/$(TARGET)/tst TSTDIR=$(BUILDDIR)/$(TARGET)/tst
CUSTOM=custom.mk
include $(CUSTOM)
B=$(BUILDDIR)/ B=$(BUILDDIR)/
T=$(TSTDIR)/ T=$(TSTDIR)/
@ -24,14 +23,18 @@ T=$(TSTDIR)/
what: what:
-@echo make all q3rcc lburg q3cpp q3lcc bprint liblcc triple clean clobber -@echo make all q3rcc lburg q3cpp q3lcc bprint liblcc triple clean clobber
makedirs:
@if [ ! -d $(B) ];then mkdir $(B);fi
@if [ ! -d $(T) ];then mkdir $(T);fi
all:: q3rcc lburg q3cpp q3lcc bprint liblcc all:: q3rcc lburg q3cpp q3lcc bprint liblcc
q3rcc: $Bq3rcc$E q3rcc: makedirs $Bq3rcc$E
lburg: $Blburg$E lburg: makedirs $Blburg$E
q3cpp: $Bq3cpp$E q3cpp: makedirs $Bq3cpp$E
q3lcc: $Bq3lcc$E q3lcc: makedirs $Bq3lcc$E
bprint: $Bbprint$E bprint: makedirs $Bbprint$E
liblcc: $Bliblcc$A liblcc: makedirs $Bliblcc$A
RCCOBJS=$Balloc$O \ RCCOBJS=$Balloc$O \
$Bbind$O \ $Bbind$O \
@ -61,13 +64,7 @@ RCCOBJS=$Balloc$O \
$Bnull$O \ $Bnull$O \
$Bsymbolic$O \ $Bsymbolic$O \
$Bgen$O \ $Bgen$O \
$Bbytecode$O \ $Bbytecode$O
$Balpha$O \
$Bmips$O \
$Bsparc$O \
$Bstab$O \
$Bx86$O \
$Bx86linux$O
$Bq3rcc$E:: $Bmain$O $Blibrcc$A $(EXTRAOBJS) $Bq3rcc$E:: $Bmain$O $Blibrcc$A $(EXTRAOBJS)
$(LD) $(LDFLAGS) -o $@ $Bmain$O $(EXTRAOBJS) $Blibrcc$A $(EXTRALIBS) $(LD) $(LDFLAGS) -o $@ $Bmain$O $(EXTRAOBJS) $Blibrcc$A $(EXTRALIBS)

View file

@ -7,17 +7,17 @@ extern Interface symbolicIR, symbolic64IR;
extern Interface nullIR; extern Interface nullIR;
extern Interface bytecodeIR; extern Interface bytecodeIR;
Binding bindings[] = { Binding bindings[] = {
"alpha/osf", &alphaIR, /*{ "alpha/osf", &alphaIR },*/
"mips/irix", &mipsebIR, /*{ "mips/irix", &mipsebIR },*/
"mips/ultrix", &mipselIR, /*{ "mips/ultrix", &mipselIR },*/
"sparc/sun", &sparcIR, /*{ "sparc/sun", &sparcIR },*/
"sparc/solaris", &solarisIR, /*{ "sparc/solaris", &solarisIR },*/
"x86/win32", &x86IR, /*{ "x86/win32", &x86IR },*/
"x86/linux", &x86linuxIR, /*{ "x86/linux", &x86linuxIR },*/
"symbolic/osf", &symbolic64IR, { "symbolic/osf", &symbolic64IR },
"symbolic/irix", &symbolicIR, { "symbolic/irix", &symbolicIR },
"symbolic", &symbolicIR, { "symbolic", &symbolicIR },
"null", &nullIR, { "null", &nullIR },
"bytecode", &bytecodeIR, { "bytecode", &bytecodeIR },
NULL, NULL { NULL, NULL },
}; };

View file

@ -320,16 +320,16 @@ static void I(stabline)(Coordinate *cp) {
#define b_blockend blockend #define b_blockend blockend
Interface bytecodeIR = { Interface bytecodeIR = {
1, 1, 0, /* char */ {1, 1, 0}, /* char */
2, 2, 0, /* short */ {2, 2, 0}, /* short */
4, 4, 0, /* int */ {4, 4, 0}, /* int */
4, 4, 0, /* long */ {4, 4, 0}, /* long */
4, 4, 0, /* long long */ {4, 4, 0}, /* long long */
4, 4, 0, /* float */ // JDC: use inline floats {4, 4, 0}, /* float */ // JDC: use inline floats
4, 4, 0, /* double */ // JDC: don't ever emit 8 byte double code {4, 4, 0}, /* double */ // JDC: don't ever emit 8 byte double code
4, 4, 0, /* long double */ // JDC: don't ever emit 8 byte double code {4, 4, 0}, /* long double */ // JDC: don't ever emit 8 byte double code
4, 4, 0, /* T* */ {4, 4, 0}, /* T* */
0, 4, 0, /* struct */ {0, 4, 0}, /* struct */
0, /* little_endian */ 0, /* little_endian */
0, /* mulops_calls */ 0, /* mulops_calls */
0, /* wants_callb */ 0, /* wants_callb */

View file

@ -14,7 +14,7 @@
#define BUFSIZE 4096 #define BUFSIZE 4096
#define istypename(t,tsym) (kind[t] == CHAR \ #define istypename(t,tsym) (kind[t] == CHAR \
|| t == ID && tsym && tsym->sclass == TYPEDEF) || (t == ID && tsym && tsym->sclass == TYPEDEF))
#define sizeop(n) ((n)<<10) #define sizeop(n) ((n)<<10)
#define generic(op) ((op)&0x3F0) #define generic(op) ((op)&0x3F0)
#define specific(op) ((op)&0x3FF) #define specific(op) ((op)&0x3FF)

View file

@ -2,9 +2,9 @@
#define iscall(op) (generic(op) == CALL \ #define iscall(op) (generic(op) == CALL \
|| IR->mulops_calls \ || (IR->mulops_calls \
&& (generic(op)==DIV||generic(op)==MOD||generic(op)==MUL) \ && (generic(op)==DIV||generic(op)==MOD||generic(op)==MUL) \
&& ( optype(op)==U || optype(op)==I)) && ( optype(op)==U || optype(op)==I)))
static Node forest; static Node forest;
static struct dag { static struct dag {
struct node node; struct node node;
@ -102,7 +102,7 @@ Node listnodes(Tree tp, int tlab, int flab) {
Node p = NULL, l, r; Node p = NULL, l, r;
int op; int op;
assert(tlab || flab || tlab == 0 && flab == 0); assert(tlab || flab || (tlab == 0 && flab == 0));
if (tp == NULL) if (tp == NULL)
return NULL; return NULL;
if (tp->node) if (tp->node)
@ -172,8 +172,8 @@ Node listnodes(Tree tp, int tlab, int flab) {
p = node(op, NULL, NULL, constant(ty, tp->u.v)); } break; p = node(op, NULL, NULL, constant(ty, tp->u.v)); } break;
case RIGHT: { if ( tp->kids[0] && tp->kids[1] case RIGHT: { if ( tp->kids[0] && tp->kids[1]
&& generic(tp->kids[1]->op) == ASGN && generic(tp->kids[1]->op) == ASGN
&& (generic(tp->kids[0]->op) == INDIR && ((generic(tp->kids[0]->op) == INDIR
&& tp->kids[0]->kids[0] == tp->kids[1]->kids[0] && tp->kids[0]->kids[0] == tp->kids[1]->kids[0])
|| (tp->kids[0]->op == FIELD || (tp->kids[0]->op == FIELD
&& tp->kids[0] == tp->kids[1]->kids[0]))) { && tp->kids[0] == tp->kids[1]->kids[0]))) {
assert(tlab == 0 && flab == 0); assert(tlab == 0 && flab == 0);
@ -276,11 +276,11 @@ Node listnodes(Tree tp, int tlab, int flab) {
unsigned int fmask = fieldmask(f); unsigned int fmask = fieldmask(f);
unsigned int mask = fmask<<fieldright(f); unsigned int mask = fmask<<fieldright(f);
Tree q = tp->kids[1]; Tree q = tp->kids[1];
if (q->op == CNST+I && q->u.v.i == 0 if ((q->op == CNST+I && q->u.v.i == 0)
|| q->op == CNST+U && q->u.v.u == 0) || (q->op == CNST+U && q->u.v.u == 0))
q = bittree(BAND, x, cnsttree(unsignedtype, (unsigned long)~mask)); q = bittree(BAND, x, cnsttree(unsignedtype, (unsigned long)~mask));
else if (q->op == CNST+I && (q->u.v.i&fmask) == fmask else if ((q->op == CNST+I && (q->u.v.i&fmask) == fmask)
|| q->op == CNST+U && (q->u.v.u&fmask) == fmask) || (q->op == CNST+U && (q->u.v.u&fmask) == fmask))
q = bittree(BOR, x, cnsttree(unsignedtype, (unsigned long)mask)); q = bittree(BOR, x, cnsttree(unsignedtype, (unsigned long)mask));
else { else {
listnodes(q, 0, 0); listnodes(q, 0, 0);
@ -621,11 +621,11 @@ static Node prune(Node forest) {
return forest; return forest;
} }
static Node visit(Node p, int listed) { static Node visit(Node p, int listed) {
if (p) if (p) {
if (p->syms[2]) if (p->syms[2])
p = tmpnode(p); p = tmpnode(p);
else if (p->count <= 1 && !iscall(p->op) else if ((p->count <= 1 && !iscall(p->op))
|| p->count == 0 && iscall(p->op)) { || (p->count == 0 && iscall(p->op))) {
p->kids[0] = visit(p->kids[0], 0); p->kids[0] = visit(p->kids[0], 0);
p->kids[1] = visit(p->kids[1], 0); p->kids[1] = visit(p->kids[1], 0);
} }
@ -654,6 +654,7 @@ static Node visit(Node p, int listed) {
if (!listed) if (!listed)
p = tmpnode(p); p = tmpnode(p);
}; };
}
return p; return p;
} }
static Node tmpnode(Node p) { static Node tmpnode(Node p) {

View file

@ -115,10 +115,10 @@ static Type specifier(int *sclass) {
type = INT; type = INT;
ty = inttype; ty = inttype;
} }
if (size == SHORT && type != INT if ((size == SHORT && type != INT)
|| size == LONG+LONG && type != INT || (size == LONG+LONG && type != INT)
|| size == LONG && type != INT && type != DOUBLE || (size == LONG && type != INT && type != DOUBLE)
|| sign && type != INT && type != CHAR) || (sign && type != INT && type != CHAR))
error("invalid type specification\n"); error("invalid type specification\n");
if (type == CHAR && sign) if (type == CHAR && sign)
ty = sign == UNSIGNED ? unsignedchar : signedchar; ty = sign == UNSIGNED ? unsignedchar : signedchar;
@ -196,7 +196,7 @@ static void decl(Symbol (*dcl)(int, char *, Type, Coordinate *)) {
} }
} else if (ty == NULL } else if (ty == NULL
|| !(isenum(ty) || || !(isenum(ty) ||
isstruct(ty) && (*unqual(ty)->u.sym->name < '1' || *unqual(ty)->u.sym->name > '9'))) (isstruct(ty) && (*unqual(ty)->u.sym->name < '1' || *unqual(ty)->u.sym->name > '9'))))
error("empty declaration\n"); error("empty declaration\n");
test(';', stop); test(';', stop);
} }
@ -220,9 +220,9 @@ static Symbol dclglobal(int sclass, char *id, Type ty, Coordinate *pos) {
if (!isfunc(ty) && p->defined && t == '=') if (!isfunc(ty) && p->defined && t == '=')
error("redefinition of `%s' previously defined at %w\n", p->name, &p->src); error("redefinition of `%s' previously defined at %w\n", p->name, &p->src);
if (p->sclass == EXTERN && sclass == STATIC if ((p->sclass == EXTERN && sclass == STATIC)
|| p->sclass == STATIC && sclass == AUTO || (p->sclass == STATIC && sclass == AUTO)
|| p->sclass == AUTO && sclass == STATIC) || (p->sclass == AUTO && sclass == STATIC))
warning("inconsistent linkage for `%s' previously declared at %w\n", p->name, &p->src); warning("inconsistent linkage for `%s' previously declared at %w\n", p->name, &p->src);
} }
@ -416,7 +416,7 @@ static Symbol *parameters(Type fty) {
error("missing parameter type\n"); error("missing parameter type\n");
n++; n++;
ty = dclr(specifier(&sclass), &id, NULL, 1); ty = dclr(specifier(&sclass), &id, NULL, 1);
if ( ty == voidtype && (ty1 || id) if ( (ty == voidtype && (ty1 || id))
|| ty1 == voidtype) || ty1 == voidtype)
error("illegal formal parameter types\n"); error("illegal formal parameter types\n");
if (id == NULL) if (id == NULL)
@ -736,10 +736,10 @@ static void funcdefn(int sclass, char *id, Type ty, Symbol params[], Coordinate
if (ty->u.f.oldstyle) if (ty->u.f.oldstyle)
warning("`%t %s()' is a non-ANSI definition\n", rty, id); warning("`%t %s()' is a non-ANSI definition\n", rty, id);
else if (!(rty == inttype else if (!(rty == inttype
&& (n == 0 && callee[0] == NULL && ((n == 0 && callee[0] == NULL)
|| n == 2 && callee[0]->type == inttype || (n == 2 && callee[0]->type == inttype
&& isptr(callee[1]->type) && callee[1]->type->type == charptype && isptr(callee[1]->type) && callee[1]->type->type == charptype
&& !variadic(ty)))) && !variadic(ty)))))
warning("`%s' is a non-ANSI definition\n", typestring(ty, id)); warning("`%s' is a non-ANSI definition\n", typestring(ty, id));
} }
p = lookup(id, identifiers); p = lookup(id, identifiers);
@ -853,7 +853,7 @@ void compound(int loop, struct swtch *swp, int lev) {
registers = append(retv, registers); registers = append(retv, registers);
} }
while (kind[t] == CHAR || kind[t] == STATIC while (kind[t] == CHAR || kind[t] == STATIC
|| istypename(t, tsym) && getchr() != ':') || (istypename(t, tsym) && getchr() != ':'))
decl(dcllocal); decl(dcllocal);
{ {
int i; int i;
@ -908,7 +908,7 @@ static void checkref(Symbol p, void *cl) {
p->type, p->name); p->type, p->name);
} }
if (p->sclass == AUTO if (p->sclass == AUTO
&& (p->scope == PARAM && regcount == 0 && ((p->scope == PARAM && regcount == 0)
|| p->scope >= LOCAL) || p->scope >= LOCAL)
&& !p->addressed && isscalar(p->type) && p->ref >= 3.0) && !p->addressed && isscalar(p->type) && p->ref >= 3.0)
p->sclass = REGISTER; p->sclass = REGISTER;
@ -933,13 +933,14 @@ static Symbol dcllocal(int sclass, char *id, Type ty, Coordinate *pos) {
sclass = AUTO; sclass = AUTO;
} }
q = lookup(id, identifiers); q = lookup(id, identifiers);
if (q && q->scope >= level if ((q && q->scope >= level)
|| q && q->scope == PARAM && level == LOCAL) || (q && q->scope == PARAM && level == LOCAL)) {
if (sclass == EXTERN && q->sclass == EXTERN if (sclass == EXTERN && q->sclass == EXTERN
&& eqtype(q->type, ty, 1)) && eqtype(q->type, ty, 1))
ty = compose(ty, q->type); ty = compose(ty, q->type);
else else
error("redeclaration of `%s' previously declared at %w\n", q->name, &q->src); error("redeclaration of `%s' previously declared at %w\n", q->name, &q->src);
}
assert(level >= LOCAL); assert(level >= LOCAL);
p = install(id, &identifiers, level, sclass == STATIC || sclass == EXTERN ? PERM : FUNC); p = install(id, &identifiers, level, sclass == STATIC || sclass == EXTERN ? PERM : FUNC);
@ -964,13 +965,14 @@ static Symbol dcllocal(int sclass, char *id, Type ty, Coordinate *pos) {
p->u.alias = q; break; p->u.alias = q; break;
case STATIC: (*IR->defsymbol)(p); case STATIC: (*IR->defsymbol)(p);
initglobal(p, 0); initglobal(p, 0);
if (!p->defined) if (!p->defined) {
if (p->type->size > 0) { if (p->type->size > 0) {
defglobal(p, BSS); defglobal(p, BSS);
(*IR->space)(p->type->size); (*IR->space)(p->type->size);
} else } else
error("undefined size for `%t %s'\n", error("undefined size for `%t %s'\n",
p->type, p->name); p->type, p->name);
}
p->defined = 1; break; p->defined = 1; break;
case REGISTER: registers = append(p, registers); case REGISTER: registers = append(p, registers);
regcount++; regcount++;
@ -987,7 +989,7 @@ static Symbol dcllocal(int sclass, char *id, Type ty, Coordinate *pos) {
t = gettok(); t = gettok();
definept(NULL); definept(NULL);
if (isscalar(p->type) if (isscalar(p->type)
|| isstruct(p->type) && t != '{') { || (isstruct(p->type) && t != '{')) {
if (t == '{') { if (t == '{') {
t = gettok(); t = gettok();
e = expr1(0); e = expr1(0);
@ -1027,7 +1029,7 @@ static void doextern(Symbol p, void *cl) {
} }
static void doglobal(Symbol p, void *cl) { static void doglobal(Symbol p, void *cl) {
if (!p->defined && (p->sclass == EXTERN if (!p->defined && (p->sclass == EXTERN
|| isfunc(p->type) && p->sclass == AUTO)) || (isfunc(p->type) && p->sclass == AUTO)))
(*IR->import)(p); (*IR->import)(p);
else if (!p->defined && !isfunc(p->type) else if (!p->defined && !isfunc(p->type)
&& (p->sclass == AUTO || p->sclass == STATIC)) { && (p->sclass == AUTO || p->sclass == STATIC)) {
@ -1077,7 +1079,7 @@ void checklab(Symbol p, void *cl) {
Type enumdcl(void) { Type enumdcl(void) {
char *tag; char *tag;
Type ty; Type ty;
Symbol p; Symbol p = {0};
Coordinate pos; Coordinate pos;
t = gettok(); t = gettok();

View file

@ -64,7 +64,7 @@ Tree call(Tree f, Type fty, Coordinate src) {
else else
q = cast(q, promote(q->type)); q = cast(q, promote(q->type));
} }
if (!IR->wants_argb && isstruct(q->type)) if (!IR->wants_argb && isstruct(q->type)) {
if (iscallb(q)) if (iscallb(q))
q = addrof(q); q = addrof(q);
else { else {
@ -73,6 +73,7 @@ Tree call(Tree f, Type fty, Coordinate src) {
q = tree(RIGHT, ptr(t1->type), q = tree(RIGHT, ptr(t1->type),
root(q), lvalue(idtree(t1))); root(q), lvalue(idtree(t1)));
} }
}
if (q->type->size == 0) if (q->type->size == 0)
q->type = inttype; q->type = inttype;
if (hascall(q)) if (hascall(q))
@ -223,15 +224,15 @@ static int isnullptr(Tree e) {
Type ty = unqual(e->type); Type ty = unqual(e->type);
return generic(e->op) == CNST return generic(e->op) == CNST
&& (ty->op == INT && e->u.v.i == 0 && ((ty->op == INT && e->u.v.i == 0)
|| ty->op == UNSIGNED && e->u.v.u == 0 || (ty->op == UNSIGNED && e->u.v.u == 0)
|| isvoidptr(ty) && e->u.v.p == NULL); || (isvoidptr(ty) && e->u.v.p == NULL));
} }
Tree eqtree(int op, Tree l, Tree r) { Tree eqtree(int op, Tree l, Tree r) {
Type xty = l->type, yty = r->type; Type xty = l->type, yty = r->type;
if (isptr(xty) && isnullptr(r) if ((isptr(xty) && isnullptr(r))
|| isptr(xty) && !isfunc(xty->type) && isvoidptr(yty) || (isptr(xty) && !isfunc(xty->type) && isvoidptr(yty))
|| (isptr(xty) && isptr(yty) || (isptr(xty) && isptr(yty)
&& eqtype(unqual(xty->type), unqual(yty->type), 1))) { && eqtype(unqual(xty->type), unqual(yty->type), 1))) {
Type ty = unsignedptr; Type ty = unsignedptr;
@ -239,8 +240,8 @@ Tree eqtree(int op, Tree l, Tree r) {
r = cast(r, ty); r = cast(r, ty);
return simplify(mkop(op,ty), inttype, l, r); return simplify(mkop(op,ty), inttype, l, r);
} }
if (isptr(yty) && isnullptr(l) if ((isptr(yty) && isnullptr(l))
|| isptr(yty) && !isfunc(yty->type) && isvoidptr(xty)) || (isptr(yty) && !isfunc(yty->type) && isvoidptr(xty)))
return eqtree(op, r, l); return eqtree(op, r, l);
return cmptree(op, l, r); return cmptree(op, l, r);
} }
@ -253,13 +254,13 @@ Type assign(Type xty, Tree e) {
xty = xty->type; xty = xty->type;
if (xty->size == 0 || yty->size == 0) if (xty->size == 0 || yty->size == 0)
return NULL; return NULL;
if ( isarith(xty) && isarith(yty) if ( (isarith(xty) && isarith(yty))
|| isstruct(xty) && xty == yty) || (isstruct(xty) && xty == yty))
return xty; return xty;
if (isptr(xty) && isnullptr(e)) if (isptr(xty) && isnullptr(e))
return xty; return xty;
if ((isvoidptr(xty) && isptr(yty) if (((isvoidptr(xty) && isptr(yty))
|| isptr(xty) && isvoidptr(yty)) || (isptr(xty) && isvoidptr(yty)))
&& ( (isconst(xty->type) || !isconst(yty->type)) && ( (isconst(xty->type) || !isconst(yty->type))
&& (isvolatile(xty->type) || !isvolatile(yty->type)))) && (isvolatile(xty->type) || !isvolatile(yty->type))))
return xty; return xty;
@ -273,8 +274,8 @@ Type assign(Type xty, Tree e) {
&& ( (isconst(xty->type) || !isconst(yty->type)) && ( (isconst(xty->type) || !isconst(yty->type))
&& (isvolatile(xty->type) || !isvolatile(yty->type)))) { && (isvolatile(xty->type) || !isvolatile(yty->type)))) {
Type lty = unqual(xty->type), rty = unqual(yty->type); Type lty = unqual(xty->type), rty = unqual(yty->type);
if (isenum(lty) && rty == inttype if ((isenum(lty) && rty == inttype)
|| isenum(rty) && lty == inttype) { || (isenum(rty) && lty == inttype)) {
if (Aflag >= 1) if (Aflag >= 1)
warning("assignment between `%t' and `%t' is compiler-dependent\n", warning("assignment between `%t' and `%t' is compiler-dependent\n",
xty, yty); xty, yty);
@ -302,13 +303,14 @@ Tree asgntree(int op, Tree l, Tree r) {
if (isptr(aty)) if (isptr(aty))
aty = unqual(aty)->type; aty = unqual(aty)->type;
if ( isconst(aty) if ( isconst(aty)
|| isstruct(aty) && unqual(aty)->u.sym->u.s.cfields) || (isstruct(aty) && unqual(aty)->u.sym->u.s.cfields)) {
if (isaddrop(l->op) if (isaddrop(l->op)
&& !l->u.sym->computed && !l->u.sym->generated) && !l->u.sym->computed && !l->u.sym->generated)
error("assignment to const identifier `%s'\n", error("assignment to const identifier `%s'\n",
l->u.sym->name); l->u.sym->name);
else else
error("assignment to const location\n"); error("assignment to const location\n");
}
if (l->op == FIELD) { if (l->op == FIELD) {
long n = 8*l->u.field->type->size - fieldsize(l->u.field); long n = 8*l->u.field->type->size - fieldsize(l->u.field);
if (n > 0 && isunsigned(l->u.field->type)) if (n > 0 && isunsigned(l->u.field->type))
@ -345,8 +347,8 @@ Tree condtree(Tree e, Tree l, Tree r) {
ty = xty; ty = xty;
else if (isnullptr(l) && isptr(yty)) else if (isnullptr(l) && isptr(yty))
ty = yty; ty = yty;
else if (isptr(xty) && !isfunc(xty->type) && isvoidptr(yty) else if ((isptr(xty) && !isfunc(xty->type) && isvoidptr(yty))
|| isptr(yty) && !isfunc(yty->type) && isvoidptr(xty)) || (isptr(yty) && !isfunc(yty->type) && isvoidptr(xty)))
ty = voidptype; ty = voidptype;
else if ((isptr(xty) && isptr(yty) else if ((isptr(xty) && isptr(yty)
&& eqtype(unqual(xty->type), unqual(yty->type), 1))) && eqtype(unqual(xty->type), unqual(yty->type), 1)))
@ -357,11 +359,11 @@ Tree condtree(Tree e, Tree l, Tree r) {
} }
if (isptr(ty)) { if (isptr(ty)) {
ty = unqual(unqual(ty)->type); ty = unqual(unqual(ty)->type);
if (isptr(xty) && isconst(unqual(xty)->type) if ((isptr(xty) && isconst(unqual(xty)->type))
|| isptr(yty) && isconst(unqual(yty)->type)) || (isptr(yty) && isconst(unqual(yty)->type)))
ty = qual(CONST, ty); ty = qual(CONST, ty);
if (isptr(xty) && isvolatile(unqual(xty)->type) if ((isptr(xty) && isvolatile(unqual(xty)->type))
|| isptr(yty) && isvolatile(unqual(yty)->type)) || (isptr(yty) && isvolatile(unqual(yty)->type)))
ty = qual(VOLATILE, ty); ty = qual(VOLATILE, ty);
ty = ptr(ty); ty = ptr(ty);
} }
@ -518,15 +520,15 @@ static Tree subtree(int op, Tree l, Tree r) {
void typeerror(int op, Tree l, Tree r) { void typeerror(int op, Tree l, Tree r) {
int i; int i;
static struct { int op; char *name; } ops[] = { static struct { int op; char *name; } ops[] = {
ASGN, "=", INDIR, "*", NEG, "-", {ASGN, "="}, {INDIR, "*"}, {NEG, "-"},
ADD, "+", SUB, "-", LSH, "<<", {ADD, "+"}, {SUB, "-"}, {LSH, "<<"},
MOD, "%", RSH, ">>", BAND, "&", {MOD, "%"}, {RSH, ">>"}, {BAND, "&"},
BCOM, "~", BOR, "|", BXOR, "^", {BCOM, "~"}, {BOR, "|"}, {BXOR, "^"},
DIV, "/", MUL, "*", EQ, "==", {DIV, "/"}, {MUL, "*"}, {EQ, "=="},
GE, ">=", GT, ">", LE, "<=", {GE, ">="}, {GT, ">"}, {LE, "<="},
LT, "<", NE, "!=", AND, "&&", {LT, "<"}, {NE, "!="}, {AND, "&&"},
NOT, "!", OR, "||", COND, "?:", {NOT, "!"}, {OR, "||"}, {COND, "?:"},
0, 0 {0, 0}
}; };
op = generic(op); op = generic(op);

View file

@ -230,13 +230,13 @@ static Tree unary(void) {
pty = p->type; pty = p->type;
if (isenum(pty)) if (isenum(pty))
pty = pty->type; pty = pty->type;
if (isarith(pty) && isarith(ty) if ((isarith(pty) && isarith(ty))
|| isptr(pty) && isptr(ty)) { || (isptr(pty) && isptr(ty))) {
explicitCast++; explicitCast++;
p = cast(p, ty); p = cast(p, ty);
explicitCast--; explicitCast--;
} else if (isptr(pty) && isint(ty) } else if ((isptr(pty) && isint(ty))
|| isint(pty) && isptr(ty)) { || (isint(pty) && isptr(ty))) {
if (Aflag >= 1 && ty->size < pty->size) if (Aflag >= 1 && ty->size < pty->size)
warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, ty); warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, ty);
@ -278,11 +278,12 @@ static Tree postfix(Tree p) {
Tree q; Tree q;
t = gettok(); t = gettok();
q = expr(']'); q = expr(']');
if (YYnull) if (YYnull) {
if (isptr(p->type)) if (isptr(p->type))
p = nullcheck(p); p = nullcheck(p);
else if (isptr(q->type)) else if (isptr(q->type))
q = nullcheck(q); q = nullcheck(q);
}
p = (*optree['+'])(ADD, pointer(p), pointer(q)); p = (*optree['+'])(ADD, pointer(p), pointer(q));
if (isptr(p->type) && isarray(p->type->type)) if (isptr(p->type) && isarray(p->type->type))
p = retype(p, p->type->type); p = retype(p, p->type->type);
@ -497,12 +498,13 @@ Type binary(Type xty, Type yty) {
xx(unsignedlonglong); xx(unsignedlonglong);
xx(longlong); xx(longlong);
xx(unsignedlong); xx(unsignedlong);
if (xty == longtype && yty == unsignedtype if ((xty == longtype && yty == unsignedtype)
|| xty == unsignedtype && yty == longtype) || (xty == unsignedtype && yty == longtype)) {
if (longtype->size > unsignedtype->size) if (longtype->size > unsignedtype->size)
return longtype; return longtype;
else else
return unsignedlong; return unsignedlong;
}
xx(longtype); xx(longtype);
xx(unsignedtype); xx(unsignedtype);
return inttype; return inttype;
@ -618,8 +620,8 @@ Tree cast(Tree p, Type type) {
if (src->op != dst->op) if (src->op != dst->op)
p = simplify(CVP, dst, p, NULL); p = simplify(CVP, dst, p, NULL);
else { else {
if (isfunc(src->type) && !isfunc(dst->type) if ((isfunc(src->type) && !isfunc(dst->type))
|| !isfunc(src->type) && isfunc(dst->type)) || (!isfunc(src->type) && isfunc(dst->type)))
warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, type); warning("conversion from `%t' to `%t' is compiler dependent\n", p->type, type);
if (src->size != dst->size) if (src->size != dst->size)

View file

@ -368,7 +368,7 @@ static unsigned emitasm(Node p, int nt) {
void emit(Node p) { void emit(Node p) {
for (; p; p = p->x.next) { for (; p; p = p->x.next) {
assert(p->x.registered); assert(p->x.registered);
if (p->x.equatable && requate(p) || moveself(p)) if ((p->x.equatable && requate(p)) || moveself(p))
; ;
else else
(*emitter)(p, p->x.inst); (*emitter)(p, p->x.inst);

View file

@ -81,7 +81,7 @@ static int initarray(int len, Type ty, int lev) {
do { do {
initializer(ty, lev); initializer(ty, lev);
n += ty->size; n += ty->size;
if (len > 0 && n >= len || t != ',') if ((len > 0 && n >= len) || t != ',')
break; break;
t = gettok(); t = gettok();
} while (t != '}'); } while (t != '}');
@ -99,7 +99,7 @@ static int initchar(int len, Type ty) {
(*IR->defstring)(inttype->size, buf); (*IR->defstring)(inttype->size, buf);
s = buf; s = buf;
} }
if (len > 0 && n >= len || t != ',') if ((len > 0 && n >= len) || t != ',')
break; break;
t = gettok(); t = gettok();
} while (t != '}'); } while (t != '}');
@ -123,9 +123,9 @@ static int initfields(Field p, Field q) {
do { do {
i = initvalue(inttype)->u.v.i; i = initvalue(inttype)->u.v.i;
if (fieldsize(p) < 8*p->type->size) { if (fieldsize(p) < 8*p->type->size) {
if (p->type == inttype && if ((p->type == inttype &&
(i < -(int)(fieldmask(p)>>1)-1 || i > (int)(fieldmask(p)>>1)) (i < -(int)(fieldmask(p)>>1)-1 || i > (int)(fieldmask(p)>>1)))
|| p->type == unsignedtype && (i&~fieldmask(p)) != 0) || (p->type == unsignedtype && (i&~fieldmask(p)) != 0))
warning("initializer exceeds bit-field width\n"); warning("initializer exceeds bit-field width\n");
i &= fieldmask(p); i &= fieldmask(p);
} }
@ -185,7 +185,7 @@ static int initstruct(int len, Type ty, int lev) {
(*IR->space)(a - n%a); (*IR->space)(a - n%a);
n = roundup(n, a); n = roundup(n, a);
} }
if (len > 0 && n >= len || t != ',') if ((len > 0 && n >= len) || t != ',')
break; break;
t = gettok(); t = gettok();
} while (t != '}'); } while (t != '}');

View file

@ -4,5 +4,4 @@ void init(int argc, char *argv[]) {
{extern void prof_init(int, char *[]); prof_init(argc, argv);} {extern void prof_init(int, char *[]); prof_init(argc, argv);}
{extern void trace_init(int, char *[]); trace_init(argc, argv);} {extern void trace_init(int, char *[]); trace_init(argc, argv);}
{extern void type_init(int, char *[]); type_init(argc, argv);} {extern void type_init(int, char *[]); type_init(argc, argv);}
{extern void x86linux_init(int, char *[]); x86linux_init(argc, argv);}
} }

View file

@ -125,10 +125,11 @@ static void resynch(void) {
} else if (Aflag >= 2 && *cp != '\n') } else if (Aflag >= 2 && *cp != '\n')
warning("unrecognized control line\n"); warning("unrecognized control line\n");
while (*cp) while (*cp)
if (*cp++ == '\n') if (*cp++ == '\n') {
if (cp == limit + 1) if (cp == limit + 1)
nextline(); nextline();
else else
break; break;
}
} }

View file

@ -685,17 +685,18 @@ int gettok(void) {
} }
goto id; goto id;
default: default:
if ((map[cp[-1]]&BLANK) == 0) if ((map[cp[-1]]&BLANK) == 0) {
if (cp[-1] < ' ' || cp[-1] >= 0177) if (cp[-1] < ' ' || cp[-1] >= 0177)
error("illegal character `\\0%o'\n", cp[-1]); error("illegal character `\\0%o'\n", cp[-1]);
else else
error("illegal character `%c'\n", cp[-1]); error("illegal character `%c'\n", cp[-1]);
} }
} }
}
} }
static Symbol icon(unsigned long n, int overflow, int base) { static Symbol icon(unsigned long n, int overflow, int base) {
if ((*cp=='u'||*cp=='U') && (cp[1]=='l'||cp[1]=='L') if (((*cp=='u'||*cp=='U') && (cp[1]=='l'||cp[1]=='L'))
|| (*cp=='l'||*cp=='L') && (cp[1]=='u'||cp[1]=='U')) { || ((*cp=='l'||*cp=='L') && (cp[1]=='u'||cp[1]=='U'))) {
tval.type = unsignedlong; tval.type = unsignedlong;
cp += 2; cp += 2;
} else if (*cp == 'u' || *cp == 'U') { } else if (*cp == 'u' || *cp == 'U') {

View file

@ -29,16 +29,16 @@ static void I(stabtype)(Symbol p) {}
Interface nullIR = { Interface nullIR = {
1, 1, 0, /* char */ {1, 1, 0}, /* char */
2, 2, 0, /* short */ {2, 2, 0}, /* short */
4, 4, 0, /* int */ {4, 4, 0}, /* int */
8, 8, 1, /* long */ {8, 8, 1}, /* long */
8 ,8, 1, /* long long */ {8 ,8, 1}, /* long long */
4, 4, 1, /* float */ {4, 4, 1}, /* float */
8, 8, 1, /* double */ {8, 8, 1}, /* double */
16,16,1, /* long double */ {16,16,1}, /* long double */
4, 4, 0, /* T* */ {4, 4, 0}, /* T* */
0, 4, 0, /* struct */ {0, 4, 0}, /* struct */
1, /* little_endian */ 1, /* little_endian */
0, /* mulops_calls */ 0, /* mulops_calls */
0, /* wants_callb */ 0, /* wants_callb */

View file

@ -5,7 +5,7 @@ static char *outs(const char *str, FILE *f, char *bp) {
if (f) if (f)
fputs(str, f); fputs(str, f);
else else
while (*bp = *str++) while ((*bp = *str++))
bp++; bp++;
return bp; return bp;
} }
@ -95,9 +95,10 @@ void vfprint(FILE *f, char *bp, const char *fmt, va_list ap) {
case 'c': if (f) fputc(va_arg(ap, int), f); else *bp++ = va_arg(ap, int); break; case 'c': if (f) fputc(va_arg(ap, int), f); else *bp++ = va_arg(ap, int); break;
case 'S': { char *s = va_arg(ap, char *); case 'S': { char *s = va_arg(ap, char *);
int n = va_arg(ap, int); int n = va_arg(ap, int);
if (s) if (s) {
for ( ; n-- > 0; s++) for ( ; n-- > 0; s++)
if (f) (void)putc(*s, f); else *bp++ = *s; if (f) (void)putc(*s, f); else *bp++ = *s;
}
} break; } break;
case 'k': { int t = va_arg(ap, int); case 'k': { int t = va_arg(ap, int);
static char *tokens[] = { static char *tokens[] = {

View file

@ -203,7 +203,7 @@ void prof_init(int argc, char *argv[]) {
return; return;
inited = 1; inited = 1;
type_init(argc, argv); type_init(argc, argv);
if (IR) if (IR) {
for (i = 1; i < argc; i++) for (i = 1; i < argc; i++)
if (strncmp(argv[i], "-a", 2) == 0) { if (strncmp(argv[i], "-a", 2) == 0) {
if (ncalled == -1 if (ncalled == -1
@ -224,4 +224,5 @@ void prof_init(int argc, char *argv[]) {
attach((Apply)bbincr, YYcounts, &events.points); attach((Apply)bbincr, YYcounts, &events.points);
} }
} }
}
} }

View file

@ -150,9 +150,9 @@ int findcount(char *file, int x, int y) {
struct count *c = cursor->counts; struct count *c = cursor->counts;
for (l = 0, u = cursor->count - 1; l <= u; ) { for (l = 0, u = cursor->count - 1; l <= u; ) {
int k = (l + u)/2; int k = (l + u)/2;
if (c[k].y > y || c[k].y == y && c[k].x > x) if (c[k].y > y || (c[k].y == y && c[k].x > x))
u = k - 1; u = k - 1;
else if (c[k].y < y || c[k].y == y && c[k].x < x) else if (c[k].y < y || (c[k].y == y && c[k].x < x))
l = k + 1; l = k + 1;
else else
return c[k].count; return c[k].count;

View file

@ -53,10 +53,10 @@ int needconst;
int explicitCast; int explicitCast;
static int addi(long x, long y, long min, long max, int needconst) { static int addi(long x, long y, long min, long max, int needconst) {
int cond = x == 0 || y == 0 int cond = x == 0 || y == 0
|| x < 0 && y < 0 && x >= min - y || (x < 0 && y < 0 && x >= min - y)
|| x < 0 && y > 0 || (x < 0 && y > 0)
|| x > 0 && y < 0 || (x > 0 && y < 0)
|| x > 0 && y > 0 && x <= max - y; || (x > 0 && y > 0 && x <= max - y);
if (!cond && needconst) { if (!cond && needconst) {
warning("overflow in constant expression\n"); warning("overflow in constant expression\n");
cond = 1; cond = 1;
@ -68,10 +68,10 @@ static int addi(long x, long y, long min, long max, int needconst) {
static int addd(double x, double y, double min, double max, int needconst) { static int addd(double x, double y, double min, double max, int needconst) {
int cond = x == 0 || y == 0 int cond = x == 0 || y == 0
|| x < 0 && y < 0 && x >= min - y || (x < 0 && y < 0 && x >= min - y)
|| x < 0 && y > 0 || (x < 0 && y > 0)
|| x > 0 && y < 0 || (x > 0 && y < 0)
|| x > 0 && y > 0 && x <= max - y; || (x > 0 && y > 0 && x <= max - y);
if (!cond && needconst) { if (!cond && needconst) {
warning("overflow in constant expression\n"); warning("overflow in constant expression\n");
cond = 1; cond = 1;
@ -146,11 +146,11 @@ static int divd(double x, double y, double min, double max, int needconst) {
/* mul[id] - return 1 if min <= x*y <= max, 0 otherwise */ /* mul[id] - return 1 if min <= x*y <= max, 0 otherwise */
static int muli(long x, long y, long min, long max, int needconst) { static int muli(long x, long y, long min, long max, int needconst) {
int cond = x > -1 && x <= 1 || y > -1 && y <= 1 int cond = (x > -1 && x <= 1) || (y > -1 && y <= 1)
|| x < 0 && y < 0 && -x <= max/-y || (x < 0 && y < 0 && -x <= max/-y)
|| x < 0 && y > 0 && x >= min/y || (x < 0 && y > 0 && x >= min/y)
|| x > 0 && y < 0 && y >= min/x || (x > 0 && y < 0 && y >= min/x)
|| x > 0 && y > 0 && x <= max/y; || (x > 0 && y > 0 && x <= max/y);
if (!cond && needconst) { if (!cond && needconst) {
warning("overflow in constant expression\n"); warning("overflow in constant expression\n");
cond = 1; cond = 1;
@ -161,11 +161,11 @@ static int muli(long x, long y, long min, long max, int needconst) {
} }
static int muld(double x, double y, double min, double max, int needconst) { static int muld(double x, double y, double min, double max, int needconst) {
int cond = x >= -1 && x <= 1 || y >= -1 && y <= 1 int cond = (x >= -1 && x <= 1) || (y >= -1 && y <= 1)
|| x < 0 && y < 0 && -x <= max/-y || (x < 0 && y < 0 && -x <= max/-y)
|| x < 0 && y > 0 && x >= min/y || (x < 0 && y > 0 && x >= min/y)
|| x > 0 && y < 0 && y >= min/x || (x > 0 && y < 0 && y >= min/x)
|| x > 0 && y > 0 && x <= max/y; || (x > 0 && y > 0 && x <= max/y);
if (!cond && needconst) { if (!cond && needconst) {
warning("overflow in constant expression\n"); warning("overflow in constant expression\n");
cond = 1; cond = 1;
@ -204,7 +204,6 @@ int intexpr(int tok, int n) {
} }
Tree simplify(int op, Type ty, Tree l, Tree r) { Tree simplify(int op, Type ty, Tree l, Tree r) {
int n; int n;
Tree p;
if (optype(op) == 0) if (optype(op) == 0)
op = mkop(op, ty); op = mkop(op, ty);
@ -256,13 +255,14 @@ Tree simplify(int op, Type ty, Tree l, Tree r) {
break; break;
case CVF+F: { case CVF+F: {
float d; float d;
if (l->op == CNST+F) if (l->op == CNST+F) {
if (l->u.v.d < ty->u.sym->u.limits.min.d) if (l->u.v.d < ty->u.sym->u.limits.min.d)
d = ty->u.sym->u.limits.min.d; d = ty->u.sym->u.limits.min.d;
else if (l->u.v.d > ty->u.sym->u.limits.max.d) else if (l->u.v.d > ty->u.sym->u.limits.max.d)
d = ty->u.sym->u.limits.max.d; d = ty->u.sym->u.limits.max.d;
else else
d = l->u.v.d; d = l->u.v.d;
}
xcvtcnst(F,l->u.v.d,ty,d,(long double)d); xcvtcnst(F,l->u.v.d,ty,d,(long double)d);
break; break;
} }
@ -308,14 +308,14 @@ Tree simplify(int op, Type ty, Tree l, Tree r) {
identity(r,retype(l,ty),I,i,0); identity(r,retype(l,ty),I,i,0);
identity(r,retype(l,ty),U,u,0); identity(r,retype(l,ty),U,u,0);
if (isaddrop(l->op) if (isaddrop(l->op)
&& (r->op == CNST+I && r->u.v.i <= longtype->u.sym->u.limits.max.i && ((r->op == CNST+I && r->u.v.i <= longtype->u.sym->u.limits.max.i
&& r->u.v.i >= longtype->u.sym->u.limits.min.i && r->u.v.i >= longtype->u.sym->u.limits.min.i)
|| r->op == CNST+U && r->u.v.u <= longtype->u.sym->u.limits.max.i)) || (r->op == CNST+U && r->u.v.u <= longtype->u.sym->u.limits.max.i)))
return addrtree(l, cast(r, longtype)->u.v.i, ty); return addrtree(l, cast(r, longtype)->u.v.i, ty);
if (l->op == ADD+P && isaddrop(l->kids[1]->op) if (l->op == ADD+P && isaddrop(l->kids[1]->op)
&& (r->op == CNST+I && r->u.v.i <= longtype->u.sym->u.limits.max.i && ((r->op == CNST+I && r->u.v.i <= longtype->u.sym->u.limits.max.i
&& r->u.v.i >= longtype->u.sym->u.limits.min.i && r->u.v.i >= longtype->u.sym->u.limits.min.i)
|| r->op == CNST+U && r->u.v.u <= longtype->u.sym->u.limits.max.i)) || (r->op == CNST+U && r->u.v.u <= longtype->u.sym->u.limits.max.i)))
return simplify(ADD+P, ty, l->kids[0], return simplify(ADD+P, ty, l->kids[0],
addrtree(l->kids[1], cast(r, longtype)->u.v.i, ty)); addrtree(l->kids[1], cast(r, longtype)->u.v.i, ty));
if ((l->op == ADD+I || l->op == SUB+I) if ((l->op == ADD+I || l->op == SUB+I)
@ -385,9 +385,9 @@ Tree simplify(int op, Type ty, Tree l, Tree r) {
break; break;
case DIV+I: case DIV+I:
identity(r,l,I,i,1); identity(r,l,I,i,1);
if (r->op == CNST+I && r->u.v.i == 0 if ((r->op == CNST+I && r->u.v.i == 0)
|| l->op == CNST+I && l->u.v.i == ty->u.sym->u.limits.min.i || (l->op == CNST+I && l->u.v.i == ty->u.sym->u.limits.min.i
&& r->op == CNST+I && r->u.v.i == -1) && r->op == CNST+I && r->u.v.i == -1))
break; break;
xfoldcnst(I,i,/,divi); xfoldcnst(I,i,/,divi);
break; break;
@ -465,9 +465,9 @@ Tree simplify(int op, Type ty, Tree l, Tree r) {
case MOD+I: case MOD+I:
if (r->op == CNST+I && r->u.v.i == 1) /* l%1 => (l,0) */ if (r->op == CNST+I && r->u.v.i == 1) /* l%1 => (l,0) */
return tree(RIGHT, ty, root(l), cnsttree(ty, 0L)); return tree(RIGHT, ty, root(l), cnsttree(ty, 0L));
if (r->op == CNST+I && r->u.v.i == 0 if ((r->op == CNST+I && r->u.v.i == 0)
|| l->op == CNST+I && l->u.v.i == ty->u.sym->u.limits.min.i || (l->op == CNST+I && l->u.v.i == ty->u.sym->u.limits.min.i
&& r->op == CNST+I && r->u.v.i == -1) && r->op == CNST+I && r->u.v.i == -1))
break; break;
xfoldcnst(I,i,%,divi); xfoldcnst(I,i,%,divi);
break; break;

View file

@ -201,9 +201,7 @@ void stabblock(int brace, int lev, Symbol *p) {
if (brace == '{') if (brace == '{')
while (*p) while (*p)
stabsym(*p++); stabsym(*p++);
if (IR == &sparcIR) {
print(".stabd 0x%x,0,%d\n", brace == '{' ? N_LBRAC : N_RBRAC, lev);
else {
int lab = genlabel(1); int lab = genlabel(1);
print(".stabn 0x%x,0,%d,%s%d-%s\n", brace == '{' ? N_LBRAC : N_RBRAC, lev, print(".stabn 0x%x,0,%d,%s%d-%s\n", brace == '{' ? N_LBRAC : N_RBRAC, lev,
stabprefix, lab, cfunc->x.name); stabprefix, lab, cfunc->x.name);
@ -252,9 +250,7 @@ void stabline(Coordinate *cp) {
print("%s%d:\n", stabprefix, lab); print("%s%d:\n", stabprefix, lab);
currentfile = cp->file; currentfile = cp->file;
} }
if (IR == &sparcIR) {
print(".stabd 0x%x,0,%d\n", N_SLINE, cp->y);
else {
int lab = genlabel(1); int lab = genlabel(1);
print(".stabn 0x%x,0,%d,%s%d-%s\n", N_SLINE, cp->y, print(".stabn 0x%x,0,%d,%s%d-%s\n", N_SLINE, cp->y,
stabprefix, lab, cfunc->x.name); stabprefix, lab, cfunc->x.name);
@ -280,7 +276,7 @@ void stabsym(Symbol p) {
sz = p->type->type->size; sz = p->type->type->size;
} else } else
tc = dbxtype(p->type); tc = dbxtype(p->type);
if (p->sclass == AUTO && p->scope == GLOBAL || p->sclass == EXTERN) { if ((p->sclass == AUTO && p->scope == GLOBAL) || p->sclass == EXTERN) {
print(".stabs \"%s:G", p->name); print(".stabs \"%s:G", p->name);
code = N_GSYM; code = N_GSYM;
} else if (p->sclass == STATIC) { } else if (p->sclass == STATIC) {

View file

@ -37,7 +37,6 @@ Code code(int kind) {
return cp; return cp;
} }
int reachable(int kind) { int reachable(int kind) {
Code cp;
if (kind > Start) { if (kind > Start) {
Code cp; Code cp;

View file

@ -296,7 +296,6 @@ Symbol mksymbol(int sclass, const char *name, Type ty) {
/* vtoa - return string for the constant v of type ty */ /* vtoa - return string for the constant v of type ty */
char *vtoa(Type ty, Value v) { char *vtoa(Type ty, Value v) {
char buf[50];
ty = unqual(ty); ty = unqual(ty);
switch (ty->op) { switch (ty->op) {

View file

@ -404,16 +404,16 @@ static void I(stabsym)(Symbol p) {}
static void I(stabtype)(Symbol p) {} static void I(stabtype)(Symbol p) {}
Interface symbolicIR = { Interface symbolicIR = {
1, 1, 0, /* char */ {1, 1, 0}, /* char */
2, 2, 0, /* short */ {2, 2, 0}, /* short */
4, 4, 0, /* int */ {4, 4, 0}, /* int */
4, 4, 0, /* long */ {4, 4, 0}, /* long */
4, 4, 0, /* long long */ {4, 4, 0}, /* long long */
4, 4, 1, /* float */ {4, 4, 1}, /* float */
8, 8, 1, /* double */ {8, 8, 1}, /* double */
8, 8, 1, /* long double */ {8, 8, 1}, /* long double */
4, 4, 0, /* T* */ {4, 4, 0}, /* T* */
0, 4, 0, /* struct */ {0, 4, 0}, /* struct */
0, /* little_endian */ 0, /* little_endian */
0, /* mulops_calls */ 0, /* mulops_calls */
0, /* wants_callb */ 0, /* wants_callb */
@ -449,16 +449,16 @@ Interface symbolicIR = {
}; };
Interface symbolic64IR = { Interface symbolic64IR = {
1, 1, 0, /* char */ {1, 1, 0}, /* char */
2, 2, 0, /* short */ {2, 2, 0}, /* short */
4, 4, 0, /* int */ {4, 4, 0}, /* int */
8, 8, 0, /* long */ {8, 8, 0}, /* long */
8, 8, 0, /* long long */ {8, 8, 0}, /* long long */
4, 4, 1, /* float */ {4, 4, 1}, /* float */
8, 8, 1, /* double */ {8, 8, 1}, /* double */
8, 8, 1, /* long double */ {8, 8, 1}, /* long double */
8, 8, 0, /* T* */ {8, 8, 0}, /* T* */
0, 1, 0, /* struct */ {0, 1, 0}, /* struct */
1, /* little_endian */ 1, /* little_endian */
0, /* mulops_calls */ 0, /* mulops_calls */
0, /* wants_callb */ 0, /* wants_callb */

View file

@ -8,7 +8,7 @@ static Symbol frameno; /* local holding frame number */
/* appendstr - append str to the evolving format string, expanding it if necessary */ /* appendstr - append str to the evolving format string, expanding it if necessary */
static void appendstr(char *str) { static void appendstr(char *str) {
do do
if (fp == fmtend) if (fp == fmtend) {
if (fp) { if (fp) {
char *s = allocate(2*(fmtend - fmt), FUNC); char *s = allocate(2*(fmtend - fmt), FUNC);
strncpy(s, fmt, fmtend - fmt); strncpy(s, fmt, fmtend - fmt);
@ -19,6 +19,7 @@ static void appendstr(char *str) {
fp = fmt = allocate(80, FUNC); fp = fmt = allocate(80, FUNC);
fmtend = fmt + 80; fmtend = fmt + 80;
} }
}
while ((*fp++ = *str++) != 0); while ((*fp++ = *str++) != 0);
fp--; fp--;
} }

View file

@ -233,8 +233,8 @@ Type qual(int op, Type ty) {
ty->align, NULL); ty->align, NULL);
else if (isfunc(ty)) else if (isfunc(ty))
warning("qualified function type ignored\n"); warning("qualified function type ignored\n");
else if (isconst(ty) && op == CONST else if ((isconst(ty) && op == CONST)
|| isvolatile(ty) && op == VOLATILE) || (isvolatile(ty) && op == VOLATILE))
error("illegal type `%k %t'\n", op, ty); error("illegal type `%k %t'\n", op, ty);
else { else {
if (isqual(ty)) { if (isqual(ty)) {
@ -276,7 +276,7 @@ Type newstruct(int op, char *tag) {
tag = stringd(genlabel(1)); tag = stringd(genlabel(1));
else else
if ((p = lookup(tag, types)) != NULL && (p->scope == level if ((p = lookup(tag, types)) != NULL && (p->scope == level
|| p->scope == PARAM && level == PARAM+1)) { || (p->scope == PARAM && level == PARAM+1))) {
if (p->type->op == op && !p->defined) if (p->type->op == op && !p->defined)
return p->type; return p->type;
error("redefinition of `%s' previously defined at %w\n", error("redefinition of `%s' previously defined at %w\n",
@ -400,7 +400,7 @@ Type compose(Type ty1, Type ty2) {
case CONST: case VOLATILE: case CONST: case VOLATILE:
return qual(ty1->op, compose(ty1->type, ty2->type)); return qual(ty1->op, compose(ty1->type, ty2->type));
case ARRAY: { Type ty = compose(ty1->type, ty2->type); case ARRAY: { Type ty = compose(ty1->type, ty2->type);
if (ty1->size && (ty1->type->size && ty2->size == 0 || ty1->size == ty2->size)) if (ty1->size && ((ty1->type->size && ty2->size == 0) || ty1->size == ty2->size))
return array(ty, ty1->size/ty1->type->size, ty1->align); return array(ty, ty1->size/ty1->type->size, ty1->align);
if (ty2->size && ty2->type->size && ty1->size == 0) if (ty2->size && ty2->type->size && ty1->size == 0)
return array(ty, ty2->size/ty2->type->size, ty2->align); return array(ty, ty2->size/ty2->type->size, ty2->align);

View file

@ -1,7 +1,7 @@
# yeah, couldn't do more simple really # yeah, couldn't do more simple really
CC=gcc CC=gcc
CFLAGS=-g -Wall CFLAGS=-O2 -Wall -Werror -fno-strict-aliasing
default: q3asm default: q3asm