From: Anders Carlsson Date: Mon, 20 Aug 2007 18:05:56 +0000 (+0000) Subject: Add support for code generation of builtins. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=022012e6e5626c3372e1a5493c0929dfc1fa9e47;p=clang Add support for code generation of builtins. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@41188 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/CodeGen/CGBuiltin.cpp b/CodeGen/CGBuiltin.cpp new file mode 100644 index 0000000000..0095bdef48 --- /dev/null +++ b/CodeGen/CGBuiltin.cpp @@ -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); +} diff --git a/CodeGen/CGExpr.cpp b/CodeGen/CGExpr.cpp index b0d34a3380..317a554800 100644 --- a/CodeGen/CGExpr.cpp +++ b/CodeGen/CGExpr.cpp @@ -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(E->getCallee())) + if (const DeclRefExpr *DRExpr = + dyn_cast(IcExpr->getSubExpr())) + if (const FunctionDecl *FDecl = + dyn_cast(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 diff --git a/CodeGen/CodeGenFunction.h b/CodeGen/CodeGenFunction.h index 314896a874..5f78a33738 100644 --- a/CodeGen/CodeGenFunction.h +++ b/CodeGen/CodeGenFunction.h @@ -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.