00001 //===-- codegen/CGContext.cpp --------------------------------- -*- C++ -*-===// 00002 // 00003 // This file is distributed under the MIT license. See LICENSE.txt for details. 00004 // 00005 // Copyright (C) 2009, Stephen Wilson 00006 // 00007 //===----------------------------------------------------------------------===// 00008 00009 #include "CGContext.h" 00010 00011 using namespace comma; 00012 00013 using llvm::dyn_cast; 00014 using llvm::cast; 00015 using llvm::isa; 00016 00017 CGContext::CGContext(CodeGen &CG, InstanceInfo *IInfo) 00018 : CG(CG), 00019 IInfo(IInfo), 00020 CGT(CG, IInfo->getInstanceDecl()) 00021 { 00022 DomainInstanceDecl *instance = IInfo->getInstanceDecl(); 00023 Domoid *domoid = IInfo->getDefinition(); 00024 if (FunctorDecl *functor = dyn_cast<FunctorDecl>(domoid)) { 00025 for (unsigned i = 0; i < instance->getArity(); ++i) { 00026 DomainType *formal = functor->getFormalType(i); 00027 DomainType *actual = instance->getActualParamType(i); 00028 paramMap[formal] = actual; 00029 } 00030 } 00031 } 00032 00033 bool CGContext::generatingCapsuleInstance() const 00034 { 00035 if (generatingCapsule()) 00036 return IInfo->getInstanceDecl()->isParameterized(); 00037 return false; 00038 } 00039 00040 DomainInstanceDecl * 00041 CGContext::rewriteAbstractDecl(AbstractDomainDecl *abstract) const { 00042 typedef ParameterMap::const_iterator iterator; 00043 iterator I = paramMap.find(abstract->getType()); 00044 if (I == paramMap.end()) 00045 return 0; 00046 DomainType *domTy = cast<DomainType>(I->second); 00047 return cast<DomainInstanceDecl>(domTy->getDomainTypeDecl()); 00048 } 00049 00050