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

Anders Carlsson andersca at mac.com
Tue Nov 20 11:21:04 PST 2007


Author: andersca
Date: Tue Nov 20 13:21:03 2007
New Revision: 44255

URL: http://llvm.org/viewvc/llvm-project?rev=44255&view=rev
Log:
Store inline asm code in the AST.

Modified:
    cfe/trunk/AST/StmtPrinter.cpp
    cfe/trunk/AST/StmtSerialization.cpp
    cfe/trunk/Parse/ParseStmt.cpp
    cfe/trunk/Parse/Parser.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
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/AST/StmtPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/StmtPrinter.cpp?rev=44255&r1=44254&r2=44255&view=diff

==============================================================================
--- cfe/trunk/AST/StmtPrinter.cpp (original)
+++ cfe/trunk/AST/StmtPrinter.cpp Tue Nov 20 13:21:03 2007
@@ -326,7 +326,9 @@
 
 
 void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
-  Indent() << "asm (/*todo*/);\n";
+  Indent() << "asm (";
+  VisitStringLiteral(Node->getAsmString());
+  OS << ");\n";
 }
 
 void StmtPrinter::VisitObjcAtTryStmt(ObjcAtTryStmt *Node) {

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

==============================================================================
--- cfe/trunk/AST/StmtSerialization.cpp (original)
+++ cfe/trunk/AST/StmtSerialization.cpp Tue Nov 20 13:21:03 2007
@@ -197,14 +197,16 @@
 
 void AsmStmt::EmitImpl(Serializer& S) const {
   S.Emit(AsmLoc);
+  getAsmString()->EmitImpl(S);
   S.Emit(RParenLoc);  
 }
 
 AsmStmt* AsmStmt::CreateImpl(Deserializer& D) {
   SourceLocation ALoc = SourceLocation::ReadVal(D);
+  StringLiteral *AsmStr = StringLiteral::CreateImpl(D);
   SourceLocation PLoc = SourceLocation::ReadVal(D);
   
-  return new AsmStmt(ALoc,PLoc);  
+  return new AsmStmt(ALoc, AsmStr, PLoc);  
 }
 
 void BinaryOperator::EmitImpl(Serializer& S) const {

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

==============================================================================
--- cfe/trunk/Parse/ParseStmt.cpp (original)
+++ cfe/trunk/Parse/ParseStmt.cpp Tue Nov 20 13:21:03 2007
@@ -943,8 +943,10 @@
   }
   Loc = ConsumeParen();
   
-  ParseAsmStringLiteral();
-  
+  ExprResult AsmString = ParseAsmStringLiteral();
+  if (AsmString.isInvalid)
+    return true;
+    
   // Parse Outputs, if present.
   ParseAsmOperandsOpt();
   
@@ -969,7 +971,7 @@
   SourceLocation RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
   
   // FIXME: Pass all the details down to the action.
-  return Actions.ActOnAsmStmt(AsmLoc, RParenLoc);
+  return Actions.ActOnAsmStmt(AsmLoc, AsmString.Val, RParenLoc);
 }
 
 /// ParseAsmOperands - Parse the asm-operands production as used by

Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=44255&r1=44254&r2=44255&view=diff

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Tue Nov 20 13:21:03 2007
@@ -575,16 +575,18 @@
 /// [GNU] asm-string-literal:
 ///         string-literal
 ///
-void Parser::ParseAsmStringLiteral() {
+Parser::ExprResult Parser::ParseAsmStringLiteral() {
   if (!isTokenStringLiteral()) {
     Diag(Tok, diag::err_expected_string_literal);
-    return;
+    return true;
   }
   
   ExprResult Res = ParseStringLiteralExpression();
-  if (Res.isInvalid) return;
+  if (Res.isInvalid) return true;
   
   // TODO: Diagnose: wide string literal in 'asm'
+    
+  return Res;
 }
 
 /// ParseSimpleAsm

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Tue Nov 20 13:21:03 2007
@@ -346,7 +346,8 @@
   virtual StmtResult ActOnReturnStmt(SourceLocation ReturnLoc,
                                      ExprTy *RetValExp);
   
-  virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 
+  virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  ExprTy *AsmString,
                                   SourceLocation RParenLoc);
   
   virtual StmtResult ActOnObjcAtCatchStmt(SourceLocation AtLoc, 

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

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Tue Nov 20 13:21:03 2007
@@ -644,9 +644,12 @@
   return new ReturnStmt(ReturnLoc, (Expr*)RetValExp);
 }
 
-Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, 
+Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
+                                    ExprTy *AsmString,
                                     SourceLocation RParenLoc) {
-  return new AsmStmt(AsmLoc, RParenLoc);
+  Expr *E = (Expr *)AsmString;
+    
+  return new AsmStmt(AsmLoc, cast<StringLiteral>(E), RParenLoc);
 }
 
 Action::StmtResult

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

==============================================================================
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Nov 20 13:21:03 2007
@@ -30,6 +30,7 @@
   class ScopedDecl;
   class IdentifierInfo;
   class SourceManager;
+  class StringLiteral;
   class SwitchStmt;
   class PrinterHelper;
     
@@ -704,11 +705,17 @@
 ///
 class AsmStmt : public Stmt {
   SourceLocation AsmLoc, RParenLoc;
+  StringLiteral *AsmStr;
   // FIXME: This doesn't capture most of the interesting pieces.
 public:
-  AsmStmt(SourceLocation asmloc, SourceLocation rparenloc)
-    : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc) {}
+  AsmStmt(SourceLocation asmloc, StringLiteral *asmstr, 
+          SourceLocation rparenloc)
+    : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc),
+      AsmStr(asmstr) {}
   
+  const StringLiteral *getAsmString() const { return AsmStr; }
+  StringLiteral *getAsmString() { return AsmStr; }
+
   virtual SourceRange getSourceRange() const {
     return SourceRange(AsmLoc, RParenLoc);
   }

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Tue Nov 20 13:21:03 2007
@@ -286,7 +286,8 @@
                                      ExprTy *RetValExp) {
     return 0;
   }
-  virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 
+  virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  ExprTy *AsmString,
                                   SourceLocation RParenLoc) {
     return 0;
   }

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Tue Nov 20 13:21:03 2007
@@ -244,7 +244,10 @@
   }
   bool SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
                  bool StopAtSemi = true, bool DontConsume = false);
-   
+ 
+  typedef Action::ExprResult ExprResult;
+  typedef Action::StmtResult StmtResult;
+    
   //===--------------------------------------------------------------------===//
   // C99 6.9: External Definitions.
   DeclTy *ParseExternalDeclaration();
@@ -252,7 +255,7 @@
   DeclTy *ParseFunctionDefinition(Declarator &D);
   void ParseKNRParamDeclarations(Declarator &D);
   void ParseSimpleAsm();
-  void ParseAsmStringLiteral();
+  ExprResult ParseAsmStringLiteral();
 
   // Objective-C External Declarations
   DeclTy *ParseObjCAtDirectives(); 
@@ -305,9 +308,6 @@
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.
 
-  typedef Action::ExprResult ExprResult;
-  typedef Action::StmtResult StmtResult;
-  
   ExprResult ParseExpression();
   ExprResult ParseConstantExpression();
   ExprResult ParseAssignmentExpression();  // Expr that doesn't include commas.





More information about the cfe-commits mailing list