1
- // RUN: %target-swift-frontend -emit-ir -O %s | FileCheck %s
1
+ // RUN: %target-swift-frontend -target x86_64-apple-macosx10.11 - emit-ir -O %s | FileCheck %s
2
2
3
3
// Test some imported CG APIs
4
4
import CoreGraphics
5
5
6
6
// REQUIRES: OS=macosx
7
7
8
+ // CHECK-LABEL: define void {{.*}}rotationAround{{.*}} {
8
9
// Get a transform that will rotate around a given offset
9
10
public func rotationAround( offset: CGPoint , angle: CGFloat ,
10
11
transform: CGAffineTransform = . identity) -> CGAffineTransform {
11
12
// FIXME: consistent API namings
12
- return transform. translateBy ( x: offset. x, y: offset. y)
13
- . rotate ( angle)
14
- . translateBy ( x: - offset. x, y: - offset. y)
13
+ return transform. translatedBy ( x: offset. x, y: offset. y)
14
+ . rotated ( by : angle)
15
+ . translatedBy ( x: - offset. x, y: - offset. y)
15
16
16
17
// CHECK: call void @CGAffineTransformTranslate(%{{.*}}.CGAffineTransform* {{.*}}, %{{.*}}.CGAffineTransform* {{.*}},{{.*}}, {{.*}})
17
18
// CHECK: call void @CGAffineTransformRotate(%{{.*}}.CGAffineTransform* {{.*}}, %{{.*}}.CGAffineTransform* {{.*}},{{.*}})
18
19
// CHECK: call void @CGAffineTransformTranslate(%{{.*}}.CGAffineTransform* {{.*}}, %{{.*}}.CGAffineTransform* {{.*}},{{.*}}, {{.*}})
20
+ //
21
+ // CHECK: ret void
19
22
}
20
23
21
- // Trace a path in red
24
+ // CHECK-LABEL: define void {{.*}}trace{{.*}} {
22
25
public func trace( in context: CGContext , path: CGPath ) {
23
26
let red = CGColor ( red: 1 , green: 0 , blue: 0 , alpha: 1 )
24
27
context. saveGState ( )
@@ -32,15 +35,77 @@ public func trace(in context: CGContext, path: CGPath) {
32
35
// CHECK: call void @CGContextSetStrokeColorWithColor(%{{.*}}.CGContext* %{{.*}}, %{{.*}}.CGColor* %{{.*}})
33
36
// CHECK: call void @CGContextStrokePath(%{{.*}}.CGContext* %{{.*}})
34
37
// CHECK: call void @CGContextRestoreGState(%{{.*}}.CGContext* %{{.*}})
38
+ //
39
+ // CHECK: ret void
35
40
}
36
41
42
+ // CHECK-LABEL: define void {{.*}}pdfOperations{{.*}} {
37
43
public func pdfOperations( _ context: CGContext ) {
38
44
context. beginPDFPage ( nil )
39
45
context. endPDFPage ( )
40
46
context. closePDF ( )
41
47
// CHECK: call void @CGPDFContextBeginPage(%{{.*}}.CGContext* %{{.*}}, %{{.*}}.__CFDictionary* {{.*}})
42
48
// CHECK: call void @CGPDFContextEndPage(%{{.*}}.CGContext* %{{.*}})
43
49
// CHECK: call void @CGPDFContextClose(%{{.*}}.CGContext* %{{.*}})
50
+ //
51
+ // CHECK: ret void
52
+ }
53
+
54
+ // Test some more recently renamed APIs
55
+
56
+ // CHECK-LABEL: define void {{.*}}testColorRenames{{.*}} {
57
+ public func testColorRenames( color: CGColor ,
58
+ intent: CGColorRenderingIntent ) {
59
+ let colorSpace = CGColorSpace ( name: CGColorSpace . sRGB) !
60
+ // CHECK: %{{.*}} = load {{.*}}%struct.__CFString** @kCGColorSpaceSRGB {{.*}}, align 8
61
+ // CHECK: %{{.*}} = {{.*}} call %struct.CGColorSpace* @CGColorSpaceCreateWithName(%struct.__CFString* %{{.*}})
62
+
63
+ let _ = color. converted ( to: colorSpace, intent: intent, options: nil )
64
+ // CHECK: %{{.*}} = {{.*}} call %struct.CGColor* @CGColorCreateCopyByMatchingToColorSpace(%struct.CGColorSpace* %{{.*}}, i32 %{{.*}}, %struct.CGColor* %{{.*}}, %struct.__CFDictionary* null)
65
+ //
66
+ // CHECK: ret void
67
+ }
68
+
69
+ // CHECK-LABEL: define void {{.*}}testRenames{{.*}} {
70
+ public func testRenames( transform: CGAffineTransform , context: CGContext ,
71
+ point: CGPoint , size: CGSize , rect: CGRect ,
72
+ image: CGImage ,
73
+ edge: CGRectEdge ) {
74
+ let transform = transform. inverted ( ) . concatenating ( transform)
75
+ // CHECK: call void @CGAffineTransformInvert(%struct.CGAffineTransform* {{.*}}, %struct.CGAffineTransform* {{.*}})
76
+ // CHECK: call void @CGAffineTransformConcat(%struct.CGAffineTransform* {{.*}}, %struct.CGAffineTransform* {{.*}}, %struct.CGAffineTransform* {{.*}})
77
+
78
+ let _ = point. applying ( transform)
79
+ var rect = rect. applying ( transform)
80
+ let _ = size. applying ( transform)
81
+ // CHECK: %{{.*}} = call { double, double } @CGPointApplyAffineTransform(double %{{.*}}, double %{{.*}}, %struct.CGAffineTransform* {{.*}})
82
+ // CHECK: call void @CGRectApplyAffineTransform(%struct.CGRect* {{.*}}, %struct.CGRect* {{.*}}, %struct.CGAffineTransform* {{.*}})
83
+ // CHECK: %{{.*}} = call { double, double } @CGSizeApplyAffineTransform(double %{{.*}}, double %{{.*}}, %struct.CGAffineTransform* {{.*}})
84
+
85
+ context. concatenate ( transform)
86
+ context. rotate ( by: CGFloat . pi)
87
+ context. scaleBy ( x: 1.0 , y: 1.0 )
88
+ context. translateBy ( x: 1.0 , y: 1.0 )
89
+ // CHECK: call void @CGContextConcatCTM(%struct.CGContext* [[CONTEXT:%[0-9]+]], %struct.CGAffineTransform* {{.*}})
90
+ // CHECK: call void @CGContextRotateCTM(%struct.CGContext* [[CONTEXT]], double {{.*}})
91
+ // CHECK: call void @CGContextScaleCTM(%struct.CGContext* [[CONTEXT]], double {{1\.0+.*}}, double {{1\.0+.*}})
92
+ // CHECK: call void @CGContextTranslateCTM(%struct.CGContext* [[CONTEXT]], double {{1\.0+.*}}, double {{1\.0+.*}})
93
+
94
+ context. clip ( to: rect)
95
+ context. clip ( to: & rect, count: 2 )
96
+ context. clip ( to: rect, mask: image)
97
+ // CHECK: call void @CGContextClipToRect(%struct.CGContext* [[CONTEXT]], %struct.CGRect* byval nonnull align 8 %{{.*}})
98
+ // CHECK: call void @CGContextClipToRects(%struct.CGContext* [[CONTEXT]], %struct.CGRect* nonnull %rect, i64 2)
99
+ // CHECK: call void @CGContextClipToMask(%struct.CGContext* [[CONTEXT]], %struct.CGRect* byval nonnull align 8 %{{.*}}, %struct.CGImage* %{{.*}})
44
100
101
+ var slice = CGRect . zero
102
+ var remainder = CGRect . zero
103
+ rect. divided ( slice: & slice, remainder: & remainder, atDistance: CGFloat ( 2.0 ) ,
104
+ from: edge)
105
+ assert ( ( slice, remainder) == rect. divided ( atDistance: CGFloat ( 2.0 ) ,
106
+ from: edge) )
107
+ // CHECK: call void @CGRectDivide(%struct.CGRect* byval nonnull align 8 %{{.*}}, %struct.CGRect* nonnull %slice, %struct.CGRect* nonnull %remainder, double {{2\.0+.*}}, i32 %{{.*}})
108
+ //
109
+ // CHECK: ret void
45
110
}
46
111
0 commit comments