Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for { and } in asm statements #641

Merged
merged 1 commit into from Oct 22, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 22 additions & 11 deletions src/parse.c
Expand Up @@ -4316,23 +4316,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)
Expand All @@ -4353,14 +4351,27 @@ 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 ';'");
}
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
Expand All @@ -4379,7 +4390,7 @@ Statement *Parser::parseStatement(int flags)
case TOKeof:
/* { */
error("matching '}' expected, not end of file");
break;
goto Lerror;

default:
Ldefault:
Expand Down