Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 1 | //===---- 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 Lattner | ab862cc | 2007-08-31 04:31:45 +0000 | [diff] [blame^] | 16 | #include "clang/AST/ASTContext.h" |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 17 | #include "clang/AST/Builtins.h" |
| 18 | #include "clang/AST/Expr.h" |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 19 | #include "llvm/Constants.h" |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 20 | using namespace clang; |
| 21 | using namespace CodeGen; |
| 22 | |
Chris Lattner | 783a78f | 2007-08-26 04:17:05 +0000 | [diff] [blame] | 23 | RValue 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 Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | return RValue::get(0); |
| 48 | } |
Chris Lattner | ab862cc | 2007-08-31 04:31:45 +0000 | [diff] [blame^] | 49 | |
| 50 | RValue CodeGenFunction::EmitBuiltinLibFuncExpr(unsigned BuiltinID, |
| 51 | const CallExpr *E) { |
| 52 | //llvm::Function *Callee = CGM.getBuiltinLibFunction(BuiltinID); |
| 53 | return RValue(); |
| 54 | } |