00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef COMMA_CODEGEN_DOMAININFO_HDR_GUARD
00010 #define COMMA_CODEGEN_DOMAININFO_HDR_GUARD
00011
00012 #include "comma/ast/Decl.h"
00013 #include "comma/codegen/CodeGen.h"
00014
00015 #include "llvm/Support/IRBuilder.h"
00016
00017 #include <string>
00018 #include <vector>
00019
00020 namespace comma {
00021
00022 class CommaRT;
00023
00026 class DomainInfo {
00027
00028 public:
00029 DomainInfo(CommaRT &CRT);
00030
00031 void init();
00032
00038 enum FieldId {
00039 Arity,
00040 NumSigs,
00041 Name,
00042 Ctor,
00043 ITable,
00044 SigOffsets,
00045 Exvec
00046 };
00047
00049 const std::string &getTypeName() const { return theTypeName; }
00050
00052 const llvm::StructType *getType() const;
00053
00055 const llvm::PointerType *getPointerTypeTo() const;
00056
00062 const llvm::PointerType *getCtorPtrType() const;
00063
00068 llvm::GlobalVariable *generateInstance(CodeGenCapsule &CGC);
00069
00072 std::string getLinkName(const CodeGenCapsule &CGC) const;
00073
00074 template <FieldId F>
00075 struct FieldIdTraits {
00076 typedef const llvm::PointerType FieldType;
00077 };
00078
00079 template <FieldId F>
00080 typename FieldIdTraits<F>::FieldType *getFieldType() const;
00081
00084 llvm::Value *indexSigOffset(llvm::IRBuilder<> &builder,
00085 llvm::Value *DInfo,
00086 llvm::Value *index) const;
00087
00090 llvm::Value *loadExportVec(llvm::IRBuilder<> &builder,
00091 llvm::Value *DInfo) const;
00092
00095 llvm::Value *loadExportFn(llvm::IRBuilder<> &builder,
00096 llvm::Value *DInfo,
00097 llvm::Value *exportIdx) const;
00098
00099 private:
00100 CommaRT &CRT;
00101 CodeGen &CG;
00102 const llvm::TargetData &TD;
00103
00105 static const std::string theTypeName;
00106
00108 llvm::PATypeHolder theType;
00109
00111 llvm::Constant *genName(CodeGenCapsule &CGC);
00112
00114 llvm::Constant *genArity(CodeGenCapsule &CGC);
00115
00117 llvm::Constant *genSignatureCount(CodeGenCapsule &CGC);
00118
00120 llvm::Constant *genConstructor(CodeGenCapsule &CGC);
00121
00123 llvm::Constant *genITable(CodeGenCapsule &CGC);
00124
00126 llvm::Constant *genSignatureOffsets(CodeGenCapsule &CGC);
00127
00129 llvm::Constant *genExportArray(CodeGenCapsule &CGC);
00130
00136 unsigned
00137 getOffsetsForSignature(SignatureType *sig,
00138 unsigned index,
00139 std::vector<llvm::Constant *> &offsets);
00140
00148 void genInstanceRequirement(llvm::IRBuilder<> &builder,
00149 CodeGenCapsule &CGC,
00150 unsigned ID,
00151 llvm::Value *destVector,
00152 llvm::Value *percent);
00153
00158 void genDomainRequirement(llvm::IRBuilder<> &builder,
00159 CodeGenCapsule &CGC,
00160 unsigned ID,
00161 llvm::Value *destVector);
00162
00167 void genFunctorRequirement(llvm::IRBuilder<> &builder,
00168 CodeGenCapsule &CGC,
00169 unsigned ID,
00170 llvm::Value *destVector,
00171 llvm::Value *percent);
00172 };
00173
00174
00175
00176
00177
00178 template <>
00179 struct DomainInfo::FieldIdTraits<DomainInfo::Arity> {
00180 typedef const llvm::IntegerType FieldType;
00181 };
00182
00183 template <>
00184 struct DomainInfo::FieldIdTraits<DomainInfo::NumSigs> {
00185 typedef const llvm::IntegerType FieldType;
00186 };
00187
00188
00189
00190
00191 template <> inline
00192 DomainInfo::FieldIdTraits<DomainInfo::Arity>::FieldType *
00193 DomainInfo::getFieldType<DomainInfo::Arity>() const {
00194 typedef FieldIdTraits<Arity>::FieldType FTy;
00195 return llvm::cast<FTy>(getType()->getElementType(Arity));
00196 }
00197
00198 template <> inline
00199 DomainInfo::FieldIdTraits<DomainInfo::NumSigs>::FieldType *
00200 DomainInfo::getFieldType<DomainInfo::NumSigs>() const {
00201 typedef FieldIdTraits<NumSigs>::FieldType FTy;
00202 return llvm::cast<FTy>(getType()->getElementType(NumSigs));
00203 }
00204
00205 template <> inline
00206 DomainInfo::FieldIdTraits<DomainInfo::Name>::FieldType *
00207 DomainInfo::getFieldType<DomainInfo::Name>() const {
00208 typedef FieldIdTraits<Name>::FieldType FTy;
00209 return llvm::cast<FTy>(getType()->getElementType(Name));
00210 }
00211
00212 template <> inline
00213 DomainInfo::FieldIdTraits<DomainInfo::Ctor>::FieldType *
00214 DomainInfo::getFieldType<DomainInfo::Ctor>() const {
00215 typedef FieldIdTraits<Ctor>::FieldType FTy;
00216 return llvm::cast<FTy>(getType()->getElementType(Ctor));
00217 }
00218
00219 template <> inline
00220 DomainInfo::FieldIdTraits<DomainInfo::ITable>::FieldType *
00221 DomainInfo::getFieldType<DomainInfo::ITable>() const {
00222 typedef FieldIdTraits<ITable>::FieldType FTy;
00223 return llvm::cast<FTy>(getType()->getElementType(ITable));
00224 }
00225
00226 template <> inline
00227 DomainInfo::FieldIdTraits<DomainInfo::SigOffsets>::FieldType *
00228 DomainInfo::getFieldType<DomainInfo::SigOffsets>() const {
00229 typedef FieldIdTraits<SigOffsets>::FieldType FTy;
00230 return llvm::cast<FTy>(getType()->getElementType(SigOffsets));
00231 }
00232
00233 template <> inline
00234 DomainInfo::FieldIdTraits<DomainInfo::Exvec>::FieldType *
00235 DomainInfo::getFieldType<DomainInfo::Exvec>() const {
00236 typedef FieldIdTraits<Exvec>::FieldType FTy;
00237 return llvm::cast<FTy>(getType()->getElementType(Exvec));
00238 }
00239
00240 };
00241
00242 #endif