[cfe-commits] r39530 - in /cfe/cfe/trunk/CodeGen: CodeGenFunction.cpp CodeGenFunction.h

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


Author: clattner
Date: Wed Jul 11 11:45:19 2007
New Revision: 39530

URL: http://llvm.org/viewvc/llvm-project?rev=39530&view=rev
Log:
implement codegen of integer literals.

Modified:
    cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp
    cfe/cfe/trunk/CodeGen/CodeGenFunction.h

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

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.cpp Wed Jul 11 11:45:19 2007
@@ -15,6 +15,7 @@
 #include "CodeGenModule.h"
 #include "clang/Basic/TargetInfo.h"
 #include "clang/AST/AST.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 using namespace llvm;
@@ -136,8 +137,14 @@
   
   switch (S->getStmtClass()) {
   default:
-    printf("Unimplemented stmt!\n");
-    S->dump();
+    // Must be an expression in a stmt context.  Emit the value and ignore the
+    // result.
+    if (const Expr *E = dyn_cast<Expr>(S)) {
+      EmitExpr(E);
+    } else {
+      printf("Unimplemented stmt!\n");
+      S->dump();
+    }
     break;
   case Stmt::NullStmtClass: break;
   case Stmt::CompoundStmtClass: EmitCompoundStmt(cast<CompoundStmt>(*S)); break;
@@ -180,3 +187,28 @@
   Builder.SetInsertPoint(new BasicBlock("", CurFn));
 }
 
+
+
+//===--------------------------------------------------------------------===//
+//                             Expression Emission
+//===--------------------------------------------------------------------===//
+
+ExprResult CodeGenFunction::EmitExpr(const Expr *E) {
+  assert(E && "Null expression?");
+  
+  switch (E->getStmtClass()) {
+  default:
+    printf("Unimplemented expr!\n");
+    E->dump();
+    return ExprResult::get(UndefValue::get(llvm::Type::Int32Ty));
+  case Stmt::IntegerLiteralClass:
+    return EmitIntegerLiteral(cast<IntegerLiteral>(E)); 
+  }
+  
+}
+
+ExprResult CodeGenFunction::EmitIntegerLiteral(const IntegerLiteral *E) {
+  return ExprResult::get(ConstantInt::get(E->getValue()));
+}
+
+

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

==============================================================================
--- cfe/cfe/trunk/CodeGen/CodeGenFunction.h (original)
+++ cfe/cfe/trunk/CodeGen/CodeGenFunction.h Wed Jul 11 11:45:19 2007
@@ -30,9 +30,30 @@
   class LabelStmt;
   class GotoStmt;
   
+  class Expr;
+  class IntegerLiteral;
+  
 namespace CodeGen {
   class CodeGenModule;
   
+struct ExprResult {
+  Value *V;
+  bool isAggregate;
+  
+  static ExprResult get(Value *V) {
+    ExprResult ER;
+    ER.V = V;
+    ER.isAggregate = false;
+    return ER;
+  }
+  static ExprResult getAggregate(Value *V) {
+    ExprResult ER;
+    ER.V = V;
+    ER.isAggregate = true;
+    return ER;
+  }
+};
+  
 /// CodeGenFunction - This class organizes the per-function state that is used
 /// while generating LLVM code.
 class CodeGenFunction {
@@ -66,6 +87,14 @@
   void EmitCompoundStmt(const CompoundStmt &S);
   void EmitLabelStmt(const LabelStmt &S);
   void EmitGotoStmt(const GotoStmt &S);
+  
+  
+  //===--------------------------------------------------------------------===//
+  //                             Expression Emission
+  //===--------------------------------------------------------------------===//
+
+  ExprResult EmitExpr(const Expr *E);
+  ExprResult EmitIntegerLiteral(const IntegerLiteral *E);
 };
 }  // end namespace CodeGen
 }  // end namespace clang





More information about the cfe-commits mailing list