@@ -208,25 +208,37 @@ pub fn unlockStdErr() void {
208
208
/// for use in "printf debugging." Use `std.log` functions for proper logging.
209
209
pub fn print (comptime fmt : []const u8 , args : anytype ) void {
210
210
if (builtin .zig_backend == .stage2_spirv ) {
211
- const ret = asm volatile (
212
- \\ %set = OpExtInstImport "OpenCL.std"
211
+ const size = 20 ;
212
+ var fmt_fmt : [size ]u8 = [1 ]u8 {undefined } ** size ;
213
+
214
+ // TODO: All formatting is done by std.
215
+ // std.fmt.bufPrint(&fmt_fmt, fmt, args) catch unreachable;
216
+ // Temporarely mock the fmt_fmt buffer to test printing 's\n'.
217
+ fmt_fmt [0 ] = 115 ;
218
+ fmt_fmt [1 ] = 115 ;
219
+ fmt_fmt [2 ] = 115 ;
220
+ fmt_fmt [3 ] = 115 ;
221
+ fmt_fmt [4 ] = 10 ;
222
+ fmt_fmt [5 ] = 0 ;
223
+
224
+ // Imports std and calls OpenCL.std.printf("%s\0", fmt_fmt)
225
+ _ = asm volatile (
226
+ \\ %std = OpExtInstImport "OpenCL.std"
213
227
\\ %u8 = OpTypeInt 8 0
214
228
\\ %u32 = OpTypeInt 32 0
215
229
\\ %u64 = OpTypeInt 64 0
216
- \\ %u64_4 = OpConstant %u64 4
217
- \\%_arr_u8_4 = OpTypeArray %u8 %u64_4
218
- \\%_ptr_UniformConstant__arr_u8_4 = OpTypePointer UniformConstant %_arr_u8_4
219
- \\ %char_H = OpConstant %u8 72
220
- \\ %char_i = OpConstant %u8 105
221
- \\ %char__n = OpConstant %u8 10
222
- \\ %char_0 = OpConstant %u8 0
223
- \\%const_str = OpConstantComposite %_arr_u8_4 %char_H %char_i %char__n %char_0
224
- \\ %fmt = OpVariable %_ptr_UniformConstant__arr_u8_4 UniformConstant %const_str
225
- \\
226
- \\ %ret = OpExtInst %u32 %set 184 %fmt
230
+ \\ %u64_3 = OpConstant %u64 3
231
+ \\%_arr_u8_3 = OpTypeArray %u8 %u64_3
232
+ \\%_ptr_UniformConstant__arr_u8_3 = OpTypePointer UniformConstant %_arr_u8_3
233
+ \\ %c1 = OpConstant %u8 37
234
+ \\ %c2 = OpConstant %u8 115
235
+ \\ %c3 = OpConstant %u8 0
236
+ \\%const_str = OpConstantComposite %_arr_u8_3 %c1 %c2 %c3
237
+ \\ %fmt = OpVariable %_ptr_UniformConstant__arr_u8_3 UniformConstant %const_str
238
+ \\ %ret = OpExtInst %u32 %std 184 %fmt %fmt_fmt
227
239
: [ret ] "" (- > u32 ),
240
+ : [fmt_fmt ] "" (& fmt_fmt ),
228
241
);
229
- _ = ret ;
230
242
} else {
231
243
lockStdErr ();
232
244
defer unlockStdErr ();
0 commit comments