LValue CodeGenFunction::EmitLValue(const Expr *E) {
switch (E->getStmtClass()) {
default: {
- printf("Statement class: %d\n", E->getStmtClass());
+ printf("Statement class: %d\n", E->getStmtClass());
WarnUnsupported(E, "l-value expression");
llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType()));
return LValue::MakeAddr(llvm::UndefValue::get(Ty));
// a class without recompiling all of the subclasses. If this is the case
// then the CGObjCRuntime subclass must return true to LateBoundIvars and
// implement the lookup itself.
- if(CGM.getObjCRuntime()->LateBoundIVars()) {
+ if (CGM.getObjCRuntime()->LateBoundIVars()) {
assert(0 && "FIXME: Implement support for late-bound instance variables");
return LValue(); // Not reached.
}
- else {
- // Get a structure type for the object
- QualType ExprTy = E->getBase()->getType();
- const llvm::Type *ObjectType = ConvertType(ExprTy);
- //TODO: Add a special case for isa (index 0)
- // Work out which index the ivar is
- const ObjCIvarDecl *Decl = E->getDecl();
- unsigned Index = CGM.getTypes().getLLVMFieldNo(Decl);
+
+ // Get a structure type for the object
+ QualType ExprTy = E->getBase()->getType();
+ const llvm::Type *ObjectType = ConvertType(ExprTy);
+ // TODO: Add a special case for isa (index 0)
+ // Work out which index the ivar is
+ const ObjCIvarDecl *Decl = E->getDecl();
+ unsigned Index = CGM.getTypes().getLLVMFieldNo(Decl);
- // Get object pointer
- llvm::Value * Object = EmitLValue(E->getBase()).getAddress();
- // Coerce object pointer to correct type.
- if (Object->getType() != ObjectType) {
- Object = Builder.CreateBitCast(Object, ObjectType);
- }
- // Get the correct element
- llvm::Value * Element = Builder.CreateStructGEP(Object,
- Index,
- Decl->getName());
- // Element = Builder.CreateLoad(Element);
- return LValue::MakeAddr(Element);
- }
+ // Get object pointer and coerce object pointer to correct type.
+ llvm::Value *Object = EmitLValue(E->getBase()).getAddress();
+ if (Object->getType() != ObjectType)
+ Object = Builder.CreateBitCast(Object, ObjectType);
+
+ // Return a pointer to the right element.
+ return LValue::MakeAddr(Builder.CreateStructGEP(Object, Index,
+ Decl->getName()));
}
RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType,
#include "llvm/GlobalVariable.h"
#include "llvm/Intrinsics.h"
#include "llvm/Support/Compiler.h"
-#include "llvm/ValueSymbolTable.h"
#include <cstdarg>
using namespace clang;
Builder(CGF.Builder),
Runtime(CGF.CGM.getObjCRuntime()) {
}
-
//===--------------------------------------------------------------------===//
// Utilities
return EmitLoadOfLValue(E);
}
Value *VisitObjCMessageExpr(ObjCMessageExpr *E);
- Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E);
+ Value *VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { return EmitLoadOfLValue(E);}
Value *VisitArraySubscriptExpr(ArraySubscriptExpr *E);
Value *VisitMemberExpr(Expr *E) { return EmitLoadOfLValue(E); }
Value *VisitOCUVectorElementExpr(Expr *E) { return EmitLoadOfLValue(E); }
return llvm::UndefValue::get(CGF.ConvertType(E->getType()));
}
-Value *ScalarExprEmitter::VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
- return Builder.CreateLoad(CGF.EmitObjCIvarRefLValue(E).getAddress());
-}
-
Value *ScalarExprEmitter::VisitObjCMessageExpr(ObjCMessageExpr *E) {
// Only the lookup mechanism and first two arguments of the method
// implementation vary between runtimes. We can get the receiver and
// arguments in generic code.
// Find the receiver
- llvm::Value * Receiver = CGF.EmitScalarExpr(E->getReceiver());
+ llvm::Value *Receiver = CGF.EmitScalarExpr(E->getReceiver());
// Process the arguments
- unsigned int ArgC = E->getNumArgs();
+ unsigned ArgC = E->getNumArgs();
llvm::SmallVector<llvm::Value*, 16> Args;
- for(unsigned i=0 ; i<ArgC ; i++) {
+ for (unsigned i = 0; i != ArgC; ++i) {
Expr *ArgExpr = E->getArg(i);
QualType ArgTy = ArgExpr->getType();
if (!CGF.hasAggregateLLVMType(ArgTy)) {
llvm::Constant *Selector = CGF.CGM.GetAddrOfConstantString(SelStr);
llvm::Value *SelPtr = Builder.CreateStructGEP(Selector, 0);
- return Runtime->generateMessageSend(Builder,
- ConvertType(E->getType()),
- CGF.CurFn->getValueSymbolTable().lookup("self"),
- Receiver,
- SelPtr,
- &Args[0],
- Args.size());
+ return Runtime->generateMessageSend(Builder, ConvertType(E->getType()),
+ // FIXME: Self can be assigned to!
+ CGF.CurFn->arg_begin(),
+ Receiver, SelPtr,
+ &Args[0], Args.size());
}
Value *ScalarExprEmitter::VisitArraySubscriptExpr(ArraySubscriptExpr *E) {
CodeGenFunction::CodeGenFunction(CodeGenModule &cgm)
: CGM(cgm), Target(CGM.getContext().Target), SwitchInsn(NULL),
- CaseRangeBlock(NULL) {}
+ CaseRangeBlock(NULL) {}
ASTContext &CodeGenFunction::getContext() const {
return CGM.getContext();
for (unsigned i=0 ; i<OMD->param_size() ; i++) {
ParamTypes.push_back(ConvertType(OMD->getParamDecl(i)->getType()));
}
- CurFn = CGM.getObjCRuntime()->MethodPreamble(ConvertType(OMD->getResultType()),
- llvm::PointerType::getUnqual(llvm::Type::Int32Ty),
- ParamTypes.begin(),
- OMD->param_size(),
- OMD->isVariadic());
+ CurFn =CGM.getObjCRuntime()->MethodPreamble(ConvertType(OMD->getResultType()),
+ llvm::PointerType::getUnqual(llvm::Type::Int32Ty),
+ ParamTypes.begin(),
+ OMD->param_size(),
+ OMD->isVariadic());
llvm::BasicBlock *EntryBB = new llvm::BasicBlock("entry", CurFn);
// Create a marker to make it easy to insert allocas into the entryblock
CodeGenModule::~CodeGenModule() {
llvm::Function *ObjCInitFunction = Runtime->ModuleInitFunction();
- if (ObjCInitFunction) {
+ if (ObjCInitFunction)
AddGlobalCtor(ObjCInitFunction);
- }
EmitGlobalCtors();
delete Runtime;
}
/// called on module load, if any have been registered with AddGlobalCtor.
void CodeGenModule::EmitGlobalCtors() {
if (GlobalCtors.empty()) return;
+
// Get the type of @llvm.global_ctors
std::vector<const llvm::Type*> CtorFields;
CtorFields.push_back(llvm::IntegerType::get(32));
// Constructor function type
std::vector<const llvm::Type*> VoidArgs;
- llvm::FunctionType* CtorFuncTy = llvm::FunctionType::get(
- llvm::Type::VoidTy,
- VoidArgs,
- false);
+ llvm::FunctionType* CtorFuncTy =
+ llvm::FunctionType::get(llvm::Type::VoidTy, VoidArgs, false);
+
// i32, function type pair
const llvm::Type *FPType = llvm::PointerType::getUnqual(CtorFuncTy);
llvm::StructType* CtorStructTy =
GlobalCtorsVal->setInitializer(llvm::ConstantArray::get(GlobalCtorsTy,
CtorValues));
-
}
/// Objective-C object, in the order that they appear. Used to create LLVM
/// structures corresponding to Objective-C objects.
void CodeGenTypes::CollectObjCIvarTypes(ObjCInterfaceDecl *ObjCClass,
- std::vector<const llvm::Type*> &IvarTypes) {
+ std::vector<const llvm::Type*> &IvarTypes) {
ObjCInterfaceDecl *SuperClass = ObjCClass->getSuperClass();
- if(SuperClass) {
+ if (SuperClass)
CollectObjCIvarTypes(SuperClass, IvarTypes);
- }
- for(ObjCInterfaceDecl::ivar_iterator ivar=ObjCClass->ivar_begin() ;
- ivar != ObjCClass->ivar_end() ;
- ivar++) {
- IvarTypes.push_back(ConvertType((*ivar)->getType()));
- ObjCIvarInfo[*ivar] = IvarTypes.size() - 1;
+ for (ObjCInterfaceDecl::ivar_iterator I = ObjCClass->ivar_begin(),
+ E = ObjCClass->ivar_end(); I != E; ++I) {
+ IvarTypes.push_back(ConvertType((*I)->getType()));
+ ObjCIvarInfo[*I] = IvarTypes.size() - 1;
}
}
/// getLLVMFieldNo - Return llvm::StructType element number
/// that corresponds to the field FD.
unsigned CodeGenTypes::getLLVMFieldNo(const FieldDecl *FD) {
- llvm::DenseMap<const FieldDecl *, unsigned>::iterator
- I = FieldInfo.find(FD);
+ llvm::DenseMap<const FieldDecl*, unsigned>::iterator I = FieldInfo.find(FD);
assert (I != FieldInfo.end() && "Unable to find field info");
return I->second;
}
unsigned CodeGenTypes::getLLVMFieldNo(const ObjCIvarDecl *OID) {
llvm::DenseMap<const ObjCIvarDecl*, unsigned>::iterator
I = ObjCIvarInfo.find(OID);
- assert (I != ObjCIvarInfo.end() && "Unable to find field info");
+ assert(I != ObjCIvarInfo.end() && "Unable to find field info");
return I->second;
}