Skip to content

[Swift+WASM] Allow Wasm object format. #20687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Basic/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/IRGen/GenClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down
30 changes: 17 additions & 13 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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.");
}
Expand Down Expand Up @@ -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.");
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 1 addition & 3 deletions lib/IRGen/GenReflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -869,16 +869,14 @@ 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:
assert(LongName.size() <= 7 &&
"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();
}
Expand Down
2 changes: 1 addition & 1 deletion lib/IRGen/IRGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand Down