[cfe-commits] r46868 - in /cfe/trunk: AST/Decl.cpp AST/DeclSerialization.cpp CodeGen/ModuleBuilder.cpp Driver/ASTConsumers.cpp Parse/Parser.cpp Sema/Sema.h Sema/SemaDecl.cpp include/clang/AST/Decl.h include/clang/Parse/Action.h include/clang/Parse/Parser.h

Anders Carlsson andersca at mac.com
Thu Feb 7 16:33:21 PST 2008


Author: andersca
Date: Thu Feb  7 18:33:21 2008
New Revision: 46868

URL: http://llvm.org/viewvc/llvm-project?rev=46868&view=rev
Log:
Put back the top-level asm code; all tests pass now.

Modified:
    cfe/trunk/AST/Decl.cpp
    cfe/trunk/AST/DeclSerialization.cpp
    cfe/trunk/CodeGen/ModuleBuilder.cpp
    cfe/trunk/Driver/ASTConsumers.cpp
    cfe/trunk/Parse/Parser.cpp
    cfe/trunk/Sema/Sema.h
    cfe/trunk/Sema/SemaDecl.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/include/clang/Parse/Action.h
    cfe/trunk/include/clang/Parse/Parser.h

Modified: cfe/trunk/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Decl.cpp?rev=46868&r1=46867&r2=46868&view=diff

==============================================================================
--- cfe/trunk/AST/Decl.cpp (original)
+++ cfe/trunk/AST/Decl.cpp Thu Feb  7 18:33:21 2008
@@ -38,6 +38,7 @@
 static unsigned nObjCCompatibleAlias = 0;
 static unsigned nObjCPropertyDecl = 0;
 static unsigned nLinkageSpecDecl = 0;
+static unsigned nFileScopeAsmDecl = 0;
 
 static bool StatSwitch = false;
 
@@ -169,7 +170,8 @@
               nObjCCategoryImpl*sizeof(ObjCCategoryImplDecl)+
               nObjCCompatibleAlias*sizeof(ObjCCompatibleAliasDecl)+
               nObjCPropertyDecl*sizeof(ObjCPropertyDecl)+
-              nLinkageSpecDecl*sizeof(LinkageSpecDecl)));
+              nLinkageSpecDecl*sizeof(LinkageSpecDecl)+
+              nFileScopeAsmDecl*sizeof(FileScopeAsmDecl)));
     
 }
 
@@ -240,6 +242,9 @@
     case LinkageSpec:
       nLinkageSpecDecl++;
       break;
+    case FileScopeAsm:
+      nFileScopeAsmDecl++;
+      break;
   }
 }
 

Modified: cfe/trunk/AST/DeclSerialization.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/DeclSerialization.cpp?rev=46868&r1=46867&r2=46868&view=diff

==============================================================================
--- cfe/trunk/AST/DeclSerialization.cpp (original)
+++ cfe/trunk/AST/DeclSerialization.cpp Thu Feb  7 18:33:21 2008
@@ -67,6 +67,9 @@
       
     case Typedef:
       return TypedefDecl::CreateImpl(D);
+      
+    case FileScopeAsm:
+      return FileScopeAsmDecl::CreateImpl(D);
   }
 }
 
@@ -438,3 +441,23 @@
   Language = static_cast<LanguageIDs>(D.ReadInt());
   D.ReadPtr(this->D);
 }
+
+//===----------------------------------------------------------------------===//
+//      FileScopeAsm Serialization.
+//===----------------------------------------------------------------------===//
+
+void FileScopeAsmDecl::EmitImpl(llvm::Serializer& S) const
+{
+  Decl::EmitInRec(S);
+  S.EmitOwnedPtr(AsmString);
+}
+
+FileScopeAsmDecl* FileScopeAsmDecl::CreateImpl(Deserializer& D) { 
+  FileScopeAsmDecl* decl = new FileScopeAsmDecl(SourceLocation(), 0);
+
+  decl->Decl::ReadInRec(D);
+  decl->AsmString = cast<StringLiteral>(D.ReadOwnedPtr<Expr>());
+//  D.ReadOwnedPtr(D.ReadOwnedPtr<StringLiteral>())<#T * * Ptr#>, <#bool AutoRegister#>)(decl->AsmString);
+  
+  return decl;
+}

