Commit 904d4045 authored by Ken Thompson's avatar Ken Thompson

1 got rid if static 'fn wo return' test

2 added dynamic calls to throw for array bounds
  and 'fn wo return'
3 small optimization on index[constant]

R=r
OCL=15281
CL=15281
parent 7c9e2c2b
...@@ -301,6 +301,7 @@ agen(Node *n, Node *res) ...@@ -301,6 +301,7 @@ agen(Node *n, Node *res)
Node n1, n2, n3, tmp; Node n1, n2, n3, tmp;
Prog *p1; Prog *p1;
uint32 w; uint32 w;
uint64 v;
Type *t; Type *t;
if(debug['g']) { if(debug['g']) {
...@@ -344,6 +345,12 @@ agen(Node *n, Node *res) ...@@ -344,6 +345,12 @@ agen(Node *n, Node *res)
cgen_aret(n, res); cgen_aret(n, res);
break; break;
case OS2I:
case OI2I:
case OI2S:
agen_inter(n, res);
break;
case OINDEXPTR: case OINDEXPTR:
w = n->type->width; w = n->type->width;
if(nr->addable) if(nr->addable)
...@@ -364,12 +371,6 @@ agen(Node *n, Node *res) ...@@ -364,12 +371,6 @@ agen(Node *n, Node *res)
cgen(nr, &n1); cgen(nr, &n1);
goto index; goto index;
case OS2I:
case OI2I:
case OI2S:
agen_inter(n, res);
break;
case OINDEX: case OINDEX:
w = n->type->width; w = n->type->width;
if(nr->addable) if(nr->addable)
...@@ -409,8 +410,7 @@ agen(Node *n, Node *res) ...@@ -409,8 +410,7 @@ agen(Node *n, Node *res)
p1 = gbranch(optoas(OLT, types[TUINT32]), T); p1 = gbranch(optoas(OLT, types[TUINT32]), T);
nodconst(&n3, types[TUINT8], 5); // 5 is range trap gins(ACALL, N, throwindex);
gins(AINT, &n3, N);
patch(p1, pc); patch(p1, pc);
} }
...@@ -431,12 +431,18 @@ agen(Node *n, Node *res) ...@@ -431,12 +431,18 @@ agen(Node *n, Node *res)
gins(optoas(OCMP, types[TUINT32]), &n1, &n3); gins(optoas(OCMP, types[TUINT32]), &n1, &n3);
p1 = gbranch(optoas(OLT, types[TUINT32]), T); p1 = gbranch(optoas(OLT, types[TUINT32]), T);
gins(ACALL, N, throwindex);
nodconst(&n3, types[TUINT8], 5); // 5 is range trap
gins(AINT, &n3, N);
patch(p1, pc); patch(p1, pc);
} }
if(whatis(nr) == Wlitint) {
regfree(&n1);
v = mpgetfix(nr->val.u.xval);
nodconst(&n2, types[tptr], v*w);
gins(optoas(OADD, types[tptr]), &n2, res);
break;
}
t = types[TUINT64]; t = types[TUINT64];
if(issigned[n1.type->etype]) if(issigned[n1.type->etype])
t = types[TINT64]; t = types[TINT64];
......
...@@ -13,9 +13,6 @@ enum ...@@ -13,9 +13,6 @@ enum
AJMPX = AADDPD, AJMPX = AADDPD,
}; };
static Node* curfn;
static Node* newproc;
void void
compile(Node *fn) compile(Node *fn)
{ {
...@@ -26,14 +23,28 @@ compile(Node *fn) ...@@ -26,14 +23,28 @@ compile(Node *fn)
if(newproc == N) { if(newproc == N) {
newproc = nod(ONAME, N, N); newproc = nod(ONAME, N, N);
memset(newproc, 0, sizeof(*newproc));
newproc->op = ONAME;
newproc->sym = pkglookup("newproc", "sys"); newproc->sym = pkglookup("newproc", "sys");
newproc->class = PEXTERN; newproc->class = PEXTERN;
newproc->addable = 1; newproc->addable = 1;
newproc->ullman = 0; newproc->ullman = 0;
} }
if(throwindex == N) {
throwindex = nod(ONAME, N, N);
throwindex->sym = pkglookup("throwindex", "sys");
throwindex->class = PEXTERN;
throwindex->addable = 1;
throwindex->ullman = 0;
}
if(throwreturn == N) {
throwreturn = nod(ONAME, N, N);
throwreturn->sym = pkglookup("throwreturn", "sys");
throwreturn->class = PEXTERN;
throwreturn->addable = 1;
throwreturn->ullman = 0;
}
if(fn->nbody == N) if(fn->nbody == N)
return; return;
...@@ -69,8 +80,7 @@ if(newproc == N) { ...@@ -69,8 +80,7 @@ if(newproc == N) {
checklabels(); checklabels();
if(curfn->type->outtuple != 0) { if(curfn->type->outtuple != 0) {
nodconst(&nod1, types[TUINT8], 6); // 6 is opcode trap gins(ACALL, N, throwreturn);
gins(AINT, &nod1, N);
} }
pc->as = ARET; // overwrite AEND pc->as = ARET; // overwrite AEND
......
...@@ -113,6 +113,10 @@ EXTERN Hist* hist; ...@@ -113,6 +113,10 @@ EXTERN Hist* hist;
EXTERN Prog zprog; EXTERN Prog zprog;
EXTERN Label* labellist; EXTERN Label* labellist;
EXTERN Label* findlab(Sym*); EXTERN Label* findlab(Sym*);
EXTERN Node* curfn;
EXTERN Node* newproc;
EXTERN Node* throwindex;
EXTERN Node* throwreturn;
/* /*
* gen.c * gen.c
......
...@@ -7,6 +7,8 @@ package foop // rename to avoid redeclaration ...@@ -7,6 +7,8 @@ package foop // rename to avoid redeclaration
func mal(uint32) *any; func mal(uint32) *any;
func breakpoint(); func breakpoint();
func throwindex();
func throwreturn();
func panicl(int32); func panicl(int32);
func printbool(bool); func printbool(bool);
...@@ -75,6 +77,8 @@ func exit(int32); ...@@ -75,6 +77,8 @@ func exit(int32);
export export
mal mal
breakpoint breakpoint
throwindex
throwreturn
// print panic // print panic
panicl panicl
......
This diff is collapsed.
...@@ -17,6 +17,10 @@ int ...@@ -17,6 +17,10 @@ int
walkret(Node *n) walkret(Node *n)
{ {
// until gri gets rid
// of the bugs on this
return 0;
loop: loop:
if(n != N) if(n != N)
switch(n->op) { switch(n->op) {
......
...@@ -25,6 +25,18 @@ sys·panicl(int32 lno) ...@@ -25,6 +25,18 @@ sys·panicl(int32 lno)
sys·exit(2); sys·exit(2);
} }
void
sys·throwindex(void)
{
throw("index out of range");
}
void
sys·throwreturn(void)
{
throw("no return at end of a typed function");
}
enum enum
{ {
NHUNK = 20<<20, NHUNK = 20<<20,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment