[cfe-commits] r39550 - in /cfe/cfe/trunk/CodeGen: CGDecl.cpp CGStmt.cpp CodeGenFunction.cpp CodeGenFunction.h

clattner at cs.uiuc.edu clattner at cs.uiuc.edu
Wed Jul 11 09:45:30 PDT 2007


Author: clattner
Date: Wed Jul 11 11:45:30 2007
New Revision: 39550

URL: http://llvm.org/viewvc/llvm-project?rev=39550&view=rev
Log:
Start stubbing out decl codegen.

Added:
    cfe/cfe/trunk/CodeGen/CGDecl.cpp   (with props)
Modified:
    cfe/cfe/trunk/CodeGen/CGStmt.cpp
    cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
    cfe/cfe/trunk/CodeGen/CodeGenFunction.h

Added: cfe/cfe/trunk/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGDecl.cpp?rev=39550&view=auto

==============================================================================
--- cfe/cfe/trunk/CodeGen/CGDecl.cpp (added)
+++ cfe/cfe/trunk/CodeGen/CGDecl.cpp Wed Jul 11 11:45:30 2007
@@ -0,0 +1,56 @@
+//===--- CGDecl.cpp - Emit LLVM Code for declarations ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Chris Lattner and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Decl nodes as LLVM code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CodeGenFunction.h"
+#include "clang/AST/AST.h"
+//#include "llvm/Constants.h"
+//#include "llvm/DerivedTypes.h"
+//#include "llvm/Function.h"
+using namespace llvm;
+using namespace clang;
+using namespace CodeGen;
+
+
+void CodeGenFunction::EmitDeclStmt(const DeclStmt &S) {
+  const Decl *Decl = S.getDecl();
+
+  switch (Decl->getKind()) {
+  default: assert(0 && "Unknown decl kind!");
+  case Decl::FileVariable:
+    assert(0 && "Should not see file-scope variables inside a function!");
+  case Decl::ParmVariable:
+    assert(0 && "Parmdecls should not be in declstmts!");
+  case Decl::Typedef:   // typedef int X;
+  case Decl::Function:  // void X();
+  case Decl::Struct:    // struct X;
+  case Decl::Union:     // union X;
+  case Decl::Class:     // class X;
+  case Decl::Enum:      // enum X;
+    // None of these decls require codegen support.
+    return;
+    
+  case Decl::BlockVariable:
+    return EmitBlockVarDecl(cast<BlockVarDecl>(*Decl));
+  case Decl::EnumConstant:
+    return EmitEnumConstantDecl(cast<EnumConstantDecl>(*Decl));
+  }
+}
+
+void CodeGenFunction::EmitBlockVarDecl(const BlockVarDecl &D) {
+  //assert(0 && "FIXME: Enum constant decls not implemented yet!");  
+  
+}
+
+void CodeGenFunction::EmitEnumConstantDecl(const EnumConstantDecl &D) {
+  assert(0 && "FIXME: Enum constant decls not implemented yet!");  
+}

Propchange: cfe/cfe/trunk/CodeGen/CGDecl.cpp

------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cfe/cfe/trunk/CodeGen/CGDecl.cpp

------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: cfe/cfe/trunk/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CGStmt.cpp?rev=39550&r1=39549&r2=39550&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CGStmt.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CGStmt.cpp Wed Jul 11 11:45:30 2007
@@ -44,6 +44,7 @@
   case Stmt::GotoStmtClass:     EmitGotoStmt(cast<GotoStmt>(*S));         break;
   case Stmt::IfStmtClass:       EmitIfStmt(cast<IfStmt>(*S));             break;
   case Stmt::ReturnStmtClass:   EmitReturnStmt(cast<ReturnStmt>(*S));     break;
+  case Stmt::DeclStmtClass:     EmitDeclStmt(cast<DeclStmt>(*S));         break;
   }
 }
 

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp?rev=39550&r1=39549&r2=39550&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp Wed Jul 11 11:45:30 2007
@@ -126,6 +126,9 @@
   
   Builder.SetInsertPoint(EntryBB);
   
+  // TODO: handle params. 
+  
+  // Emit the function body.
   EmitStmt(FD->getBody());
   
   // Emit a return for code that falls off the end.

Modified: cfe/cfe/trunk/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/CodeGen/CodeGenFunction.h?rev=39550&r1=39549&r2=39550&view=diff

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:45:30 2007
@@ -21,21 +21,26 @@
   class Module;
 namespace clang {
   class ASTContext;
+  class Decl;
   class FunctionDecl;
   class QualType;
   class SourceLocation;
   class TargetInfo;
+  
   class Stmt;
   class CompoundStmt;
   class LabelStmt;
   class GotoStmt;
   class IfStmt;
   class ReturnStmt;
+  class DeclStmt;
   
   class Expr;
   class IntegerLiteral;
   class BinaryOperator;
   
+  class BlockVarDecl;
+  class EnumConstantDecl;
 namespace CodeGen {
   class CodeGenModule;
   
@@ -85,6 +90,10 @@
   const FunctionDecl *CurFuncDecl;
   llvm::Function *CurFn;
 
+  /// LocalDeclMap - This keeps track of the LLVM allocas or globals for local C
+  /// decls.
+  DenseMap<const Decl*, llvm::Value*> LocalDeclMap;
+
   /// LabelMap - This keeps track of the LLVM basic block for each C label.
   DenseMap<const LabelStmt*, llvm::BasicBlock*> LabelMap;
 public:
@@ -101,8 +110,17 @@
   
   
   void EmitBlock(BasicBlock *BB);
+
   
   //===--------------------------------------------------------------------===//
+  //                        Local Declaration Emission
+  //===--------------------------------------------------------------------===//
+  
+  void EmitDeclStmt(const DeclStmt &S);
+  void EmitBlockVarDecl(const BlockVarDecl &D);
+  void EmitEnumConstantDecl(const EnumConstantDecl &D);
+
+  //===--------------------------------------------------------------------===//
   //                             Statement Emission
   //===--------------------------------------------------------------------===//
 





More information about the cfe-commits mailing list