blob: 769fa5ce3bb365238e3e6c05d8124fc8dcd91a95 [file] [log] [blame]
Anders Carlsson49865302007-08-20 18:05:56 +00001//===---- CGBuiltin.cpp - Emit LLVM Code for builtins ---------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Anders Carlsson and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This contains code to emit Builtin calls as LLVM code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenFunction.h"
15#include "CodeGenModule.h"
16#include "clang/AST/Builtins.h"
17#include "clang/AST/Expr.h"
Anders Carlsson36a04872007-08-21 00:21:21 +000018#include "llvm/Constant.h"
Anders Carlsson49865302007-08-20 18:05:56 +000019
20using namespace clang;
21using namespace CodeGen;
22
23RValue CodeGenFunction::EmitBuiltinExpr(unsigned builtinID, const CallExpr *E)
24{
25 switch (builtinID) {
Anders Carlsson36a04872007-08-21 00:21:21 +000026 case Builtin::BI__builtin___CFStringMakeConstantString: {
27 const Expr *Arg = E->getArg(0);
28
29 while (const ParenExpr *PE = dyn_cast<const ParenExpr>(Arg))
30 Arg = PE->getSubExpr();
31
32 const StringLiteral *Literal = cast<const StringLiteral>(Arg);
33 std::string S(Literal->getStrData(), Literal->getByteLength());
34
35 return RValue::get(CGM.GetAddrOfConstantCFString(S));
36 }
Anders Carlsson49865302007-08-20 18:05:56 +000037 default:
38 assert(0 && "Unknown builtin id");
39 }
40
41 return RValue::get(0);
42}