00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "DomainInstance.h"
00010 #include "comma/codegen/CommaRT.h"
00011
00012 using namespace comma;
00013
00014 using llvm::dyn_cast;
00015 using llvm::cast;
00016 using llvm::isa;
00017
00018 DomainInstance::DomainInstance(CommaRT &CRT)
00019 : CRT(CRT),
00020 CG(CRT.getCodeGen()),
00021 TD(CG.getTargetData()),
00022 theType(llvm::OpaqueType::get()) { }
00023
00024 void DomainInstance::init()
00025 {
00026 std::vector<const llvm::Type*> members;
00027
00028 const llvm::PointerType *InfoPtrTy;
00029 const llvm::PointerType *ViewPtrTy;
00030 const llvm::Type *ViewTy;
00031 const llvm::PointerType *InstancePtrTy;
00032
00033 InfoPtrTy = CRT.getType<CommaRT::CRT_DomainInfo>();
00034 ViewPtrTy = CRT.getType<CommaRT::CRT_DomainView>();
00035 ViewTy = ViewPtrTy->getElementType();
00036 InstancePtrTy = llvm::PointerType::getUnqual(theType.get());
00037
00038 members.push_back(InfoPtrTy);
00039 members.push_back(theType.get());
00040 members.push_back(CG.getPointerType(ViewPtrTy));
00041 members.push_back(CG.getPointerType(ViewTy));
00042 members.push_back(CG.getPointerType(InstancePtrTy));
00043
00044 llvm::StructType *InstanceTy = llvm::StructType::get(members);
00045 cast<llvm::OpaqueType>(theType.get())->refineAbstractTypeTo(InstanceTy);
00046 }
00047
00048 const std::string DomainInstance::theTypeName("comma_instance_t");
00049
00050 const llvm::StructType *DomainInstance::getType() const
00051 {
00052 return cast<llvm::StructType>(theType.get());
00053 }
00054
00055 const llvm::PointerType *DomainInstance::getPointerTypeTo() const
00056 {
00057 return llvm::PointerType::getUnqual(theType.get());
00058 }
00059
00061 llvm::Value *DomainInstance::loadInfo(llvm::IRBuilder<> &builder,
00062 llvm::Value *Instance) const
00063 {
00064 assert(Instance->getType() == getPointerTypeTo() &&
00065 "Wrong type of LLVM Value!");
00066
00067 llvm::Value *InfoAddr = builder.CreateStructGEP(Instance, Info);
00068 return builder.CreateLoad(InfoAddr);
00069 }
00070
00073 llvm::Value *DomainInstance::loadParamVec(llvm::IRBuilder<> &builder,
00074 llvm::Value *instance) const
00075 {
00076 assert(instance->getType() == getPointerTypeTo() &&
00077 "Wrong type of LLVM Value!");
00078
00079 llvm::Value *paramsAddr = builder.CreateStructGEP(instance, Params);
00080 return builder.CreateLoad(paramsAddr);
00081 }
00082
00085 llvm::Value *DomainInstance::loadParam(llvm::IRBuilder<> &builder,
00086 llvm::Value *instance,
00087 unsigned paramIdx) const
00088 {
00089 assert(instance->getType() == getPointerTypeTo() &&
00090 "Wrong type of LLVM Value!");
00091
00092 llvm::Value *index = llvm::ConstantInt::get(llvm::Type::Int32Ty, paramIdx);
00093
00094 llvm::Value *paramVec = loadParamVec(builder, instance);
00095 llvm::Value *viewAddr = builder.CreateGEP(paramVec, index);
00096 return builder.CreateLoad(viewAddr);
00097 }
00098
00101 llvm::Value *DomainInstance::loadViewVec(llvm::IRBuilder<> &builder,
00102 llvm::Value *instance) const
00103 {
00104 assert(instance->getType() == getPointerTypeTo() &&
00105 "Wrong type of LLVM Value!");
00106
00107 llvm::Value *vecAddr = builder.CreateStructGEP(instance, Views);
00108 return builder.CreateLoad(vecAddr);
00109 }
00110
00113 llvm::Value *DomainInstance::loadView(llvm::IRBuilder<> &builder,
00114 llvm::Value *instance,
00115 llvm::Value *sigIndex) const
00116 {
00117 assert(instance->getType() == getPointerTypeTo() &&
00118 "Wrong type of LLVM Value!");
00119
00120 llvm::Value *viewArr = loadViewVec(builder, instance);
00121 return builder.CreateGEP(viewArr, sigIndex);
00122 }
00123
00124
00127 llvm::Value *DomainInstance::loadView(llvm::IRBuilder<> &builder,
00128 llvm::Value *instance,
00129 unsigned sigIndex) const
00130 {
00131 llvm::Value *index = llvm::ConstantInt::get(llvm::Type::Int32Ty, sigIndex);
00132 return loadView(builder, instance, index);
00133 }