-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathmodules-used.swift
51 lines (40 loc) · 1.79 KB
/
modules-used.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s
// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift
// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -emit-sil | %FileCheck %s --check-prefix CHECK-SIL
// RUN: %target-swift-frontend -enable-experimental-feature SymbolLinkageMarkers -enable-experimental-feature Embedded -parse-as-library -I %t %t/Main.swift -c -o %t/a.o
// RUN: %target-clang %t/a.o -o %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: OS=macosx
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_feature_SymbolLinkageMarkers
// BEGIN MyModule.swift
@_used
@_section("__DATA,__mysection")
let i_am_not_referenced = 42
// BEGIN Main.swift
import MyModule
@_silgen_name(raw: "section$start$__DATA$__mysection")
var mysection_start: Int
@_silgen_name(raw: "section$end$__DATA$__mysection")
var mysection_end: Int
@main
struct Main {
static func main() {
let start = UnsafeRawPointer(&mysection_start)
let end = UnsafeRawPointer(&mysection_end)
let size = end - start
let count = size / (Int.bitWidth / 8)
print("count: \(count)")
let linker_set = UnsafeBufferPointer(start: start.bindMemory(to: Int.self, capacity: count), count: count)
for i in 0 ..< linker_set.count {
print("mysection[\(i)]: \(linker_set[i])")
}
}
}
// CHECK-SIL: // i_am_not_referenced
// CHECK-SIL-NEXT: sil_global [serialized] [let] @$e8MyModule19i_am_not_referencedSivp : $Int = {
// CHECK: count: 1
// CHECK: mysection[0]: 42