Skip to content

Commit 47cd951

Browse files
committed
Merge pull request #2817 from compnerd/reflection
IRGen: support reflection for swift 3 on COFF
2 parents e33def8 + 83b2b59 commit 47cd951

File tree

2 files changed

+50
-18
lines changed

2 files changed

+50
-18
lines changed

lib/IRGen/GenReflection.cpp

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -705,47 +705,52 @@ class CaptureDescriptorBuilder : public ReflectionMetadataBuilder {
705705
};
706706

707707
static std::string getReflectionSectionName(IRGenModule &IGM,
708-
std::string Base) {
708+
StringRef LongName,
709+
StringRef FourCC) {
709710
SmallString<50> SectionName;
710711
llvm::raw_svector_ostream OS(SectionName);
711712
switch (IGM.TargetInfo.OutputObjectFormat) {
712-
case llvm::Triple::MachO:
713-
assert(Base.size() <= 7
714-
&& "Mach-O section name length must be <= 16 characters");
715-
OS << "__TEXT, __swift3_" << Base << ", regular, no_dead_strip";
716-
break;
717-
case llvm::Triple::ELF:
718-
OS << ".swift3_" << Base;
719-
break;
720-
default:
721-
llvm_unreachable("Don't know how to emit field name table for "
722-
"the selected object format.");
713+
case llvm::Triple::UnknownObjectFormat:
714+
llvm_unreachable("unknown object format");
715+
case llvm::Triple::COFF:
716+
assert(FourCC.size() <= 4 &&
717+
"COFF section name length must be <= 8 characters");
718+
OS << ".sw3" << FourCC;
719+
break;
720+
case llvm::Triple::ELF:
721+
OS << ".swift3_" << LongName;
722+
break;
723+
case llvm::Triple::MachO:
724+
assert(LongName.size() <= 7 &&
725+
"Mach-O section name length must be <= 16 characters");
726+
OS << "__TEXT,__swift3_" << LongName << ", regular, no_dead_strip";
727+
break;
723728
}
724729
return OS.str();
725730
}
726731

727732
std::string IRGenModule::getFieldTypeMetadataSectionName() {
728-
return getReflectionSectionName(*this, "fieldmd");
733+
return getReflectionSectionName(*this, "fieldmd", "flmd");
729734
}
730735

731736
std::string IRGenModule::getBuiltinTypeMetadataSectionName() {
732-
return getReflectionSectionName(*this, "builtin");
737+
return getReflectionSectionName(*this, "builtin", "bltn");
733738
}
734739

735740
std::string IRGenModule::getAssociatedTypeMetadataSectionName() {
736-
return getReflectionSectionName(*this, "assocty");
741+
return getReflectionSectionName(*this, "assocty", "asty");
737742
}
738743

739744
std::string IRGenModule::getCaptureDescriptorMetadataSectionName() {
740-
return getReflectionSectionName(*this, "capture");
745+
return getReflectionSectionName(*this, "capture", "cptr");
741746
}
742747

743748
std::string IRGenModule::getReflectionStringsSectionName() {
744-
return getReflectionSectionName(*this, "reflstr");
749+
return getReflectionSectionName(*this, "reflstr", "rfst");
745750
}
746751

747752
std::string IRGenModule::getReflectionTypeRefSectionName() {
748-
return getReflectionSectionName(*this, "typeref");
753+
return getReflectionSectionName(*this, "typeref", "tyrf");
749754
}
750755

751756
llvm::Constant *IRGenModule::getAddrOfFieldName(StringRef Name) {

test/IRGen/swift3-metadata-coff.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %swift -target thumbv7--windows-itanium -parse-stdlib -parse-as-library -module-name Swift -O -emit-ir %s -o - | FileCheck %s
2+
3+
public enum Optional<Wrapped> {
4+
case none
5+
case some(Wrapped)
6+
}
7+
8+
public protocol P {
9+
associatedtype T
10+
}
11+
12+
public struct S : P {
13+
public typealias T = Optional<S>
14+
}
15+
16+
public func f(s : S) -> (() -> ()) {
17+
return { _ = s }
18+
}
19+
20+
// CHECK-DAG: @"\01l__swift3_capture_descriptor" = private constant {{.*}}, section ".sw3cptr"
21+
// CHECK-DAG: @{{[0-9]+}} = private constant [3 x i8] c"Sq\00", section ".sw3tyrf"
22+
// CHECK-DAG: @{{[0-9]+}} = private constant [5 x i8] c"none\00", section ".sw3rfst"
23+
// CHECK-DAG: @{{[0-9]+}} = private constant [5 x i8] c"some\00", section ".sw3rfst"
24+
// CHECK-DAG: @"\01l__swift3_reflection_metadata" = private constant {{.*}}, section ".sw3flmd"
25+
// CHECK-DAG: @"\01l__swift3_assocty_metadata" = private constant {{.*}}, section ".sw3asty"
26+
// CHECK-DAG: @"\01l__swift3_builtin_metadata" = private constant {{.*}}, section ".sw3bltn"
27+

0 commit comments

Comments
 (0)