/// Get or create SILGlobalVariable for a given global VarDecl. SILGlobalVariable *SILGenModule::getSILGlobalVariable(VarDecl *gDecl, ForDefinition_t forDef) { // First, get a mangled name for the declaration. std::string mangledName; if (auto SILGenName = gDecl->getAttrs().getAttribute<SILGenNameAttr>()) { mangledName = SILGenName->Name; } else { Mangle::ASTMangler NewMangler; mangledName = NewMangler.mangleGlobalVariableFull(gDecl); } // Check if it is already created, and update linkage if necessary. if (auto gv = M.lookUpGlobalVariable(mangledName)) { // Update the SILLinkage here if this is a definition. if (forDef == ForDefinition) { gv->setLinkage(getSILLinkage(getDeclLinkage(gDecl), ForDefinition)); gv->setDeclaration(false); } return gv; } // Get the linkage for SILGlobalVariable. SILLinkage link = getSILLinkage(getDeclLinkage(gDecl), forDef); SILType silTy = M.Types.getLoweredTypeOfGlobal(gDecl); auto *silGlobal = SILGlobalVariable::create(M, link, IsNotSerialized, mangledName, silTy, None, gDecl); silGlobal->setDeclaration(!forDef); return silGlobal; }