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)
Node n1, n2, n3, tmp;
Prog *p1;
uint32 w;
uint64 v;
Type *t;
if(debug['g']) {
......@@ -344,6 +345,12 @@ agen(Node *n, Node *res)
cgen_aret(n, res);
break;
case OS2I:
case OI2I:
case OI2S:
agen_inter(n, res);
break;
case OINDEXPTR:
w = n->type->width;
if(nr->addable)
......@@ -364,12 +371,6 @@ agen(Node *n, Node *res)
cgen(nr, &n1);
goto index;
case OS2I:
case OI2I:
case OI2S:
agen_inter(n, res);
break;
case OINDEX:
w = n->type->width;
if(nr->addable)
......@@ -409,8 +410,7 @@ agen(Node *n, Node *res)
p1 = gbranch(optoas(OLT, types[TUINT32]), T);
nodconst(&n3, types[TUINT8], 5); // 5 is range trap
gins(AINT, &n3, N);
gins(ACALL, N, throwindex);
patch(p1, pc);
}
......@@ -431,12 +431,18 @@ agen(Node *n, Node *res)
gins(optoas(OCMP, types[TUINT32]), &n1, &n3);
p1 = gbranch(optoas(OLT, types[TUINT32]), T);
nodconst(&n3, types[TUINT8], 5); // 5 is range trap
gins(AINT, &n3, N);
gins(ACALL, N, throwindex);
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];
if(issigned[n1.type->etype])
t = types[TINT64];
......
......@@ -13,9 +13,6 @@ enum
AJMPX = AADDPD,
};
static Node* curfn;
static Node* newproc;
void
compile(Node *fn)
{
......@@ -26,14 +23,28 @@ compile(Node *fn)
if(newproc == N) {
newproc = nod(ONAME, N, N);
memset(newproc, 0, sizeof(*newproc));
newproc->op = ONAME;
newproc->sym = pkglookup("newproc", "sys");
newproc->class = PEXTERN;
newproc->addable = 1;
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)
return;
......@@ -69,8 +80,7 @@ if(newproc == N) {
checklabels();
if(curfn->type->outtuple != 0) {
nodconst(&nod1, types[TUINT8], 6); // 6 is opcode trap
gins(AINT, &nod1, N);
gins(ACALL, N, throwreturn);
}
pc->as = ARET; // overwrite AEND
......
......@@ -113,6 +113,10 @@ EXTERN Hist* hist;
EXTERN Prog zprog;
EXTERN Label* labellist;
EXTERN Label* findlab(Sym*);
EXTERN Node* curfn;
EXTERN Node* newproc;
EXTERN Node* throwindex;
EXTERN Node* throwreturn;
/*
* gen.c
......
......@@ -7,6 +7,8 @@ package foop // rename to avoid redeclaration
func mal(uint32) *any;
func breakpoint();
func throwindex();
func throwreturn();
func panicl(int32);
func printbool(bool);
......@@ -75,6 +77,8 @@ func exit(int32);
export
mal
breakpoint
throwindex
throwreturn
// print panic
panicl
......
This diff is collapsed.
......@@ -17,6 +17,10 @@ int
walkret(Node *n)
{
// until gri gets rid
// of the bugs on this
return 0;
loop:
if(n != N)
switch(n->op) {
......
......@@ -25,6 +25,18 @@ sys·panicl(int32 lno)
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
{
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