Skip to content

Commit 63b820d

Browse files
committed
Support BCC's #asm/#endasm blocks
1 parent 41df507 commit 63b820d

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

src/ansi-c/parser.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,10 @@ asm_definition:
27052705
{
27062706
// Not obvious what to do with this.
27072707
}
2708+
| '{' TOK_ASM_STRING '}'
2709+
{
2710+
// Not obvious what to do with this.
2711+
}
27082712
;
27092713

27102714
function_definition:

src/ansi-c/scanner.l

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,7 @@ void ansi_c_scanner_init()
290290
<GRAMMAR,GCC_ATTRIBUTE3>{string_lit} {
291291
PARSER.string_literal.clear();
292292
PARSER.string_literal.append(yytext);
293-
newstack(yyansi_clval);
294-
PARSER.set_source_location(stack(yyansi_clval));
293+
loc();
295294
// String literals can be continued in
296295
// the next line
297296
yy_push_state(STRING_LITERAL);
@@ -381,6 +380,23 @@ void ansi_c_scanner_init()
381380
<GRAMMAR>{cppstart}"define"{ws}.* { /* ignore */ }
382381
<GRAMMAR>{cppstart}"undef"{ws}.* { /* ignore */ }
383382

383+
<GRAMMAR>{cppstart}"asm" {
384+
if(PARSER.mode==configt::ansi_ct::flavourt::GCC) // really, this is BCC
385+
{
386+
BEGIN(ASM_BLOCK);
387+
PARSER.string_literal.clear();
388+
loc();
389+
return '{';
390+
}
391+
else
392+
return make_identifier();
393+
}
394+
395+
<GRAMMAR>{cppstart}"endasm" {
396+
loc();
397+
return '}';
398+
}
399+
384400
<GRAMMAR>{cppdirective} {
385401
yyansi_cerror("Preprocessor directive found");
386402
return TOK_SCANNER_ERROR;
@@ -1374,7 +1390,11 @@ __decltype { if(PARSER.cpp98 &&
13741390

13751391
"{" {
13761392
PARSER.tag_following=false;
1377-
if(PARSER.asm_block_following) { BEGIN(ASM_BLOCK); }
1393+
if(PARSER.asm_block_following)
1394+
{
1395+
BEGIN(ASM_BLOCK);
1396+
PARSER.string_literal.clear();
1397+
}
13781398
loc();
13791399
return yytext[0];
13801400
}
@@ -1392,7 +1412,12 @@ __decltype { if(PARSER.cpp98 &&
13921412
<MSC_ANNOTATION>"]" { BEGIN(GRAMMAR); }
13931413
<MSC_ANNOTATION>. { /* ignore */ }
13941414

1395-
<MSC_ASM>{ws}"{" { BEGIN(ASM_BLOCK); loc(); return '{'; }
1415+
<MSC_ASM>{ws}"{" {
1416+
BEGIN(ASM_BLOCK);
1417+
PARSER.string_literal.clear();
1418+
loc();
1419+
return '{';
1420+
}
13961421
<MSC_ASM>[^{^}^\n]* { loc();
13971422
source_locationt l=stack(yyansi_clval).source_location();
13981423
stack(yyansi_clval)=string_constantt(yytext);
@@ -1401,13 +1426,20 @@ __decltype { if(PARSER.cpp98 &&
14011426
return TOK_ASM_STRING;
14021427
}
14031428

1404-
<ASM_BLOCK>[^}]* { loc();
1405-
source_locationt l=stack(yyansi_clval).source_location();
1406-
stack(yyansi_clval)=string_constantt(yytext);
1407-
stack(yyansi_clval).add_source_location()=l;
1408-
return TOK_ASM_STRING; }
1409-
<ASM_BLOCK>"}" { PARSER.asm_block_following=false;
1410-
BEGIN(GRAMMAR); loc(); return '}'; }
1429+
<ASM_BLOCK>{
1430+
{ws} { /* ignore */ }
1431+
{newline} { /* ignore */ }
1432+
[^#}\n][^\n}]*[\n] { PARSER.string_literal.append(yytext); }
1433+
[^#}\n][^\n}]* { PARSER.string_literal.append(yytext); }
1434+
. { // anything else: back to normal
1435+
PARSER.asm_block_following=false;
1436+
loc();
1437+
stack(yyansi_clval)=string_constantt(PARSER.string_literal);
1438+
BEGIN(GRAMMAR);
1439+
yyless(0); // put back
1440+
return TOK_ASM_STRING;
1441+
}
1442+
}
14111443

14121444
<IGNORE_PARENS>")" { PARSER.parenthesis_counter--;
14131445
if(PARSER.parenthesis_counter==0)

0 commit comments

Comments
 (0)