Skip to content

Commit

Permalink
cmd/7a: labels are local to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
4ad committed Jan 12, 2015
1 parent 3e6bf43 commit c244086
Show file tree
Hide file tree
Showing 4 changed files with 738 additions and 755 deletions.
1 change: 1 addition & 0 deletions src/cmd/7a/a.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ void newio(void);
void newfile(char*, int);
Sym* slookup(char*);
Sym* lookup(void);
Sym* labellookup(Sym*);
void settext(LSym*);
void syminit(Sym*);
int32 yylex(void);
Expand Down
21 changes: 6 additions & 15 deletions src/cmd/7a/a.y
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,11 @@ prog:
| prog line

line:
LLAB ':'
{
if($1->value != pc)
yyerror("redeclaration of %s", $1->name);
$1->value = pc;
}
line
| LNAME ':'
{
$1 = labellookup($1);
if($1->type == LLAB && $1->value != pc)
yyerror("redeclaration of %s", $1->labelname);
$1->type = LLAB;
$1->value = pc;
}
Expand Down Expand Up @@ -435,15 +431,10 @@ rel:
}
| LNAME offset
{
$1 = labellookup($1);
$$ = nullgen;
if(pass == 2)
yyerror("undefined label: %s", $1->name);
$$.type = D_BRANCH;
$$.offset = $2;
}
| LLAB offset
{
$$ = nullgen;
if(pass == 2 && $1->type != LLAB)
yyerror("undefined label: %s", $1->labelname);
$$.type = D_BRANCH;
$$.offset = $1->value + $2;
}
Expand Down

0 comments on commit c244086

Please sign in to comment.