]> granicus.if.org Git - clang/commitdiff
Add support for code generation of builtins.
authorAnders Carlsson <andersca@mac.com>
Mon, 20 Aug 2007 18:05:56 +0000 (18:05 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 20 Aug 2007 18:05:56 +0000 (18:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41188 91177308-0d34-0410-b5e6-96231b3b80d8

CodeGen/CGBuiltin.cpp [new file with mode: 0644]
CodeGen/CGExpr.cpp
CodeGen/CodeGenFunction.h

diff --git a/CodeGen/CGBuiltin.cpp b/CodeGen/CGBuiltin.cpp
new file mode 100644 (file)
index 0000000..0095bde
--- /dev/null
@@ -0,0 +1,30 @@
+//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Anders Carlsson and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This contains code to emit Builtin calls as LLVM code.
+//
+//===----------------------------------------------------------------------===//
+
+#include "CodeGenFunction.h"
+#include "CodeGenModule.h"
+#include "clang/AST/Builtins.h"
+#include "clang/AST/Expr.h"
+
+using namespace clang;
+using namespace CodeGen;
+
+RValue CodeGenFunction::EmitBuiltinExpr(unsigned builtinID, const CallExpr *E)
+{
+  switch (builtinID) {
+    default:
+      assert(0 && "Unknown builtin id");
+  }
+      
+  return RValue::get(0);
+}
index b0d34a33807d76c12e6b6652b9ad050eddb480d6..317a5548006e1537f36d1bfde869691a08333e9e 100644 (file)
@@ -14,6 +14,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/AST/AST.h"
+#include "clang/Lex/IdentifierTable.h"
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
@@ -660,6 +661,15 @@ RValue CodeGenFunction::EmitCastExpr(const Expr *Op, QualType DestTy) {
 }
 
 RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) {
+  if (const ImplicitCastExpr *IcExpr = 
+      dyn_cast<const ImplicitCastExpr>(E->getCallee()))
+    if (const DeclRefExpr *DRExpr = 
+        dyn_cast<const DeclRefExpr>(IcExpr->getSubExpr()))
+      if (const FunctionDecl *FDecl = 
+          dyn_cast<const FunctionDecl>(DRExpr->getDecl()))
+        if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID())
+          return EmitBuiltinExpr(builtinID, E);
+        
   llvm::Value *Callee = EmitExpr(E->getCallee()).getVal();
   
   // The callee type will always be a pointer to function type, get the function
index 314896a874fba19d4694bdf8b05b274411e5a0a2..5f78a3373875b002eb40b590f989dcbfb9d08de1 100644 (file)
@@ -352,6 +352,7 @@ public:
    
   RValue EmitCastExpr(const Expr *Op, QualType DestTy);
   RValue EmitCallExpr(const CallExpr *E);
+  RValue EmitBuiltinExpr(unsigned builtinID, const CallExpr *E);
   RValue EmitArraySubscriptExprRV(const ArraySubscriptExpr *E);
 
   // Unary Operators.