}
void
-newlab(int op, Sym *s)
+newlab(int op, Sym *s, Node *stmt)
{
Label *lab;
lab->sym = s;
lab->op = op;
lab->label = pc;
+ lab->stmt = stmt;
}
void
for(l=labellist; l!=L; l=l->link) {
switch(l->op) {
- case OFOR:
case OLABEL:
// these are definitions -
s = l->sym;
if(m->sym != s)
continue;
switch(m->op) {
- case OFOR:
case OLABEL:
// these are definitions -
// look for redefinitions
yyerror("label %S not defined", l->sym);
}
-Label*
-findlab(Sym *s)
-{
- Label *l;
-
- for(l=labellist; l!=L; l=l->link) {
- if(l->sym != s)
- continue;
- if(l->op != OFOR)
- continue;
- return l;
- }
- return L;
-}
-
/*
* compile statements
*/
break;
case OLABEL:
- newlab(OLABEL, n->left->sym);
+ newlab(OLABEL, n->left->sym, n->right);
break;
case OGOTO:
- newlab(OGOTO, n->left->sym);
+ newlab(OGOTO, n->left->sym, N);
gjmp(P);
break;
continpc = pc;
// define break and continue labels
- if((lab = labellist) != L && lab->label == p3 && lab->op == OLABEL) {
+ if((lab = labellist) != L && lab->label == p3 && lab->op == OLABEL && lab->stmt == n) {
lab->breakpc = breakpc;
lab->continpc = continpc;
}
breakpc = gjmp(P); // break: goto done
// define break label
- if((lab = labellist) != L && lab->label == p3 && lab->op == OLABEL)
+ if((lab = labellist) != L && lab->label == p3 && lab->op == OLABEL && lab->stmt == n)
lab->breakpc = breakpc;
patch(p1, pc); // test:
breakpc = gjmp(P); // break: goto done
// define break label
- if((lab = labellist) != L && lab->label == p3 && lab->op == OLABEL)
+ if((lab = labellist) != L && lab->label == p3 && lab->op == OLABEL && lab->stmt == n)
lab->breakpc = breakpc;
patch(p1, pc); // test:
{
uchar op; // OGOTO/OLABEL
Sym* sym;
+ Node* stmt;
Prog* label; // pointer to code
Prog* breakpc; // pointer to code
Prog* continpc; // pointer to code
#define L ((Label*)0)
EXTERN Label* labellist;
-EXTERN Label* findlab(Sym*);
typedef struct Plist Plist;
struct Plist
void cgen_dcl(Node *n);
void cgen_proc(Node *n, int proc);
void checklabels(void);
-Label* findlab(Sym *s);
void gen(Node *n);
void genlist(NodeList *l);
-void newlab(int op, Sym *s);
+void newlab(int op, Sym *s, Node*);
Node* sysfunc(char *name);
Plist* newplist(void);