Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #641 from braddr/cleanup-backend

Add support for { and } in asm statements
  • Loading branch information...
commit 48157cb615c973220923183f073dcb4945428a75 2 parents 3b19988 + 11d41eb
@WalterBright WalterBright authored
Showing with 22 additions and 11 deletions.
  1. +22 −11 src/parse.c
View
33 src/parse.c
@@ -4348,23 +4348,21 @@ Statement *Parser::parseStatement(int flags)
break;
case TOKasm:
- { Statements *statements;
- Identifier *label;
- Loc labelloc;
- Token *toklist;
- Token **ptoklist;
-
+ {
// Parse the asm block into a sequence of AsmStatements,
// each AsmStatement is one instruction.
// Separate out labels.
// Defer parsing of AsmStatements until semantic processing.
+ Loc labelloc;
+
nextToken();
check(TOKlcurly);
- toklist = NULL;
- ptoklist = &toklist;
- label = NULL;
- statements = new Statements();
+ Token *toklist = NULL;
+ Token **ptoklist = &toklist;
+ Identifier *label = NULL;
+ Statements *statements = new Statements();
+ size_t nestlevel = 0;
while (1)
{
switch (token.value)
@@ -4385,7 +4383,17 @@ Statement *Parser::parseStatement(int flags)
}
goto Ldefault;
+ case TOKlcurly:
+ ++nestlevel;
+ goto Ldefault;
+
case TOKrcurly:
+ if (nestlevel > 0)
+ {
+ --nestlevel;
+ goto Ldefault;
+ }
+
if (toklist || label)
{
error("asm statements must end in ';'");
@@ -4393,6 +4401,9 @@ Statement *Parser::parseStatement(int flags)
break;
case TOKsemicolon:
+ if (nestlevel != 0)
+ error("mismatched number of curly brackets");
+
s = NULL;
if (toklist || label)
{ // Create AsmStatement from list of tokens we've saved
@@ -4411,7 +4422,7 @@ Statement *Parser::parseStatement(int flags)
case TOKeof:
/* { */
error("matching '}' expected, not end of file");
- break;
+ goto Lerror;
default:
Ldefault:
Please sign in to comment.
Something went wrong with that request. Please try again.