blob: a04557bd00cac1ff2ce59fae628abdf1e2bddf65 [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"
Anders Carlsson022012e2007-08-20 18:05:56 +000020using namespace clang;
21using namespace CodeGen;
22
Chris Lattner6de93ff2007-08-26 04:17:05 +000023RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
24 switch (BuiltinID) {
25 default:
26 fprintf(stderr, "Unimplemented builtin!!\n");
27 E->dump();
28
29 // Unknown builtin, for now just dump it out and return undef.
30 if (hasAggregateLLVMType(E->getType()))
31 return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType())));
32 return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
33
34 case Builtin::BI__builtin___CFStringMakeConstantString: {
35 const Expr *Arg = E->getArg(0);
36
37 while (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
38 Arg = PE->getSubExpr();
39
40 const StringLiteral *Literal = cast<StringLiteral>(Arg);
41 std::string S(Literal->getStrData(), Literal->getByteLength());
42
43 return RValue::get(CGM.GetAddrOfConstantCFString(S));
44 }
Anders Carlsson022012e2007-08-20 18:05:56 +000045 }
46
47 return RValue::get(0);
48}
Chris Lattnerbef20ac2007-08-31 04:31:45 +000049
50RValue CodeGenFunction::EmitBuiltinLibFuncExpr(unsigned BuiltinID,
51 const CallExpr *E) {
52 //llvm::Function *Callee = CGM.getBuiltinLibFunction(BuiltinID);
53 return RValue();
54}