blob: 833b1882d10664a6f0e486317f90477924e1ca6e [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"
Chris Lattner783a78f2007-08-26 04:17:05 +000018#include "llvm/Constants.h"
Anders Carlsson49865302007-08-20 18:05:56 +000019using namespace clang;
20using namespace CodeGen;
21
Chris Lattner783a78f2007-08-26 04:17:05 +000022RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
23 switch (BuiltinID) {
24 default:
25 fprintf(stderr, "Unimplemented builtin!!\n");
26 E->dump();
27
28 // Unknown builtin, for now just dump it out and return undef.
29 if (hasAggregateLLVMType(E->getType()))
30 return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType())));
31 return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
32
33 case Builtin::BI__builtin___CFStringMakeConstantString: {
34 const Expr *Arg = E->getArg(0);
35
36 while (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
37 Arg = PE->getSubExpr();
38
39 const StringLiteral *Literal = cast<StringLiteral>(Arg);
40 std::string S(Literal->getStrData(), Literal->getByteLength());
41
42 return RValue::get(CGM.GetAddrOfConstantCFString(S));
43 }
Anders Carlsson49865302007-08-20 18:05:56 +000044 }
45
46 return RValue::get(0);
47}