summaryrefslogtreecommitdiff
path: root/src/cmd/gc/lex.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/gc/lex.c')
-rw-r--r--src/cmd/gc/lex.c97
1 files changed, 66 insertions, 31 deletions
diff --git a/src/cmd/gc/lex.c b/src/cmd/gc/lex.c
index 8c739391a..a50101c42 100644
--- a/src/cmd/gc/lex.c
+++ b/src/cmd/gc/lex.c
@@ -14,7 +14,6 @@
#define ungetc ccungetc
extern int yychar;
-int windows;
int yyprev;
int yylast;
@@ -61,7 +60,7 @@ static void
addexp(char *s)
{
int i;
-
+
for(i=0; exper[i].name != nil; i++) {
if(strcmp(exper[i].name, s) == 0) {
*exper[i].val = 1;
@@ -78,8 +77,10 @@ setexp(void)
{
char *f[20];
int i, nf;
-
- // The makefile #defines GOEXPERIMENT for us.
+
+ precisestack_enabled = 1; // on by default
+
+ // cmd/dist #defines GOEXPERIMENT for us.
nf = getfields(GOEXPERIMENT, f, nelem(f), 1, ",");
for(i=0; i<nf; i++)
addexp(f[i]);
@@ -165,6 +166,21 @@ fault(int s)
fatal("fault");
}
+#ifdef PLAN9
+void
+catcher(void *v, char *s)
+{
+ USED(v);
+
+ if(strncmp(s, "sys: trap: fault read", 21) == 0) {
+ if(nsavederrors + nerrors > 0)
+ errorexit();
+ fatal("fault");
+ }
+ noted(NDFLT);
+}
+#endif
+
void
doversion(void)
{
@@ -189,6 +205,24 @@ main(int argc, char *argv[])
signal(SIGSEGV, fault);
#endif
+#ifdef PLAN9
+ notify(catcher);
+ // Tell the FPU to handle all exceptions.
+ setfcr(FPPDBL|FPRNR);
+#endif
+ // Allow GOARCH=thestring or GOARCH=thestringsuffix,
+ // but not other values.
+ p = getgoarch();
+ if(strncmp(p, thestring, strlen(thestring)) != 0)
+ sysfatal("cannot use %cg with GOARCH=%s", thechar, p);
+ goarch = p;
+
+ linkarchinit();
+ ctxt = linknew(thelinkarch);
+ ctxt->diag = yyerror;
+ ctxt->bso = &bstdout;
+ Binit(&bstdout, 1, OWRITE);
+
localpkg = mkpkg(strlit(""));
localpkg->prefix = "\"\"";
@@ -229,8 +263,11 @@ main(int argc, char *argv[])
goroot = getgoroot();
goos = getgoos();
- goarch = thestring;
-
+
+ nacl = strcmp(goos, "nacl") == 0;
+ if(nacl)
+ flag_largemodel = 1;
+
setexp();
outfile = nil;
@@ -260,12 +297,16 @@ main(int argc, char *argv[])
flagstr("installsuffix", "pkg directory suffix", &flag_installsuffix);
flagcount("j", "debug runtime-initialized variables", &debug['j']);
flagcount("l", "disable inlining", &debug['l']);
+ flagcount("live", "debug liveness analysis", &debuglive);
flagcount("m", "print optimization decisions", &debug['m']);
+ flagcount("nolocalimports", "reject local (relative) imports", &nolocalimports);
flagstr("o", "obj: set output file", &outfile);
flagstr("p", "path: set expected package import path", &myimportpath);
+ flagcount("pack", "write package file instead of object file", &writearchive);
flagcount("r", "debug generated wrappers", &debug['r']);
flagcount("race", "enable race detector", &flag_race);
flagcount("s", "warn about composite literals that can be simplified", &debug['s']);
+ flagstr("trimpath", "prefix: remove prefix from recorded source file paths", &ctxt->trimpath);
flagcount("u", "reject unsafe code", &safemode);
flagcount("v", "increase debug verbosity", &debug['v']);
flagcount("w", "debug type checking", &debug['w']);
@@ -275,6 +316,7 @@ main(int argc, char *argv[])
flagcount("largemodel", "generate code that assumes a large memory model", &flag_largemodel);
flagparse(&argc, &argv, usage);
+ ctxt->debugasm = debug['S'];
if(argc < 1)
usage();
@@ -319,20 +361,6 @@ main(int argc, char *argv[])
sysfatal("unsupported setting GO386=%s", p);
}
- pathname = mal(1000);
- if(getwd(pathname, 999) == 0)
- strcpy(pathname, "/???");
-
- if(yy_isalpha(pathname[0]) && pathname[1] == ':') {
- // On Windows.
- windows = 1;
-
- // Canonicalize path by converting \ to / (Windows accepts both).
- for(p=pathname; *p; p++)
- if(*p == '\\')
- *p = '/';
- }
-
fmtinstallgo();
betypeinit();
if(widthptr == 0)
@@ -527,12 +555,13 @@ skiptopkgdef(Biobuf *b)
return 0;
if(memcmp(p, "!<arch>\n", 8) != 0)
return 0;
- /* symbol table is first; skip it */
+ /* symbol table may be first; skip it */
sz = arsize(b, "__.GOSYMDEF");
- if(sz < 0)
- return 0;
- Bseek(b, sz, 1);
- /* package export block is second */
+ if(sz >= 0)
+ Bseek(b, sz, 1);
+ else
+ Bseek(b, 8, 0);
+ /* package export block is next */
sz = arsize(b, "__.PKGDEF");
if(sz <= 0)
return 0;
@@ -560,7 +589,7 @@ islocalname(Strlit *name)
{
if(name->len >= 1 && name->s[0] == '/')
return 1;
- if(windows && name->len >= 3 &&
+ if(ctxt->windows && name->len >= 3 &&
yy_isalpha(name->s[0]) && name->s[1] == ':' && name->s[2] == '/')
return 1;
if(name->len >= 2 && strncmp(name->s, "./", 2) == 0)
@@ -581,7 +610,7 @@ findpkg(Strlit *name)
char *q, *suffix, *suffixsep;
if(islocalname(name)) {
- if(safemode)
+ if(safemode || nolocalimports)
return 0;
// try .a before .6. important for building libraries:
// if there is an array.6 in the array.a library,
@@ -702,7 +731,7 @@ importfile(Val *f, int line)
fakeimport();
return;
}
- prefix = pathname;
+ prefix = ctxt->pathname;
if(localimport != nil)
prefix = localimport;
cleanbuf = mal(strlen(prefix) + strlen(path->s) + 2);
@@ -760,7 +789,7 @@ importfile(Val *f, int line)
yyerror("import %s: not a go object file", file);
errorexit();
}
- q = smprint("%s %s %s %s", getgoos(), thestring, getgoversion(), expstring());
+ q = smprint("%s %s %s %s", getgoos(), getgoarch(), getgoversion(), expstring());
if(strcmp(p+10, q) != 0) {
yyerror("import %s: object is [%s] expected [%s]", file, p+10, q);
errorexit();
@@ -1528,7 +1557,7 @@ getlinepragma(void)
goto out;
// try to avoid allocating file name over and over
- for(h=hist; h!=H; h=h->link) {
+ for(h=ctxt->hist; h!=nil; h=h->link) {
if(h->name != nil && strcmp(h->name, lexbuf) == 0) {
linehist(h->name, n, 0);
goto out;
@@ -2143,14 +2172,18 @@ struct
} lexn[] =
{
LANDAND, "ANDAND",
+ LANDNOT, "ANDNOT",
LASOP, "ASOP",
LBREAK, "BREAK",
LCASE, "CASE",
LCHAN, "CHAN",
LCOLAS, "COLAS",
+ LCOMM, "<-",
LCONST, "CONST",
LCONTINUE, "CONTINUE",
+ LDDD, "...",
LDEC, "DEC",
+ LDEFAULT, "DEFAULT",
LDEFER, "DEFER",
LELSE, "ELSE",
LEQ, "EQ",
@@ -2177,6 +2210,7 @@ struct
LRANGE, "RANGE",
LRETURN, "RETURN",
LRSH, "RSH",
+ LSELECT, "SELECT",
LSTRUCT, "STRUCT",
LSWITCH, "SWITCH",
LTYPE, "TYPE",
@@ -2207,6 +2241,7 @@ struct
"LASOP", "op=",
"LBREAK", "break",
"LCASE", "case",
+ "LCHAN", "chan",
"LCOLAS", ":=",
"LCONST", "const",
"LCONTINUE", "continue",
@@ -2354,7 +2389,7 @@ mkpackage(char* pkgname)
if(outfile == nil) {
p = strrchr(infile, '/');
- if(windows) {
+ if(ctxt->windows) {
q = strrchr(infile, '\\');
if(q > p)
p = q;