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 "CodeGen.h"
00013 #include "comma/ast/Decl.h"
00014
00015 #include "llvm/Support/IRBuilder.h"
00016
00017 #include <string>
00018 #include <vector>
00019
00020 namespace comma {
00021
00022 class CommaRT;
00023 class DependencySet;
00024
00027 class DomainInfo {
00028
00029 public:
00030 DomainInfo(CommaRT &CRT);
00031
00032 void init();
00033
00039 enum FieldId {
00040 Arity,
00041 Name,
00042 Ctor,
00043 ITable,
00044 };
00045
00047 const std::string &getTypeName() const { return theTypeName; }
00048
00050 const llvm::StructType *getType() const;
00051
00053 const llvm::PointerType *getPointerTypeTo() const;
00054
00060 const llvm::PointerType *getCtorPtrType() const;
00061
00066 llvm::GlobalVariable *emit(const Domoid *domoid);
00067
00070 static std::string getLinkName(const Domoid *model);
00071
00072 template <FieldId F>
00073 struct FieldIdTraits {
00074 typedef const llvm::PointerType FieldType;
00075 };
00076
00077 template <FieldId F>
00078 typename FieldIdTraits<F>::FieldType *getFieldType() const;
00079
00080 private:
00081 CommaRT &CRT;
00082 CodeGen &CG;
00083 const llvm::TargetData &TD;
00084
00086 static const std::string theTypeName;
00087
00089 llvm::PATypeHolder theType;
00090
00092 llvm::Constant *genName(const Domoid *domoid);
00093
00095 llvm::Constant *genArity(const Domoid *domoid);
00096
00098 llvm::Constant *genConstructor(const Domoid *domoid);
00099
00101 llvm::Constant *genITable(const Domoid *domoid);
00102
00110 void genInstanceRequirement(llvm::IRBuilder<> &builder,
00111 const DependencySet &DS,
00112 unsigned ID,
00113 llvm::Value *destVector,
00114 llvm::Value *percent);
00115
00120 void genDomainRequirement(llvm::IRBuilder<> &builder,
00121 const DependencySet &DS,
00122 unsigned ID,
00123 llvm::Value *destVector);
00124
00129 void genFunctorRequirement(llvm::IRBuilder<> &builder,
00130 const DependencySet &DS,
00131 unsigned ID,
00132 llvm::Value *destVector,
00133 llvm::Value *percent);
00134
00137 static std::string getCtorName(const Domoid *domoid);
00138 };
00139
00140
00141
00142
00143
00144 template <>
00145 struct DomainInfo::FieldIdTraits<DomainInfo::Arity> {
00146 typedef const llvm::IntegerType FieldType;
00147 };
00148
00149
00150
00151
00152 template <> inline
00153 DomainInfo::FieldIdTraits<DomainInfo::Arity>::FieldType *
00154 DomainInfo::getFieldType<DomainInfo::Arity>() const {
00155 typedef FieldIdTraits<Arity>::FieldType FTy;
00156 return llvm::cast<FTy>(getType()->getElementType(Arity));
00157 }
00158
00159 template <> inline
00160 DomainInfo::FieldIdTraits<DomainInfo::Name>::FieldType *
00161 DomainInfo::getFieldType<DomainInfo::Name>() const {
00162 typedef FieldIdTraits<Name>::FieldType FTy;
00163 return llvm::cast<FTy>(getType()->getElementType(Name));
00164 }
00165
00166 template <> inline
00167 DomainInfo::FieldIdTraits<DomainInfo::Ctor>::FieldType *
00168 DomainInfo::getFieldType<DomainInfo::Ctor>() const {
00169 typedef FieldIdTraits<Ctor>::FieldType FTy;
00170 return llvm::cast<FTy>(getType()->getElementType(Ctor));
00171 }
00172
00173 template <> inline
00174 DomainInfo::FieldIdTraits<DomainInfo::ITable>::FieldType *
00175 DomainInfo::getFieldType<DomainInfo::ITable>() const {
00176 typedef FieldIdTraits<ITable>::FieldType FTy;
00177 return llvm::cast<FTy>(getType()->getElementType(ITable));
00178 }
00179
00180 };
00181
00182 #endif