2007-08-20 22:05:56 +04:00
|
|
|
//===---- 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"
|
2007-08-31 08:31:45 +04:00
|
|
|
#include "clang/AST/ASTContext.h"
|
2007-08-20 22:05:56 +04:00
|
|
|
#include "clang/AST/Builtins.h"
|
|
|
|
#include "clang/AST/Expr.h"
|
2007-08-26 08:17:05 +04:00
|
|
|
#include "llvm/Constants.h"
|
2007-08-31 08:44:06 +04:00
|
|
|
#include "llvm/Function.h"
|
2007-08-20 22:05:56 +04:00
|
|
|
using namespace clang;
|
|
|
|
using namespace CodeGen;
|
|
|
|
|
2007-08-26 08:17:05 +04:00
|
|
|
RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
|
|
|
|
switch (BuiltinID) {
|
|
|
|
default:
|
2007-08-31 08:44:06 +04:00
|
|
|
if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
|
|
|
|
return EmitCallExpr(CGM.getBuiltinLibFunction(BuiltinID), E);
|
|
|
|
|
2007-08-26 08:17:05 +04:00
|
|
|
fprintf(stderr, "Unimplemented builtin!!\n");
|
|
|
|
E->dump();
|
|
|
|
|
|
|
|
// Unknown builtin, for now just dump it out and return undef.
|
|
|
|
if (hasAggregateLLVMType(E->getType()))
|
|
|
|
return RValue::getAggregate(CreateTempAlloca(ConvertType(E->getType())));
|
|
|
|
return RValue::get(llvm::UndefValue::get(ConvertType(E->getType())));
|
|
|
|
|
|
|
|
case Builtin::BI__builtin___CFStringMakeConstantString: {
|
|
|
|
const Expr *Arg = E->getArg(0);
|
|
|
|
|
|
|
|
while (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
|
|
|
|
Arg = PE->getSubExpr();
|
|
|
|
|
|
|
|
const StringLiteral *Literal = cast<StringLiteral>(Arg);
|
|
|
|
std::string S(Literal->getStrData(), Literal->getByteLength());
|
|
|
|
|
|
|
|
return RValue::get(CGM.GetAddrOfConstantCFString(S));
|
|
|
|
}
|
2007-08-20 22:05:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return RValue::get(0);
|
|
|
|
}
|