Skip to content

Commit 1efee0c

Browse files
committed
[Swift+WASM] Allow Wasm object format.
- This currently does nothing more than adopt the ELF conventions, but for the Wasm object file format.
1 parent 694b153 commit 1efee0c

File tree

7 files changed

+24
-19
lines changed

7 files changed

+24
-19
lines changed

include/swift/Basic/Dwarf.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace swift {
2727
static const char MachOASTSectionName[] = "__ast";
2828
static const char ELFASTSectionName[] = ".swift_ast";
2929
static const char COFFASTSectionName[] = "swiftast";
30+
static const char WasmASTSectionName[] = ".swift_ast";
3031
} // end namespace swift
3132

3233
#endif // SWIFT_BASIC_DWARF_H

lib/IRGen/GenClass.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2050,9 +2050,10 @@ namespace {
20502050
var->setSection(".data");
20512051
break;
20522052
case llvm::Triple::ELF:
2053+
case llvm::Triple::Wasm:
20532054
var->setSection(".data");
20542055
break;
2055-
default:
2056+
case llvm::Triple::UnknownObjectFormat:
20562057
llvm_unreachable("Don't know how to emit private global constants for "
20572058
"the selected object format.");
20582059
}

lib/IRGen/GenDecl.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ std::string IRGenModule::GetObjCSectionName(StringRef Section,
899899
case llvm::Triple::COFF:
900900
return ("." + Section.substr(2) + "$B").str();
901901
case llvm::Triple::Wasm:
902-
error(SourceLoc(), "wasm is not a supported object file format");
902+
return Section.substr(2).str();
903903
}
904904

905905
llvm_unreachable("unexpected object file format");
@@ -930,7 +930,6 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV,
930930
case llvm::Triple::COFF:
931931
return;
932932
case llvm::Triple::Wasm:
933-
error(SourceLoc(), "wasm is not a supported object file format");
934933
return;
935934
}
936935

