diff --git a/include/swift/Basic/Dwarf.h b/include/swift/Basic/Dwarf.h index baac0354c3f16..16e06123f5470 100644 --- a/include/swift/Basic/Dwarf.h +++ b/include/swift/Basic/Dwarf.h @@ -27,6 +27,7 @@ namespace swift { static const char MachOASTSectionName[] = "__ast"; static const char ELFASTSectionName[] = ".swift_ast"; static const char COFFASTSectionName[] = "swiftast"; + static const char WasmASTSectionName[] = ".swift_ast"; } // end namespace swift #endif // SWIFT_BASIC_DWARF_H diff --git a/lib/IRGen/GenClass.cpp b/lib/IRGen/GenClass.cpp index 03478ab57c473..a49a9b8446e05 100644 --- a/lib/IRGen/GenClass.cpp +++ b/lib/IRGen/GenClass.cpp @@ -2050,9 +2050,10 @@ namespace { var->setSection(".data"); break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: var->setSection(".data"); break; - default: + case llvm::Triple::UnknownObjectFormat: llvm_unreachable("Don't know how to emit private global constants for " "the selected object format."); } diff --git a/lib/IRGen/GenDecl.cpp b/lib/IRGen/GenDecl.cpp index 5feff4bfde8bf..3de91be77083a 100644 --- a/lib/IRGen/GenDecl.cpp +++ b/lib/IRGen/GenDecl.cpp @@ -899,7 +899,7 @@ std::string IRGenModule::GetObjCSectionName(StringRef Section, case llvm::Triple::COFF: return ("." + Section.substr(2) + "$B").str(); case llvm::Triple::Wasm: - error(SourceLoc(), "wasm is not a supported object file format"); + return Section.substr(2).str(); } llvm_unreachable("unexpected object file format"); @@ -930,7 +930,6 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV, case llvm::Triple::COFF: return; case llvm::Triple::Wasm: - error(SourceLoc(), "wasm is not a supported object file format"); return; } @@ -1226,18 +1225,19 @@ void IRGenerator::noteUseOfTypeGlobals(NominalTypeDecl *type, static std::string getDynamicReplacementSection(IRGenModule &IGM) { std::string sectionName; switch (IGM.TargetInfo.OutputObjectFormat) { + case llvm::Triple::UnknownObjectFormat: + llvm_unreachable("Don't know how to emit field records table for " + "the selected object format."); case llvm::Triple::MachO: sectionName = "__TEXT, __swift5_replace, regular, no_dead_strip"; break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: sectionName = "swift5_replace"; break; case llvm::Triple::COFF: sectionName = ".sw5repl"; break; - default: - llvm_unreachable("Don't know how to emit field records table for " - "the selected object format."); } return sectionName; } @@ -2700,18 +2700,19 @@ llvm::Constant *IRGenModule::emitSwiftProtocols() { StringRef sectionName; switch (TargetInfo.OutputObjectFormat) { + case llvm::Triple::UnknownObjectFormat: + llvm_unreachable("Don't know how to emit protocols for " + "the selected object format."); case llvm::Triple::MachO: sectionName = "__TEXT, __swift5_protos, regular, no_dead_strip"; break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: sectionName = "swift5_protocols"; break; case llvm::Triple::COFF: sectionName = ".sw5prt$B"; break; - default: - llvm_unreachable("Don't know how to emit protocols for " - "the selected object format."); } var->setSection(sectionName); @@ -2772,18 +2773,19 @@ llvm::Constant *IRGenModule::emitProtocolConformances() { StringRef sectionName; switch (TargetInfo.OutputObjectFormat) { + case llvm::Triple::UnknownObjectFormat: + llvm_unreachable("Don't know how to emit protocol conformances for " + "the selected object format."); case llvm::Triple::MachO: sectionName = "__TEXT, __swift5_proto, regular, no_dead_strip"; break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: sectionName = "swift5_protocol_conformances"; break; case llvm::Triple::COFF: sectionName = ".sw5prtc$B"; break; - default: - llvm_unreachable("Don't know how to emit protocol conformances for " - "the selected object format."); } var->setSection(sectionName); @@ -2803,12 +2805,13 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords() { sectionName = "__TEXT, __swift5_types, regular, no_dead_strip"; break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: sectionName = "swift5_type_metadata"; break; case llvm::Triple::COFF: sectionName = ".sw5tymd$B"; break; - default: + case llvm::Triple::UnknownObjectFormat: llvm_unreachable("Don't know how to emit type metadata table for " "the selected object format."); } @@ -2870,12 +2873,13 @@ llvm::Constant *IRGenModule::emitFieldDescriptors() { sectionName = "__TEXT, __swift5_fieldmd, regular, no_dead_strip"; break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: sectionName = "swift5_fieldmd"; break; case llvm::Triple::COFF: sectionName = ".swift5_fieldmd"; break; - default: + case llvm::Triple::UnknownObjectFormat: llvm_unreachable("Don't know how to emit field records table for " "the selected object format."); } diff --git a/lib/IRGen/GenMeta.cpp b/lib/IRGen/GenMeta.cpp index c97de23998118..23b47ad739d5a 100644 --- a/lib/IRGen/GenMeta.cpp +++ b/lib/IRGen/GenMeta.cpp @@ -119,7 +119,7 @@ void IRGenModule::setTrueConstGlobal(llvm::GlobalVariable *var) { var->setSection(".rdata"); break; case llvm::Triple::Wasm: - llvm_unreachable("web assembly object format is not supported."); + var->setSection(".rodata"); break; } } diff --git a/lib/IRGen/GenReflection.cpp b/lib/IRGen/GenReflection.cpp index 8f50f6010d7c1..331286cdfcf57 100644 --- a/lib/IRGen/GenReflection.cpp +++ b/lib/IRGen/GenReflection.cpp @@ -869,6 +869,7 @@ static std::string getReflectionSectionName(IRGenModule &IGM, OS << ".sw5" << FourCC << "$B"; break; case llvm::Triple::ELF: + case llvm::Triple::Wasm: OS << "swift5_" << LongName; break; case llvm::Triple::MachO: @@ -876,9 +877,6 @@ static std::string getReflectionSectionName(IRGenModule &IGM, "Mach-O section name length must be <= 16 characters"); OS << "__TEXT,__swift5_" << LongName << ", regular, no_dead_strip"; break; - case llvm::Triple::Wasm: - llvm_unreachable("web assembly object format is not supported."); - break; } return OS.str(); } diff --git a/lib/IRGen/IRGen.cpp b/lib/IRGen/IRGen.cpp index 589edae6f3c18..8571898fff6ad 100644 --- a/lib/IRGen/IRGen.cpp +++ b/lib/IRGen/IRGen.cpp @@ -1160,7 +1160,7 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer, Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName; break; case llvm::Triple::Wasm: - llvm_unreachable("web assembly object format is not supported."); + Section = WasmASTSectionName; break; } ASTSym->setSection(Section); diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp index 69c33d25b70e1..0c5628f5c99ed 100644 --- a/lib/IRGen/IRGenModule.cpp +++ b/lib/IRGen/IRGenModule.cpp @@ -1033,6 +1033,7 @@ void IRGenModule::emitAutolinkInfo() { } else { assert((TargetInfo.OutputObjectFormat == llvm::Triple::ELF || + TargetInfo.OutputObjectFormat == llvm::Triple::Wasm || Triple.isOSCygMing()) && "expected ELF output format or COFF format for Cygwin/MinGW");