File: modules-used.swift

package info (click to toggle)
swiftlang 6.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,856,264 kB
  • sloc: cpp: 9,995,718; ansic: 2,234,019; asm: 1,092,167; python: 313,940; objc: 82,726; f90: 80,126; lisp: 38,373; pascal: 25,580; sh: 20,378; ml: 5,058; perl: 4,751; makefile: 4,725; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (51 lines) | stat: -rw-r--r-- 1,833 bytes parent folder | download
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