[cfe-commits] r46777 - in /cfe/trunk: AST/Stmt.cpp AST/StmtSerialization.cpp Parse/ParseStmt.cpp Sema/Sema.h Sema/SemaStmt.cpp include/clang/AST/Stmt.h include/clang/Parse/Action.h

Anders Carlsson andersca at mac.com
Tue Feb 5 15:03:50 PST 2008


Author: andersca
Date: Tue Feb  5 17:03:50 2008
New Revision: 46777

URL: http://llvm.org/viewvc/llvm-project?rev=46777&view=rev
Log:
Handle simple asm statements correctly.

Modified:
    cfe/trunk/AST/Stmt.cpp
    cfe/trunk/AST/StmtSerialization.cpp
    cfe/trunk/Parse/ParseStmt.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaStmt.cpp
    cfe/trunk/include/clang/AST/Stmt.h
    cfe/trunk/include/clang/Parse/Action.h

Modified: cfe/trunk/AST/Stmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Stmt.cpp?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/AST/Stmt.cpp (original)
+++ cfe/trunk/AST/Stmt.cpp Tue Feb  5 17:03:50 2008
@@ -115,13 +115,14 @@
 // Constructors
 //===----------------------------------------------------------------------===//
 
-AsmStmt::AsmStmt(SourceLocation asmloc,  bool isvolatile,
+AsmStmt::AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile,
                  unsigned numoutputs, unsigned numinputs,
                  std::string *names, StringLiteral **constraints,
                  Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
                  StringLiteral **clobbers, SourceLocation rparenloc)
   : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