Modified: cfe/trunk/CodeGen/ModuleBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/CodeGen/ModuleBuilder.cpp?rev=46868&r1=46867&r2=46868&view=diff

==============================================================================
--- cfe/trunk/CodeGen/ModuleBuilder.cpp (original)
+++ cfe/trunk/CodeGen/ModuleBuilder.cpp Thu Feb  7 18:33:21 2008
@@ -70,6 +70,15 @@
           Builder->WarnUnsupported(LSD, "linkage spec");
         // FIXME: implement C++ linkage, C linkage works mostly by C
         // language reuse already.
+      } else if (FileScopeAsmDecl *AD = dyn_cast<FileScopeAsmDecl>(D)) {
+        std::string AsmString(AD->getAsmString()->getStrData(),
+                              AD->getAsmString()->getByteLength());
+        
+        const std::string &S = Builder->getModule().getModuleInlineAsm();
+        if (S.empty())
+          Builder->getModule().setModuleInlineAsm(AsmString);
+        else
+          Builder->getModule().setModuleInlineAsm(S + '\n' + AsmString);
       } else {
         assert(isa<TypeDecl>(D) && "Unknown top level decl");
         // TODO: handle debug info?

Modified: cfe/trunk/Driver/ASTConsumers.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Driver/ASTConsumers.cpp?rev=46868&r1=46867&r2=46868&view=diff

==============================================================================
--- cfe/trunk/Driver/ASTConsumers.cpp (original)
+++ cfe/trunk/Driver/ASTConsumers.cpp Thu Feb  7 18:33:21 2008
@@ -97,6 +97,10 @@
     Out << "Read top-level variable decl: '" << SD->getName() << "'\n";
   } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
     PrintLinkageSpec(LSD);
+  } else if (FileScopeAsmDecl *AD = dyn_cast<FileScopeAsmDecl>(D)) {
+    Out << "asm(";
+    AD->getAsmString()->printPretty(Out);
+    Out << ")\n";
   } else {
     assert(0 && "Unknown decl type!");
   }
@@ -402,6 +406,8 @@
         Out << "Read objc fwd protocol decl\n";
       } else if (isa<ObjCClassDecl>(D)) {
         Out << "Read objc fwd class decl\n";
+      } else if (isa<FileScopeAsmDecl>(D)) {
+        Out << "Read file scope asm decl\n";
       } else {
         assert(0 && "Unknown decl type!");
       }

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

==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Thu Feb  7 18:33:21 2008
@@ -320,12 +320,15 @@
     // FIXME: Restore extension warnings.
     return RV;
   }
-  case tok::kw_asm:
-    ParseSimpleAsm();
+  case tok::kw_asm: {
+    ExprResult Result = ParseSimpleAsm();
+    
     ExpectAndConsume(tok::semi, diag::err_expected_semi_after,
                      "top-level asm block");
-    // TODO: Invoke action for top-level asm.
-    return 0;
+
+    if (!Result.isInvalid)
+      return Actions.ActOnFileScopeAsmDecl(Tok.getLocation(), Result.Val);
+  }
   case tok::at:
     // @ is not a legal token unless objc is enabled, no need to check.
     return ParseObjCAtDirectives();
@@ -610,19 +613,21 @@
 /// [GNU] simple-asm-expr:
 ///         'asm' '(' asm-string-literal ')'
 ///
-void Parser::ParseSimpleAsm() {
+Parser::ExprResult Parser::ParseSimpleAsm() {
   assert(Tok.is(tok::kw_asm) && "Not an asm!");
-  ConsumeToken();
+  SourceLocation Loc = ConsumeToken();
   
   if (Tok.isNot(tok::l_paren)) {
     Diag(Tok, diag::err_expected_lparen_after, "asm");
-    return;
+    return 0;
   }
   
-  SourceLocation Loc = ConsumeParen();
+  ConsumeParen();
   
-  ParseAsmStringLiteral();
+  ExprResult Result = ParseAsmStringLiteral();
   
   MatchRHSPunctuation(tok::r_paren, Loc);
+  
+  return Result;
 }
 

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

==============================================================================
--- cfe/trunk/Sema/Sema.h (original)
+++ cfe/trunk/Sema/Sema.h Thu Feb  7 18:33:21 2008
@@ -197,7 +197,8 @@
   virtual DeclTy *ActOnLinkageSpec(SourceLocation Loc, SourceLocation LBrace,
 				   SourceLocation RBrace, const char *Lang,
 				   unsigned StrSize, DeclTy *D);
-  
+  virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *expr);
+
   /// Scope actions.
   virtual void ActOnPopScope(SourceLocation Loc, Scope *S);
   virtual void ActOnTranslationUnitScope(SourceLocation Loc, Scope *S);

