[Swift+WASM] Allow Wasm object format.

- This currently does nothing more than adopt the ELF conventions, but for the
   Wasm object file format.
This commit is contained in:
Daniel Dunbar
2018-11-20 09:23:28 -07:00
parent 694b153992
commit 1efee0c27a
7 changed files with 24 additions and 19 deletions

View File

@@ -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

View File

@@ -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.");
}

View File

@@ -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.");
}

View File

@@ -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;
}
}

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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");