Skip to content

Commit c244086

Browse files
committedJan 12, 2015
cmd/7a: labels are local to functions
Replay of https://codereview.appspot.com/159670043/ Fixes golang#44
1 parent 3e6bf43 commit c244086

File tree

4 files changed

+738
-755
lines changed

4 files changed

+738
-755
lines changed
 

‎src/cmd/7a/a.h

+1
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ void newio(void);
107107
void newfile(char*, int);
108108
Sym* slookup(char*);
109109
Sym* lookup(void);
110+
Sym* labellookup(Sym*);
110111
void settext(LSym*);
111112
void syminit(Sym*);
112113
int32 yylex(void);

‎src/cmd/7a/a.y

+6-15
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,11 @@ prog:
4141
| prog line
4242

4343
line:
44-
LLAB ':'
45-
{
46-
if($1->value != pc)
47-
yyerror("redeclaration of %s", $1->name);
48-
$1->value = pc;
49-
}
50-
line
5144
| LNAME ':'
5245
{
46+
$1 = labellookup($1);
47+
if($1->type == LLAB && $1->value != pc)
48+
yyerror("redeclaration of %s", $1->labelname);
5349
$1->type = LLAB;
5450
$1->value = pc;
5551
}
@@ -435,15 +431,10 @@ rel:
435431
}
436432
| LNAME offset
437433
{
434+
$1 = labellookup($1);
438435
$$ = nullgen;
439-
if(pass == 2)
440-
yyerror("undefined label: %s", $1->name);
441-
$$.type = D_BRANCH;
442-
$$.offset = $2;
443-
}
444-
| LLAB offset
445-
{
446-
$$ = nullgen;
436+
if(pass == 2 && $1->type != LLAB)
437+
yyerror("undefined label: %s", $1->labelname);
447438
$$.type = D_BRANCH;
448439
$$.offset = $1->value + $2;
449440
}

‎src/cmd/7a/y.tab.c

+729-738
Large diffs are not rendered by default.

‎src/cmd/7a/y.tab.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -186,15 +186,15 @@ extern int yydebug;
186186
typedef union YYSTYPE YYSTYPE;
187187
union YYSTYPE
188188
{
189-
#line 9 "a.y" /* yacc.c:1915 */
189+
#line 9 "a.y" /* yacc.c:1909 */
190190

191191
Sym *sym;
192192
vlong lval;
193193
double dval;
194194
char sval[NSNAME];
195195
Addr addr;
196196

197-
#line 198 "y.tab.h" /* yacc.c:1915 */
197+
#line 198 "y.tab.h" /* yacc.c:1909 */
198198
};
199199
# define YYSTYPE_IS_TRIVIAL 1
200200
# define YYSTYPE_IS_DECLARED 1

0 commit comments

Comments
 (0)
Please sign in to comment.