Modified: cfe/trunk/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaDecl.cpp?rev=46868&r1=46867&r2=46868&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/Sema/SemaDecl.cpp Thu Feb  7 18:33:21 2008
@@ -1711,6 +1711,13 @@
   Consumer.HandleTagDeclDefinition(Enum);
 }
 
+Sema::DeclTy *Sema::ActOnFileScopeAsmDecl(SourceLocation Loc,
+                                          ExprTy *expr) {
+  StringLiteral *AsmString = cast<StringLiteral>((Expr*)expr);
+  
+  return new FileScopeAsmDecl(Loc, AsmString);
+}
+
 Sema::DeclTy* Sema::ActOnLinkageSpec(SourceLocation Loc,
 				     SourceLocation LBrace,
 				     SourceLocation RBrace,

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

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Thu Feb  7 18:33:21 2008
@@ -27,6 +27,7 @@
 namespace clang {
 class Expr;
 class Stmt;
+class StringLiteral;
 class FunctionDecl;
 class IdentifierInfo;
 
@@ -71,6 +72,7 @@
          ObjCClass,
          ObjCForwardProtocol,
  	 LinkageSpec,
+   FileScopeAsm,
   
     // For each non-leaf class, we now define a mapping to the first/last member
     // of the class, to allow efficient classof.
@@ -755,6 +757,27 @@
   friend Decl* Decl::Create(llvm::Deserializer& D);
 };
 
+class FileScopeAsmDecl : public Decl {
+  StringLiteral *AsmString;
+public:
+  FileScopeAsmDecl(SourceLocation L, StringLiteral *asmstring)
+    : Decl(FileScopeAsm, L), AsmString(asmstring) {}
+
+  const StringLiteral *getAsmString() const { return AsmString; }
+  StringLiteral *getAsmString() { return AsmString; }
+  static bool classof(const Decl *D) {
+    return D->getKind() == FileScopeAsm;
+  }
+  static bool classof(const FileScopeAsmDecl *D) { return true; }  
+protected:
+  /// EmitImpl - Serialize this FileScopeAsmDecl. Called by Decl::Emit.
+  virtual void EmitImpl(llvm::Serializer& S) const;
+  
+  /// CreateImpl - Deserialize a FileScopeAsmDecl.  Called by Decl::Create.
+  static FileScopeAsmDecl* CreateImpl(llvm::Deserializer& D);
+  
+  friend Decl* Decl::Create(llvm::Deserializer& D);
+};
 
 /// LinkageSpecDecl - This represents a linkage specification.  For example:
 ///   extern "C" void foo();

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Feb  7 18:33:21 2008
@@ -141,6 +141,10 @@
     return Decl;
   }
 
+  virtual DeclTy *ActOnFileScopeAsmDecl(SourceLocation Loc, ExprTy *AsmString) {
+    return 0;
+  }
+  
   /// ActOnPopScope - This callback is called immediately before the specified
   /// scope is popped and deleted.
   virtual void ActOnPopScope(SourceLocation Loc, Scope *S) {}

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

==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Feb  7 18:33:21 2008
@@ -256,7 +256,7 @@
   DeclTy *ParseDeclarationOrFunctionDefinition();
   DeclTy *ParseFunctionDefinition(Declarator &D);
   void ParseKNRParamDeclarations(Declarator &D);
-  void ParseSimpleAsm();
+  ExprResult ParseSimpleAsm();
   ExprResult ParseAsmStringLiteral();
 
   // Objective-C External Declarations





More information about the cfe-commits mailing list