00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include "CodeGen.h"
00010 #include "CodeGenTypes.h"
00011 #include "InstanceInfo.h"
00012 #include "SRInfo.h"
00013 #include "comma/codegen/Mangle.h"
00014 
00015 using namespace comma;
00016 using llvm::dyn_cast;
00017 using llvm::cast;
00018 using llvm::isa;
00019 
00020 SubroutineDecl *InstanceInfo::getKeySRDecl(SubroutineDecl *srDecl)
00021 {
00022     
00023     
00024     DeclRegion *region = srDecl->getDeclRegion();
00025     if (isa<DomainInstanceDecl>(region)) {
00026         srDecl = srDecl->getOrigin();
00027         region = srDecl->getDeclRegion();
00028     }
00029 
00030     
00031     
00032     assert((isa<PercentDecl>(region) || isa<AddDecl>(region)) &&
00033            "Inconsistent context for subroutine declaration!");
00034 
00035     
00036     if (srDecl->getDefiningDeclaration())
00037         srDecl = srDecl->getDefiningDeclaration();
00038 
00039     return srDecl;
00040 }
00041 
00042 InstanceInfo::InstanceInfo(CodeGen &CG, DomainInstanceDecl *instance)
00043         : instance(instance),
00044           linkName(mangle::getLinkName(instance)),
00045           compiledFlag(false)
00046 {
00047     CodeGenTypes CGT(CG, instance);
00048 
00049     DeclRegion::DeclIter I;
00050     DeclRegion::DeclIter E;
00051 
00052     
00053     
00054     E = instance->endDecls();
00055     for (I = instance->beginDecls(); I != E; ++I) {
00057         if (SubroutineDecl *srDecl = dyn_cast<SubroutineDecl>(*I)) {
00058             SubroutineDecl *key = getKeySRDecl(srDecl);
00059 
00060             assert(!srInfoTable.count(key) &&
00061                    "Multiple declarations map to the same key!");
00062 
00063             llvm::Function *fn = CG.makeFunction(instance, srDecl, CGT);
00064             srInfoTable[key] = new SRInfo(key, fn);
00065         }
00066     }
00067 
00068     
00069     
00070     Domoid *domoid = instance->getDefinition();
00071     AddDecl *impl = domoid->getImplementation();
00072     E = impl->endDecls();
00073     for (I = impl->beginDecls(); I != E; ++I) {
00074         
00075         if (SubroutineDecl *srDecl = dyn_cast<SubroutineDecl>(*I)) {
00076             SubroutineDecl *key = getKeySRDecl(srDecl);
00077 
00078             
00079             
00080             if (srInfoTable.count(key))
00081                 continue;
00082 
00083             llvm::Function *fn = CG.makeFunction(instance, srDecl, CGT);
00084             srInfoTable[key] = new SRInfo(key, fn);
00085         }
00086     }
00087 }