Skip to content

Commit 8980213

Browse files
authored
Merge pull request #20687 from ddunbar/swasm-allow-wasm-object-format
[Swift+WASM] Allow Wasm object format.
2 parents 3f4990d + 1efee0c commit 8980213

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
@@ -2055,9 +2055,10 @@ namespace {
20552055
var->setSection(".data");
20562056
break;
20572057
case llvm::Triple::ELF:
2058+
case llvm::Triple::Wasm:
20582059
var->setSection(".data");
20592060
break;
2060-
default:
2061+
case llvm::Triple::UnknownObjectFormat:
20612062
llvm_unreachable("Don't know how to emit private global constants for "
20622063
"the selected object format.");
20632064
}

lib/IRGen/GenDecl.cpp

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

907907
llvm_unreachable("unexpected object file format");
@@ -932,7 +932,6 @@ void IRGenModule::SetCStringLiteralSection(llvm::GlobalVariable *GV,
932932
case llvm::Triple::COFF:
933933
return;
934934
case llvm::Triple::Wasm:
935-
error(SourceLoc(), "wasm is not a supported object file format");
936935
return;
937936
}
938937

@@ -1211,18 +1210,19 @@ void IRGenerator::noteUseOfTypeGlobals(NominalTypeDecl *type,
12111210
static std::string getDynamicReplacementSection(IRGenModule &IGM) {
12121211
std::string sectionName;
12131212
switch (IGM.TargetInfo.OutputObjectFormat) {
1213+
case llvm::Triple::UnknownObjectFormat:
1214+
llvm_unreachable("Don't know how to emit field records table for "
1215+
"the selected object format.");
12141216
case llvm::Triple::MachO:
12151217
sectionName = "__TEXT, __swift5_replace, regular, no_dead_strip";
12161218
break;
12171219
case llvm::Triple::ELF:
1220+
case llvm::Triple::Wasm:
12181221
sectionName = "swift5_replace";
12191222
break;
12201223
case llvm::Triple::COFF:
12211224
sectionName = ".sw5repl$B";
12221225
break;
1223-
default:
1224-
llvm_unreachable("Don't know how to emit field records table for "
1225-
"the selected object format.");
12261226
}
12271227
return sectionName;
12281228
}
@@ -2674,18 +2674,19 @@ llvm::Constant *IRGenModule::emitSwiftProtocols() {
26742674

26752675
StringRef sectionName;
26762676
switch (TargetInfo.OutputObjectFormat) {
2677+
case llvm::Triple::UnknownObjectFormat:
2678+
llvm_unreachable("Don't know how to emit protocols for "
2679+
"the selected object format.");
26772680
case llvm::Triple::MachO:
26782681
sectionName = "__TEXT, __swift5_protos, regular, no_dead_strip";
26792682
break;
26802683
case llvm::Triple::ELF:
2684+
case llvm::Triple::Wasm:
26812685
sectionName = "swift5_protocols";
26822686
break;
26832687
case llvm::Triple::COFF:
26842688
sectionName = ".sw5prt$B";
26852689
break;
2686-
default:
2687-
llvm_unreachable("Don't know how to emit protocols for "
2688-
"the selected object format.");
26892690
}
26902691

26912692
var->setSection(sectionName);
@@ -2733,18 +2734,19 @@ llvm::Constant *IRGenModule::emitProtocolConformances() {
27332734

27342735
StringRef sectionName;
27352736
switch (TargetInfo.OutputObjectFormat) {
2737+
case llvm::Triple::UnknownObjectFormat:
2738+
llvm_unreachable("Don't know how to emit protocol conformances for "
2739+
"the selected object format.");
27362740
case llvm::Triple::MachO:
27372741
sectionName = "__TEXT, __swift5_proto, regular, no_dead_strip";
27382742
break;
27392743
case llvm::Triple::ELF:
2744+
case llvm::Triple::Wasm:
27402745
sectionName = "swift5_protocol_conformances";
27412746
break;
27422747
case llvm::Triple::COFF:
27432748
sectionName = ".sw5prtc$B";
27442749
break;
2745-
default:
2746-
llvm_unreachable("Don't know how to emit protocol conformances for "
2747-
"the selected object format.");
27482750
}
27492751

27502752
var->setSection(sectionName);
@@ -2764,12 +2766,13 @@ llvm::Constant *IRGenModule::emitTypeMetadataRecords() {
27642766
sectionName = "__TEXT, __swift5_types, regular, no_dead_strip";
27652767
break;
27662768
case llvm::Triple::ELF:
2769+
case llvm::Triple::Wasm:
27672770
sectionName = "swift5_type_metadata";
27682771
break;
27692772
case llvm::Triple::COFF:
27702773
sectionName = ".sw5tymd$B";
27712774
break;
2772-
default:
2775+
case llvm::Triple::UnknownObjectFormat:
27732776
llvm_unreachable("Don't know how to emit type metadata table for "
27742777
"the selected object format.");
27752778
}
@@ -2831,12 +2834,13 @@ llvm::Constant *IRGenModule::emitFieldDescriptors() {
28312834
sectionName = "__TEXT, __swift5_fieldmd, regular, no_dead_strip";
28322835
break;
28332836
case llvm::Triple::ELF:
2837+
case llvm::Triple::Wasm:
28342838
sectionName = "swift5_fieldmd";
28352839
break;
28362840
case llvm::Triple::COFF:
28372841
sectionName = ".swift5_fieldmd";
28382842
break;
2839-
default:
2843+
case llvm::Triple::UnknownObjectFormat:
28402844
llvm_unreachable("Don't know how to emit field records table for "
28412845
"the selected object format.");
28422846
}

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
@@ -1055,6 +1055,7 @@ void IRGenModule::emitAutolinkInfo() {
10551055

10561056
} else {
10571057
assert((TargetInfo.OutputObjectFormat == llvm::Triple::ELF ||
1058+
TargetInfo.OutputObjectFormat == llvm::Triple::Wasm ||
10581059
Triple.isOSCygMing()) &&
10591060
"expected ELF output format or COFF format for Cygwin/MinGW");
10601061

0 commit comments

Comments
 (0)