@@ -47,14 +47,14 @@ Print a formatted string in device context on the host standard output.
47
47
macro mtlprintf (fmt:: String , args... )
48
48
fmt_val = Val (Symbol (fmt))
49
49
50
- quote
50
+ return quote
51
51
_mtlprintf ($ fmt_val, $ (map (arg -> :(promote_c_argument ($ arg)), esc .(args))... ))
52
52
end
53
53
end
54
54
55
55
@generated function _mtlprintf (:: Val{fmt} , argspec... ) where {fmt}
56
- @dispose ctx= Context () begin
57
- arg_exprs = [:( argspec[$ i] ) for i in 1 : length (argspec)]
56
+ return @dispose ctx = Context () begin
57
+ arg_exprs = [:(argspec[$ i]) for i in 1 : length (argspec)]
58
58
arg_types = [argspec... ]
59
59
60
60
T_void = LLVM. VoidType ()
68
68
wrapper_f, wrapper_ft = create_function (T_void, param_types)
69
69
mod = LLVM. parent (wrapper_f)
70
70
71
- llvm_ft = LLVM. FunctionType (T_void, LLVMType[]; vararg= true )
71
+ llvm_ft = LLVM. FunctionType (T_void, LLVMType[]; vararg = true )
72
72
llvm_f = LLVM. Function (mod, " metal_os_log" , llvm_ft)
73
73
push! (function_attributes (llvm_f), EnumAttribute (" alwaysinline" , 0 ))
74
74
75
75
# generate IR
76
- @dispose builder= IRBuilder () begin
76
+ @dispose builder = IRBuilder () begin
77
77
entry = BasicBlock (llvm_f, " entry" )
78
78
position! (builder, entry)
79
79
80
- str = globalstring_ptr! (builder, String (fmt), addrspace= 2 )
81
- subsystem_str = globalstring_ptr! (builder, MTLLOG_SUBSYSTEM, addrspace= 2 )
82
- category_str = globalstring_ptr! (builder, MTLLOG_CATEGORY, addrspace= 2 )
80
+ str = globalstring_ptr! (builder, String (fmt), addrspace = 2 )
81
+ subsystem_str = globalstring_ptr! (builder, MTLLOG_SUBSYSTEM, addrspace = 2 )
82
+ category_str = globalstring_ptr! (builder, MTLLOG_CATEGORY, addrspace = 2 )
83
83
log_type = LLVM. ConstantInt (T_int32, __METAL_OS_LOG_TYPE_DEBUG__)
84
84
85
85
# compute argsize
115
115
ret! (builder)
116
116
end
117
117
118
- @dispose builder= IRBuilder () begin
118
+ @dispose builder = IRBuilder () begin
119
119
entry = BasicBlock (wrapper_f, " entry" )
120
120
position! (builder, entry)
121
121
@@ -137,29 +137,29 @@ export @mtlprint, @mtlprintln
137
137
# simple conversions, defining an expression and the resulting argument type. nothing fancy,
138
138
# `@mtlprint` pretty directly maps to `@mtlprintf`; we should just support `write(::IO)`.
139
139
const mtlprint_conversions = [
140
- Float32 => (x-> :(Float64 ($ x)), Float64),
141
- Ptr{<: Any } => (x-> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
142
- LLVMPtr{<: Any } => (x-> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
143
- Bool => (x-> :(Int32 ($ x)), Int32),
140
+ Float32 => (x -> :(Float64 ($ x)), Float64),
141
+ Ptr{<: Any } => (x -> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
142
+ LLVMPtr{<: Any } => (x -> :(reinterpret (Int, $ x)), Ptr{Cvoid}),
143
+ Bool => (x -> :(Int32 ($ x)), Int32),
144
144
]
145
145
146
146
# format specifiers
147
147
const mtlprint_specifiers = Dict (
148
148
# integers
149
- Int16 => " %hd" ,
150
- Int32 => " %d" ,
151
- Int64 => " %ld" ,
152
- UInt16 => " %hu" ,
153
- UInt32 => " %u" ,
154
- UInt64 => " %lu" ,
149
+ Int16 => " %hd" ,
150
+ Int32 => " %d" ,
151
+ Int64 => " %ld" ,
152
+ UInt16 => " %hu" ,
153
+ UInt32 => " %u" ,
154
+ UInt64 => " %lu" ,
155
155
156
156
# floating-point
157
- Float32 => " %f" ,
157
+ Float32 => " %f" ,
158
158
159
159
# other
160
- Cchar => " %c" ,
161
- Ptr{Cvoid} => " %p" ,
162
- Cstring => " %s" ,
160
+ Cchar => " %c" ,
161
+ Ptr{Cvoid} => " %p" ,
162
+ Cstring => " %s" ,
163
163
)
164
164
165
165
@inline @generated function _mtlprint (parts... )
@@ -217,7 +217,7 @@ const mtlprint_specifiers = Dict(
217
217
end
218
218
end
219
219
220
- quote
220
+ return quote
221
221
@mtlprintf ($ fmt, $ (args... ))
222
222
end
223
223
end
@@ -240,7 +240,7 @@ Limited string interpolation is also possible:
240
240
```
241
241
"""
242
242
macro mtlprint (parts... )
243
- args = Union{Val,Expr,Symbol}[]
243
+ args = Union{Val, Expr, Symbol}[]
244
244
245
245
parts = [parts... ]
246
246
while true
@@ -266,16 +266,18 @@ macro mtlprint(parts...)
266
266
end
267
267
end
268
268
269
- quote
269
+ return quote
270
270
_mtlprint ($ (map (esc, args)... ))
271
271
end
272
272
end
273
273
274
274
@doc (@doc @mtlprint ) ->
275
275
macro mtlprintln (parts... )
276
- esc (quote
277
- Metal. @mtlprint ($ (parts... ), " \n " )
278
- end )
276
+ return esc (
277
+ quote
278
+ Metal. @mtlprint ($ (parts... ), " \n " )
279
+ end
280
+ )
279
281
end
280
282
281
283
export @mtlshow
@@ -292,9 +294,17 @@ GPU analog of `Base.@show`. It comes with the same type restrictions as [`@mtlpr
292
294
macro mtlshow (exs... )
293
295
blk = Expr (:block )
294
296
for ex in exs
295
- push! (blk. args, :(Metal. @mtlprintln ($ (sprint (Base. show_unquoted,ex)* " = " ),
296
- begin local value = $ (esc (ex)) end )))
297
+ push! (
298
+ blk. args, :(
299
+ Metal. @mtlprintln (
300
+ $ (sprint (Base. show_unquoted, ex) * " = " ),
301
+ begin
302
+ local value = $ (esc (ex))
303
+ end
304
+ )
305
+ )
306
+ )
297
307
end
298
308
isempty (exs) || push! (blk. args, :value )
299
- blk
309
+ return blk
300
310
end
0 commit comments