]> granicus.if.org Git - clang/commitdiff
Store inline asm code in the AST.
authorAnders Carlsson <andersca@mac.com>
Tue, 20 Nov 2007 19:21:03 +0000 (19:21 +0000)
committerAnders Carlsson <andersca@mac.com>
Tue, 20 Nov 2007 19:21:03 +0000 (19:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44255 91177308-0d34-0410-b5e6-96231b3b80d8

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

index fa3eb84b529700d86cac11eb413e0c43807e1692..306bfcb18e641530bdee839853d97a8d4acdafd9 100644 (file)
@@ -326,7 +326,9 @@ void StmtPrinter::VisitReturnStmt(ReturnStmt *Node) {
 
 
 void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
-  Indent() << "asm (/*todo*/);\n";
+  Indent() << "asm (";
+  VisitStringLiteral(Node->getAsmString());
+  OS << ");\n";
 }
 
 void StmtPrinter::VisitObjcAtTryStmt(ObjcAtTryStmt *Node) {
index 24733eb7ac418b1c7d8f3efde116c16d80753513..f2c7834e729b856645b517cc15a78a10fa4426ec 100644 (file)
@@ -197,14 +197,16 @@ ArraySubscriptExpr* ArraySubscriptExpr::CreateImpl(Deserializer& D) {
 
 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 {
index cb2a6917190540850ab241639a2f8a535553a497..8d5be6868cf0328fe4f86d133853cf3aec8ee60c 100644 (file)
@@ -943,8 +943,10 @@ Parser::StmtResult Parser::ParseAsmStatement() {
   }
   Loc = ConsumeParen();
   
-  ParseAsmStringLiteral();
-  
+  ExprResult AsmString = ParseAsmStringLiteral();
+  if (AsmString.isInvalid)
+    return true;
+    
   // Parse Outputs, if present.
   ParseAsmOperandsOpt();
   
@@ -969,7 +971,7 @@ Parser::StmtResult Parser::ParseAsmStatement() {
   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
index b571703a3a5cbe3852c7ec8f2d59875095f2fe8a..8a0d8c7ecd0103212532be4de0d4880e738fc535 100644 (file)
@@ -575,16 +575,18 @@ void Parser::ParseKNRParamDeclarations(Declarator &D) {
 /// [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
index 4ed71f7388d14b3a7f167922970f24e36964829d..78cc888f341294749d95a82d9eb6d55816319387 100644 (file)
@@ -346,7 +346,8 @@ public:
   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, 
index 65acf0bb14d10bf604fbb161f0cb8186257fff15..ad3d2e4ee6603ceb8809ccdb24a06b866abab7f5 100644 (file)
@@ -644,9 +644,12 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprTy *rex) {
   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
index 20344829d0ea272c10f4c08868efe65efbb2867f..802c025cdbeb541a95cebad6ac541d5c041e73a9 100644 (file)
@@ -30,6 +30,7 @@ namespace clang {
   class ScopedDecl;
   class IdentifierInfo;
   class SourceManager;
+  class StringLiteral;
   class SwitchStmt;
   class PrinterHelper;
     
@@ -704,11 +705,17 @@ public:
 ///
 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);
   }
index 2e8b4de927b093e1acc47cea718f2ad6469d676a..2da8e01149eb6f67cbe01e10a9489b8fceb3b657 100644 (file)
@@ -286,7 +286,8 @@ public:
                                      ExprTy *RetValExp) {
     return 0;
   }
-  virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, 
+  virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc,
+                                  ExprTy *AsmString,
                                   SourceLocation RParenLoc) {
     return 0;
   }
index 57fd4e1e790f8800c1a6821773625ce3dc364d7e..9d7f27e1844d19f63411d8a7b565debc6977815e 100644 (file)
@@ -244,7 +244,10 @@ private:
   }
   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 @@ private:
   DeclTy *ParseFunctionDefinition(Declarator &D);
   void ParseKNRParamDeclarations(Declarator &D);
   void ParseSimpleAsm();
-  void ParseAsmStringLiteral();
+  ExprResult ParseAsmStringLiteral();
 
   // Objective-C External Declarations
   DeclTy *ParseObjCAtDirectives(); 
@@ -305,9 +308,6 @@ private:
   //===--------------------------------------------------------------------===//
   // C99 6.5: Expressions.
 
-  typedef Action::ExprResult ExprResult;
-  typedef Action::StmtResult StmtResult;
-  
   ExprResult ParseExpression();
   ExprResult ParseConstantExpression();
   ExprResult ParseAssignmentExpression();  // Expr that doesn't include commas.