00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef COMMA_CODEGEN_COMMART_HDR_GUARD
00010 #define COMMA_CODEGEN_COMMART_HDR_GUARD
00011
00012 #include "comma/ast/AstBase.h"
00013 #include "llvm/Support/IRBuilder.h"
00014
00015 namespace llvm {
00016
00017 class TargetData;
00018
00019 }
00020
00021 namespace comma {
00022
00023 class CodeGen;
00024 class CodeGenCapsule;
00025 class DomainInfo;
00026 class DomainInstance;
00027 class DomainView;
00028 class ExportMap;
00029
00030 class CommaRT {
00031
00032 public:
00033 CommaRT(CodeGen &CG);
00034
00035 ~CommaRT();
00036
00039 CodeGen &getCodeGen() { return CG; }
00040 const CodeGen &getCodeGen() const { return CG; }
00041
00044 ExportMap &getExportMap() { return *EM; }
00045 const ExportMap &getExportMap() const { return *EM; }
00046
00047 enum TypeId {
00048 CRT_ExportFn,
00049 CRT_ITable,
00050 CRT_DomainInfo,
00051 CRT_DomainView,
00052 CRT_DomainInstance,
00053 CRT_DomainCtor
00054 };
00055
00056 template <TypeId F>
00057 struct TypeIdTraits {
00058 typedef const llvm::PointerType FieldType;
00059 };
00060
00061 template <TypeId F>
00062 typename TypeIdTraits<F>::FieldType *getType() const;
00063
00064 const std::string &getTypeName(TypeId id) const;
00065
00066 llvm::GlobalVariable *registerCapsule(CodeGenCapsule &CGC);
00067
00068 void registerSignature(const Sigoid *sigoid);
00069
00070 llvm::Value *getDomain(llvm::IRBuilder<> &builder,
00071 llvm::GlobalValue *capsuleInfo) const;
00072
00073 llvm::Value *getDomain(llvm::IRBuilder<> &builder,
00074 std::vector<llvm::Value*> &args) const;
00075
00076 llvm::Value *getLocalCapsule(llvm::IRBuilder<> &builder,
00077 llvm::Value *percent, unsigned ID) const;
00078
00079 llvm::Value *genAbstractCall(llvm::IRBuilder<> &builder,
00080 llvm::Value *percent,
00081 const SubroutineDecl *srDecl,
00082 const std::vector<llvm::Value *> &args) const;
00083
00084
00085 unsigned getSignatureOffset(Domoid *domoid, SignatureType *target);
00086
00087
00090 const DomainInfo *getDomainInfo() const { return DInfo; }
00091 const DomainView *getDomainView() const { return DView; }
00092 const DomainInstance *getDomainInstance() const { return DInstance; }
00093
00094 private:
00095
00096 CodeGen &CG;
00097
00099 ExportMap *EM;
00100
00101
00102 std::string InvalidName;
00103 std::string ITableName;
00104 std::string DomainCtorName;
00105
00106 DomainInfo *DInfo;
00107 const llvm::PointerType *DomainInfoPtrTy;
00108
00109 DomainView *DView;
00110 const llvm::PointerType *DomainViewPtrTy;
00111
00112 DomainInstance *DInstance;
00113 const llvm::PointerType *DomainInstancePtrTy;
00114
00115 const llvm::PointerType *ExportFnPtrTy;
00116 const llvm::PointerType *ITablePtrTy;
00117 const llvm::PointerType *DomainCtorPtrTy;
00118
00119 std::string GetDomainName;
00120
00121
00122 llvm::Function *getDomainFn;
00123
00124 const llvm::PointerType *getDomainCtorPtrTy();
00125 const llvm::PointerType *getExportFnPtrTy();
00126 const llvm::PointerType *getITablePtrTy();
00127
00128
00129 void defineGetDomain();
00130
00131
00132 void generateRuntimeTypes();
00133
00134
00135
00136 void generateRuntimeFunctions();
00137
00138
00139 llvm::Constant *genCapsuleCtor(CodeGenCapsule &CGC);
00140
00141
00142
00143
00144 void genInstanceRequirement(llvm::IRBuilder<> &builder,
00145 CodeGenCapsule &CGC,
00146 unsigned ID,
00147 llvm::Value *destVector,
00148 llvm::Value *percent);
00149
00154 void genDomainRequirement(llvm::IRBuilder<> &builder,
00155 CodeGenCapsule &CGC,
00156 unsigned ID,
00157 llvm::Value *destVector);
00158
00163 void genFunctorRequirement(llvm::IRBuilder<> &builder,
00164 CodeGenCapsule &CGC,
00165 unsigned ID,
00166 llvm::Value *destVector,
00167 llvm::Value *percent);
00168
00169
00170
00171 llvm::ConstantInt *genSignatureCount(CodeGenCapsule &CGC);
00172
00173 llvm::Constant *genSignatureOffsets(CodeGenCapsule &CGC);
00174
00175 llvm::Constant *genExportArray(CodeGenCapsule &CGC);
00176
00177 unsigned
00178 emitOffsetsForSignature(SignatureType *sig,
00179 unsigned index,
00180 const llvm::Type *elemTy,
00181 std::vector<llvm::Constant *> &offsets);
00182
00183 };
00184
00185 template <> inline
00186 CommaRT::TypeIdTraits<CommaRT::CRT_ExportFn>::FieldType *
00187 CommaRT::getType<CommaRT::CRT_ExportFn>() const {
00188 return ExportFnPtrTy;
00189 }
00190
00191 template <> inline
00192 CommaRT::TypeIdTraits<CommaRT::CRT_ITable>::FieldType *
00193 CommaRT::getType<CommaRT::CRT_ITable>() const {
00194 return ExportFnPtrTy;
00195 }
00196
00197 template <> inline
00198 CommaRT::TypeIdTraits<CommaRT::CRT_DomainInfo>::FieldType *
00199 CommaRT::getType<CommaRT::CRT_DomainInfo>() const {
00200 return DomainInfoPtrTy;
00201 }
00202
00203 template <> inline
00204 CommaRT::TypeIdTraits<CommaRT::CRT_DomainView>::FieldType *
00205 CommaRT::getType<CommaRT::CRT_DomainView>() const {
00206 return DomainViewPtrTy;
00207 }
00208
00209 template <> inline
00210 CommaRT::TypeIdTraits<CommaRT::CRT_DomainInstance>::FieldType *
00211 CommaRT::getType<CommaRT::CRT_DomainInstance>() const {
00212 return DomainInstancePtrTy;
00213 }
00214
00215 template <> inline
00216 CommaRT::TypeIdTraits<CommaRT::CRT_DomainCtor>::FieldType *
00217 CommaRT::getType<CommaRT::CRT_DomainCtor>() const {
00218 return DomainCtorPtrTy;
00219 }
00220
00221 }
00222
00223 #endif
00224