[cfe-commits] r91801 - /cfe/trunk/lib/Parse/ParseStmt.cpp
Chris Lattner
sabre at nondot.org
Sun Dec 20 15:00:41 PST 2009
Author: lattner
Date: Sun Dec 20 17:00:41 2009
New Revision: 91801
URL: http://llvm.org/viewvc/llvm-project?rev=91801&view=rev
Log:
refactor asm stmt parsing to avoid nesting as much, and
pull ':' eating out of ParseAsmOperandsOpt.
Modified:
cfe/trunk/lib/Parse/ParseStmt.cpp
Modified: cfe/trunk/lib/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseStmt.cpp?rev=91801&r1=91800&r2=91801&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/lib/Parse/ParseStmt.cpp Sun Dec 20 17:00:41 2009
@@ -1232,7 +1232,6 @@
// Remember if this was a volatile asm.
bool isVolatile = DS.getTypeQualifiers() & DeclSpec::TQ_volatile;
- bool isSimple = false;
if (Tok.isNot(tok::l_paren)) {
Diag(Tok, diag::err_expected_lparen_after) << "asm";
SkipUntil(tok::r_paren);
@@ -1249,53 +1248,58 @@
ExprVector Exprs(Actions);
ExprVector Clobbers(Actions);
- unsigned NumInputs = 0, NumOutputs = 0;
-
- SourceLocation RParenLoc;
if (Tok.is(tok::r_paren)) {
- // We have a simple asm expression
- isSimple = true;
+ // We have a simple asm expression like 'asm("foo")'.
+ SourceLocation RParenLoc = ConsumeParen();
+ return Actions.ActOnAsmStmt(AsmLoc, /*isSimple*/ true, isVolatile,
+ /*NumOutputs*/ 0, /*NumInputs*/ 0, 0,
+ move_arg(Constraints), move_arg(Exprs),
+ move(AsmString), move_arg(Clobbers),
+ RParenLoc);
+ }
- RParenLoc = ConsumeParen();
- } else {
- // Parse Outputs, if present.
+ // Parse Outputs, if present.
+ if (Tok.is(tok::colon)) {
+ ConsumeToken();
+
if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
- return StmtError();
-
- NumOutputs = Names.size();
+ return StmtError();
+ }
+ unsigned NumOutputs = Names.size();
- // Parse Inputs, if present.
+ // Parse Inputs, if present.
+ if (Tok.is(tok::colon)) {
+ ConsumeToken();
if (ParseAsmOperandsOpt(Names, Constraints, Exprs))
- return StmtError();
+ return StmtError();
+ }
- assert(Names.size() == Constraints.size() &&
- Constraints.size() == Exprs.size()
- && "Input operand size mismatch!");
+ assert(Names.size() == Constraints.size() &&
+ Constraints.size() == Exprs.size() &&
+ "Input operand size mismatch!");
- NumInputs = Names.size() - NumOutputs;
+ unsigned NumInputs = Names.size() - NumOutputs;
- // Parse the clobbers, if present.
- if (Tok.is(tok::colon)) {
- ConsumeToken();
+ // Parse the clobbers, if present.
+ if (Tok.is(tok::colon)) {
+ ConsumeToken();
- // Parse the asm-string list for clobbers.
- while (1) {
- OwningExprResult Clobber(ParseAsmStringLiteral());
+ // Parse the asm-string list for clobbers.
+ while (1) {
+ OwningExprResult Clobber(ParseAsmStringLiteral());
- if (Clobber.isInvalid())
- break;
+ if (Clobber.isInvalid())
+ break;
- Clobbers.push_back(Clobber.release());
+ Clobbers.push_back(Clobber.release());
- if (Tok.isNot(tok::comma)) break;
- ConsumeToken();
- }
+ if (Tok.isNot(tok::comma)) break;
+ ConsumeToken();
}
-
- RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
}
- return Actions.ActOnAsmStmt(AsmLoc, isSimple, isVolatile,
+ SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
+ return Actions.ActOnAsmStmt(AsmLoc, false, isVolatile,
NumOutputs, NumInputs, Names.data(),
move_arg(Constraints), move_arg(Exprs),
move(AsmString), move_arg(Clobbers),
@@ -1303,8 +1307,7 @@
}
/// ParseAsmOperands - Parse the asm-operands production as used by
-/// asm-statement. We also parse a leading ':' token. If the leading colon is
-/// not present, we do not parse anything.
+/// asm-statement, assuming the leading ':' token was eaten.
///
/// [GNU] asm-operands:
/// asm-operand
@@ -1319,10 +1322,6 @@
bool Parser::ParseAsmOperandsOpt(llvm::SmallVectorImpl<std::string> &Names,
llvm::SmallVectorImpl<ExprTy*> &Constraints,
llvm::SmallVectorImpl<ExprTy*> &Exprs) {
- // Only do anything if this operand is present.
- if (Tok.isNot(tok::colon)) return false;
- ConsumeToken();
-
// 'asm-operands' isn't present?
if (!isTokenStringLiteral() && Tok.isNot(tok::l_square))
return false;
More information about the cfe-commits
mailing list