blob: 6dbd2725216b5fd084958f225043eb4ba2b82838 [file] [log] [blame]
Anders Carlsson022012e2007-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"
Chris Lattnerbef20ac2007-08-31 04:31:45 +000016#include "clang/AST/ASTContext.h"
Anders Carlsson022012e2007-08-20 18:05:56 +000017#include "clang/AST/Builtins.h"
18#include "clang/AST/Expr.h"
Chris Lattner6de93ff2007-08-26 04:17:05 +000019#include "llvm/Constants.h"
Chris Lattnerc5e940f2007-08-31 04:44:06 +000020#include "llvm/Function.h"
Anders Carlsson022012e2007-08-20 18:05:56 +000021using namespace clang;
22using namespace CodeGen;
23
Chris Lattner6de93ff2007-08-26 04:17:05 +000024RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
25 switch (BuiltinID) {
26 default:
Chris Lattnerc5e940f2007-08-31 04:44:06 +000027 if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
28 return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), E);
29
Chris Lattner6de93ff2007-08-26 04:17:05 +000030 fprintf(stderr, "Unimplemented builtin!!\n");
Chris Lattner419ea7e2007-09-13 01:17:29 +000031 E->dump(getContext().SourceMgr);
Chris Lattner6de93ff2007-08-26 04:17:05 +000032
33 // Unknown builtin, for now just dump it out and return undef.
34 if (hasAggregateLLVMType(E->getType()))
35 return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType())));
36 return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
37
38 case Builtin::BI__builtin___CFStringMakeConstantString: {
39 const Expr *Arg = E->getArg(0);
40
41 while (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
42 Arg = PE->getSubExpr();
43
44 const StringLiteral *Literal = cast<StringLiteral>(Arg);
45 std::string S(Literal->getStrData(), Literal->getByteLength());
46
47 return RValue::get(CGM.GetAddrOfConstantCFString(S));
48 }
Anders Carlsson022012e2007-08-20 18:05:56 +000049 }
50
51 return RValue::get(0);
52}