]> granicus.if.org Git - clang/commitdiff
Handle simple asm statements correctly.
authorAnders Carlsson <andersca@mac.com>
Tue, 5 Feb 2008 23:03:50 +0000 (23:03 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 5 Feb 2008 23:03:50 +0000 (23:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46777 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 249794db595c79084bf478cdedefc0b770b0fb58..572280bc05456aadae6d4c471d78410e744bef06 100644 (file)
@@ -115,13 +115,14 @@ bool Stmt::hasImplicitControlFlow() const {
 // 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]);
index 9a03a5320f97f0bcc8d7faa723bf7a2273264d4d..f075e1c12d14707cad657b5a38f4fb16f6d4146f 100644 (file)
@@ -229,6 +229,7 @@ void AsmStmt::EmitImpl(Serializer& S) const {
   S.Emit(RParenLoc);  
 
   S.EmitBool(IsVolatile);
+  S.EmitBool(IsSimple);
   S.EmitInt(NumOutputs);
   S.EmitInt(NumInputs);
 
@@ -254,7 +255,8 @@ AsmStmt* AsmStmt::CreateImpl(Deserializer& D) {
   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);  
 
index b6cd558b0432c0b0b0b70a846c98ef784aa2635e..a074463f3cf59a733a08b36753752aec9bfdb45b 100644 (file)
@@ -939,7 +939,7 @@ Parser::StmtResult Parser::ParseAsmStatement() {
   
   // 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 @@ Parser::StmtResult Parser::ParseAsmStatement() {
   llvm::SmallVector<std::string, 4> Names;
   llvm::SmallVector<ExprTy*, 4> Constraints;
   llvm::SmallVector<ExprTy*, 4> Exprs;
+  llvm::SmallVector<ExprTy*, 4> Clobbers;
+
+  unsigned NumInputs = 0, NumOutputs = 0;
   
-  // Parse Outputs, if present. 
-  ParseAsmOperandsOpt(Names, Constraints, Exprs);
+  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);
   
-  unsigned NumOutputs = Names.size();
+    NumOutputs = Names.size();
   
-  // Parse Inputs, if present.
-  ParseAsmOperandsOpt(Names, Constraints, Exprs);
-  assert(Names.size() == Constraints.size() &&
-         Constraints.size() == Exprs.size() 
-         && "Input operand size mismatch!");
+    // Parse Inputs, if present.
+    ParseAsmOperandsOpt(Names, Constraints, Exprs);
+    assert(Names.size() == Constraints.size() &&
+           Constraints.size() == Exprs.size() 
+           && "Input operand size mismatch!");
 
-  unsigned NumInputs = Names.size() - NumOutputs;
-  
-  llvm::SmallVector<ExprTy*, 4> Clobbers;
+    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],
index ecd5ffd2c9b5dc34d9849d9852b5f50181037ec1..3b463eb407967abd0a3917b06bdaad2cd96865d5 100644 (file)
@@ -361,6 +361,7 @@ public:
                                      ExprTy *RetValExp);
   
   virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  bool IsSimple,
                                   bool IsVolatile,
                                   unsigned NumOutputs,
                                   unsigned NumInputs,
index c84b3f344f3f38e253b39ff1c272dcc888dee2ef..1c847717621dc13a3443e9110f193ff070835c51 100644 (file)
@@ -668,6 +668,7 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
 }
 
 Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
+                                    bool IsSimple,                                    
                                     bool IsVolatile,
                                     unsigned NumOutputs,
                                     unsigned NumInputs,
@@ -765,6 +766,7 @@ Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
   }
   
   return new AsmStmt(AsmLoc,
+                     IsSimple,
                      IsVolatile,
                      NumOutputs,
                      NumInputs, 
index 8ea6f1edbfd5b930eb808ae9e07a96e22fe70ae8..dae7fbf49b64cd58735f55f857028804caf2a0b3 100644 (file)
@@ -755,6 +755,7 @@ class AsmStmt : public Stmt {
   SourceLocation AsmLoc, RParenLoc;
   StringLiteral *AsmStr;
 
+  bool IsSimple;
   bool IsVolatile;
   
   unsigned NumOutputs;
@@ -766,13 +767,15 @@ class AsmStmt : public Stmt {
 
   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]; }
index ce4781b91a8d752864fd43403f1947e6e73d1c94..7a2081978d5dba08e6c0936bc4fe1c101def4958 100644 (file)
@@ -299,6 +299,7 @@ public:
     return 0;
   }
   virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  bool IsSimple,                                  
                                   bool IsVolatile,
                                   unsigned NumOutputs,
                                   unsigned NumInputs,