@@ -1226,18 +1225,19 @@ void IRGenerator::noteUseOfTypeGlobals(NominalTypeDecl *type,
12261225
static std::string getDynamicReplacementSection(IRGenModule &IGM) {
12271226
std::string sectionName;
12281227
switch (IGM.TargetInfo.OutputObjectFormat) {
1228+
case llvm::Triple::UnknownObjectFormat:
1229+
llvm_unreachable("Don't know how to emit field records table for "
1230+
"the selected object format.");
12291231
case llvm::Triple::MachO:
12301232
sectionName = "__TEXT, __swift5_replace, regular, no_dead_strip";
12311233
break;
12321234
case llvm::Triple::ELF:
1235+
case llvm::Triple::Wasm:
12331236
sectionName = "swift5_replace";
12341237
break;
12351238
case llvm::Triple::COFF:
12361239
sectionName = ".sw5repl";
12371240
break;
1238-
default:
1239-
llvm_unreachable("Don't know how to emit field records table for "
1240-
"the selected object format.");
12411241
}
12421242
return sectionName;
12431243
}
@@ -2700,18 +2700,19 @@ llvm::Constant *IRGenModule::emitSwiftProtocols() {
27002700

27012701
StringRef sectionName;
27022702
switch (TargetInfo.OutputObjectFormat) {
2703+
case llvm::Triple::UnknownObjectFormat:
2704+
llvm_unreachable("Don't know how to emit protocols for "
2705+
"the selected object format.");
27032706
case llvm::Triple::MachO:
27042707
sectionName = "__TEXT, __swift5_protos, regular, no_dead_strip";
27052708
break;
27062709
case llvm::Triple::ELF:
2710+
case llvm::Triple::Wasm:
27072711
sectionName = "swift5_protocols";
27082712
break;
27092713
case llvm::Triple::COFF:
27102714
sectionName = ".sw5prt$B";
27112715
break;
2712-
default:
2713-
llvm_unreachable("Don't know how to emit protocols for "
2714-
"the selected object format.");
27152716
}
27162717

27172718
var->setSection(sectionName);
@@ -2772,18 +2773,19 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
27722773

27732774
StringRef sectionName;
27742775
switch (TargetInfo.OutputObjectFormat) {
2776+
case llvm::Triple::UnknownObjectFormat:
2777+
llvm_unreachable("Don't know how to emit protocol conformances for "
2778+
"the selected object format.");
27752779
case llvm::Triple::MachO:
27762780
sectionName = "__TEXT, __swift5_proto, regular, no_dead_strip";
27772781
break;
27782782
case llvm::Triple::ELF:
2783+
case llvm::Triple::Wasm:
27792784
sectionName = "swift5_protocol_conformances";
27802785
break;
27812786
case llvm::Triple::COFF:
27822787
sectionName = ".sw5prtc$B";
27832788
break;
2784-
default:
2785-
llvm_unreachable("Don't know how to emit protocol conformances for "
2786-
"the selected object format.");
27872789
}
27882790

27892791
var->setSection(sectionName);
@@ -2803,12 +2805,13 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords() {
28032805
sectionName = "__TEXT, __swift5_types, regular, no_dead_strip";
28042806
break;
28052807
case llvm::Triple::ELF:
2808+
case llvm::Triple::Wasm:
28062809
sectionName = "swift5_type_metadata";
28072810
break;
28082811
case llvm::Triple::COFF:
28092812
sectionName = ".sw5tymd$B";
28102813
break;
2811-
default:
2814+
case llvm::Triple::UnknownObjectFormat:
28122815
llvm_unreachable("Don't know how to emit type metadata table for "
28132816
"the selected object format.");
28142817
}
@@ -2870,12 +2873,13 @@ llvm::Constant *IRGenModule::emitFieldDescriptors() {
28702873
sectionName = "__TEXT, __swift5_fieldmd, regular, no_dead_strip";
28712874
break;
28722875
case llvm::Triple::ELF:
2876+
case llvm::Triple::Wasm:
28732877
sectionName = "swift5_fieldmd";
28742878
break;
28752879
case llvm::Triple::COFF:
28762880
sectionName = ".swift5_fieldmd";
28772881
break;
2878-
default:
2882+
case llvm::Triple::UnknownObjectFormat:
28792883
llvm_unreachable("Don't know how to emit field records table for "
28802884
"the selected object format.");
28812885
}

lib/IRGen/GenMeta.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void IRGenModule::setTrueConstGlobal(llvm::GlobalVariable *var) {
119119
var->setSection(".rdata");
120120
break;
121121
case llvm::Triple::Wasm:
122-
llvm_unreachable("web assembly object format is not supported.");
122+
var->setSection(".rodata");
123123
break;
124124
}
125125
}

lib/IRGen/GenReflection.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,14 @@ static std::string getReflectionSectionName(IRGenModule &IGM,
869869
OS << ".sw5" << FourCC << "$B";
870870
break;
871871
case llvm::Triple::ELF:
872+
case llvm::Triple::Wasm:
872873
OS << "swift5_" << LongName;
873874
break;
874875
case llvm::Triple::MachO:
875876
assert(LongName.size() <= 7 &&
876877
"Mach-O section name length must be <= 16 characters");
877878
OS << "__TEXT,__swift5_" << LongName << ", regular, no_dead_strip";
878879
break;
879-
case llvm::Triple::Wasm:
880-
llvm_unreachable("web assembly object format is not supported.");
881-
break;
882880
}
883881
return OS.str();
884882
}

lib/IRGen/IRGen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ swift::createSwiftModuleObjectFile(SILModule &SILMod, StringRef Buffer,
11601160
Section = std::string(MachOASTSegmentName) + "," + MachOASTSectionName;
11611161
break;
11621162
case llvm::Triple::Wasm:
1163-
llvm_unreachable("web assembly object format is not supported.");
1163+
Section = WasmASTSectionName;
11641164
break;
11651165
}
11661166
ASTSym->setSection(Section);

lib/IRGen/IRGenModule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ void IRGenModule::emitAutolinkInfo() {
10331033

10341034
} else {
10351035
assert((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
1036+
TargetInfo.OutputObjectFormat == llvm::Triple::Wasm ||
10361037
Triple.isOSCygMing()) &&
10371038
"expected ELF output format or COFF format for Cygwin/MinGW");
10381039

0 commit comments

Comments
 (0)