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" |
| 16 | #include "clang/AST/Builtins.h" |
| 17 | #include "clang/AST/Expr.h" |
Anders Carlsson | 36a0487 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 18 | #include "llvm/Constant.h" |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | using namespace CodeGen; |
| 22 | |
| 23 | RValue CodeGenFunction::EmitBuiltinExpr(unsigned builtinID, const CallExpr *E) |
| 24 | { |
| 25 | switch (builtinID) { |
Anders Carlsson | 36a0487 | 2007-08-21 00:21:21 +0000 | [diff] [blame] | 26 | case Builtin::BI__builtin___CFStringMakeConstantString: { |
| 27 | const Expr *Arg = E->getArg(0); |
| 28 | |
| 29 | while (const ParenExpr *PE = dyn_cast<const ParenExpr>(Arg)) |
| 30 | Arg = PE->getSubExpr(); |
| 31 | |
| 32 | const StringLiteral *Literal = cast<const StringLiteral>(Arg); |
| 33 | std::string S(Literal->getStrData(), Literal->getByteLength()); |
| 34 | |
| 35 | return RValue::get(CGM.GetAddrOfConstantCFString(S)); |
| 36 | } |
Anders Carlsson | 4986530 | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 37 | default: |
| 38 | assert(0 && "Unknown builtin id"); |
| 39 | } |
| 40 | |
| 41 | return RValue::get(0); |
| 42 | } |