00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef COMMA_CODEGEN_DOMAININSTANCE_HDR_GUARD
00010 #define COMMA_CODEGEN_DOMAININSTANCE_HDR_GUARD
00011
00012 #include "comma/codegen/CodeGen.h"
00013 #include "llvm/Support/IRBuilder.h"
00014
00015 namespace comma {
00016
00017 class CommaRT;
00018
00019 class DomainInstance {
00020
00021 public:
00022 DomainInstance(CommaRT &CRT);
00023
00024 void init();
00025
00026 enum FieldId {
00027 Info,
00028 Next,
00029 Params,
00030 Views,
00031 Requirements
00032 };
00033
00035 const std::string &getTypeName() const { return theTypeName; }
00036
00038 const llvm::StructType *getType() const;
00039
00041 const llvm::PointerType *getPointerTypeTo() const;
00042
00043 template <FieldId F>
00044 struct FieldIdTraits {
00045 typedef const llvm::PointerType FieldType;
00046 };
00047
00048 template <FieldId F>
00049 typename FieldIdTraits<F>::FieldType *getFieldType() const;
00050
00052 llvm::Value *loadInfo(llvm::IRBuilder<> &builder,
00053 llvm::Value *Instance) const;
00054
00057 llvm::Value *loadParamVec(llvm::IRBuilder<> &builder,
00058 llvm::Value *instance) const;
00059
00063 llvm::Value *loadParam(llvm::IRBuilder<> &builder,
00064 llvm::Value *instance,
00065 unsigned paramIdx) const;
00066
00069 llvm::Value *loadViewVec(llvm::IRBuilder<> &builder,
00070 llvm::Value *instance) const;
00071
00074 llvm::Value *loadView(llvm::IRBuilder<> &builder,
00075 llvm::Value *instance,
00076 llvm::Value *sigIndex) const;
00077
00080 llvm::Value *loadView(llvm::IRBuilder<> &builder,
00081 llvm::Value *instance,
00082 unsigned sigIndex) const;
00083
00084 private:
00085 CommaRT &CRT;
00086 CodeGen &CG;
00087 const llvm::TargetData &TD;
00088
00090 static const std::string theTypeName;
00091
00093 llvm::PATypeHolder theType;
00094 };
00095
00096
00097
00098
00099
00100 template <> inline
00101 DomainInstance::FieldIdTraits<DomainInstance::Info>::FieldType *
00102 DomainInstance::getFieldType<DomainInstance::Info>() const {
00103 typedef FieldIdTraits<Info>::FieldType FTy;
00104 return llvm::cast<FTy>(getType()->getElementType(Info));
00105 }
00106
00107 template <> inline
00108 DomainInstance::FieldIdTraits<DomainInstance::Next>::FieldType *
00109 DomainInstance::getFieldType<DomainInstance::Next>() const {
00110 typedef FieldIdTraits<Next>::FieldType FTy;
00111 return llvm::cast<FTy>(getType()->getElementType(Next));
00112 }
00113
00114 template <> inline
00115 DomainInstance::FieldIdTraits<DomainInstance::Params>::FieldType *
00116 DomainInstance::getFieldType<DomainInstance::Params>() const {
00117 typedef FieldIdTraits<Params>::FieldType FTy;
00118 return llvm::cast<FTy>(getType()->getElementType(Params));
00119 }
00120
00121 template <> inline
00122 DomainInstance::FieldIdTraits<DomainInstance::Views>::FieldType *
00123 DomainInstance::getFieldType<DomainInstance::Views>() const {
00124 typedef FieldIdTraits<Views>::FieldType FTy;
00125 return llvm::cast<FTy>(getType()->getElementType(Views));
00126 }
00127
00128 template <> inline
00129 DomainInstance::FieldIdTraits<DomainInstance::Requirements>::FieldType *
00130 DomainInstance::getFieldType<DomainInstance::Requirements>() const {
00131 typedef FieldIdTraits<Requirements>::FieldType FTy;
00132 return llvm::cast<FTy>(getType()->getElementType(Requirements));
00133 }
00134
00135 }
00136
00137 #endif