-  , IsVolatile(isvolatile), NumOutputs(numoutputs), NumInputs(numinputs) {
+  , IsSimple(issimple), IsVolatile(isvolatile)
+  , NumOutputs(numoutputs), NumInputs(numinputs) {
   for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) {
     Names.push_back(names[i]);
     Exprs.push_back(exprs[i]);

Modified: cfe/trunk/AST/StmtSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtSerialization.cpp?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Tue Feb  5 17:03:50 2008
@@ -229,6 +229,7 @@
   S.Emit(RParenLoc);  
 
   S.EmitBool(IsVolatile);
+  S.EmitBool(IsSimple);
   S.EmitInt(NumOutputs);
   S.EmitInt(NumInputs);
 
@@ -254,7 +255,8 @@
   SourceLocation PLoc = SourceLocation::ReadVal(D);
   
   bool IsVolatile = D.ReadBool();
-  AsmStmt *Stmt = new AsmStmt(ALoc, IsVolatile, 0, 0, 0, 0, 0,  
+  bool IsSimple = D.ReadBool();
+  AsmStmt *Stmt = new AsmStmt(ALoc, IsSimple, IsVolatile, 0, 0, 0, 0, 0,  
                               AsmStr, 
                               0, 0, PLoc);  
 

Modified: cfe/trunk/Parse/ParseStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/ParseStmt.cpp?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Tue Feb  5 17:03:50 2008
@@ -939,7 +939,7 @@
   
   // 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);
@@ -954,43 +954,53 @@
   llvm::SmallVector<std::string, 4> Names;
   llvm::SmallVector<ExprTy*, 4> Constraints;
   llvm::SmallVector<ExprTy*, 4> Exprs;
-  
-  // Parse Outputs, if present. 
-  ParseAsmOperandsOpt(Names, Constraints, Exprs);
-  
-  unsigned NumOutputs = Names.size();
-  
-  // Parse Inputs, if present.
-  ParseAsmOperandsOpt(Names, Constraints, Exprs);
-  assert(Names.size() == Constraints.size() &&
-         Constraints.size() == Exprs.size() 
-         && "Input operand size mismatch!");
+  llvm::SmallVector<ExprTy*, 4> Clobbers;
 
-  unsigned NumInputs = Names.size() - NumOutputs;
+  unsigned NumInputs = 0, NumOutputs = 0;
   
-  llvm::SmallVector<ExprTy*, 4> Clobbers;
+  SourceLocation RParenLoc;
+  if (Tok.is(tok::r_paren)) {
+    // We have a simple asm expression
+    isSimple = true;
+    
+    RParenLoc = ConsumeParen();
+  } else {
+    // Parse Outputs, if present. 
+    ParseAsmOperandsOpt(Names, Constraints, Exprs);
+  
+    NumOutputs = Names.size();
+  
+    // Parse Inputs, if present.
+    ParseAsmOperandsOpt(Names, Constraints, Exprs);
+    assert(Names.size() == Constraints.size() &&
+           Constraints.size() == Exprs.size() 
+           && "Input operand size mismatch!");
+
+    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) {
-      ExprResult Clobber = ParseAsmStringLiteral();
+      // Parse the asm-string list for clobbers.
+      while (1) {
+        ExprResult Clobber = ParseAsmStringLiteral();
 
-      if (Clobber.isInvalid)
-        break;
+        if (Clobber.isInvalid)
+          break;
       
-      Clobbers.push_back(Clobber.Val);
+        Clobbers.push_back(Clobber.Val);
       
-      if (Tok.isNot(tok::comma)) break;
-      ConsumeToken();
+        if (Tok.isNot(tok::comma)) break;
+        ConsumeToken();
+      }
     }
-  }
   
-  SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
+    RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
+  }
   
-  return Actions.ActOnAsmStmt(AsmLoc, isVolatile, NumOutputs, NumInputs,
+  return Actions.ActOnAsmStmt(AsmLoc, isSimple, isVolatile,
+                              NumOutputs, NumInputs,
                               &Names[0], &Constraints[0], &Exprs[0],
                               AsmString.Val,
                               Clobbers.size(), &Clobbers[0],

Modified: cfe/trunk/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/Sema.h?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Feb  5 17:03:50 2008
@@ -361,6 +361,7 @@
                                      ExprTy *RetValExp);
   
   virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  bool IsSimple,
                                   bool IsVolatile,
                                   unsigned NumOutputs,
                                   unsigned NumInputs,

Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Tue Feb  5 17:03:50 2008
@@ -668,6 +668,7 @@
 }
 
 Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
+                                    bool IsSimple,                                    
                                     bool IsVolatile,
                                     unsigned NumOutputs,
                                     unsigned NumInputs,
@@ -765,6 +766,7 @@
   }
   
   return new AsmStmt(AsmLoc,
+                     IsSimple,
                      IsVolatile,
                      NumOutputs,
                      NumInputs, 

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Feb  5 17:03:50 2008
@@ -755,6 +755,7 @@
   SourceLocation AsmLoc, RParenLoc;
   StringLiteral *AsmStr;
 
+  bool IsSimple;
   bool IsVolatile;
   
   unsigned NumOutputs;
@@ -766,13 +767,15 @@
 
   llvm::SmallVector<StringLiteral*, 4> Clobbers;
 public:
-  AsmStmt(SourceLocation asmloc,  bool isvolatile, unsigned numoutputs,
-          unsigned numinputs, std::string *names, StringLiteral **constraints,
+  AsmStmt(SourceLocation asmloc, bool issimple, bool isvolatile, 
+          unsigned numoutputs, unsigned numinputs, 
+          std::string *names, StringLiteral **constraints,
           Expr **exprs, StringLiteral *asmstr, unsigned numclobbers,
           StringLiteral **clobbers, SourceLocation rparenloc);
 
   bool isVolatile() const { return IsVolatile; }
-  
+  bool isSimple() const { return IsSimple; }
+
   unsigned getNumOutputs() const { return NumOutputs; }
   const std::string &getOutputName(unsigned i) const
     { return Names[i]; }

Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=46777&r1=46776&r2=46777&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Feb  5 17:03:50 2008
@@ -299,6 +299,7 @@
     return 0;
   }
   virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  bool IsSimple,                                  
                                   bool IsVolatile,
                                   unsigned NumOutputs,
                                   unsigned NumInputs,





More information about the cfe-commits mailing list