@@ -7,8 +7,7 @@ const assert = std.debug.assert;
7
7
const spec = @import ("spec.zig" );
8
8
const Opcode = spec .Opcode ;
9
9
const Word = spec .Word ;
10
- const IdRef = spec .IdRef ;
11
- const IdResult = spec .IdResult ;
10
+ const Id = spec .Id ;
12
11
const StorageClass = spec .StorageClass ;
13
12
14
13
const SpvModule = @import ("Module.zig" );
@@ -127,10 +126,10 @@ const AsmValue = union(enum) {
127
126
unresolved_forward_reference ,
128
127
129
128
/// This result-value is a normal result produced by a different instruction.
130
- value : IdRef ,
129
+ value : Id ,
131
130
132
131
/// This result-value represents a type registered into the module's type system.
133
- ty : IdRef ,
132
+ ty : Id ,
134
133
135
134
/// This is a pre-supplied constant integer value.
136
135
constant : u32 ,
@@ -141,7 +140,7 @@ const AsmValue = union(enum) {
141
140
/// Retrieve the result-id of this AsmValue. Asserts that this AsmValue
142
141
/// is of a variant that allows the result to be obtained (not an unresolved
143
142
/// forward declaration, not in the process of being declared, etc).
144
- pub fn resultId (self : AsmValue ) IdRef {
143
+ pub fn resultId (self : AsmValue ) Id {
145
144
return switch (self ) {
146
145
.just_declared ,
147
146
.unresolved_forward_reference ,
@@ -275,28 +274,28 @@ fn todo(self: *Assembler, comptime fmt: []const u8, args: anytype) Error {
275
274
/// error message has already been emitted into `self.errors`.
276
275
fn processInstruction (self : * Assembler ) ! void {
277
276
const result : AsmValue = switch (self .inst .opcode ) {
278
- .OpEntryPoint = > {
277
+ .entry_point = > {
279
278
return self .fail (0 , "cannot export entry points via OpEntryPoint, export the kernel using callconv(.kernel)" , .{});
280
279
},
281
- .OpCapability = > {
280
+ .capability = > {
282
281
try self .spv .addCapability (@enumFromInt (self .inst .operands .items [0 ].value ));
283
282
return ;
284
283
},
285
- .OpExtension = > {
284
+ .extension = > {
286
285
const ext_name_offset = self .inst .operands .items [0 ].string ;
287
286
const ext_name = std .mem .sliceTo (self .inst .string_bytes .items [ext_name_offset .. ], 0 );
288
287
try self .spv .addExtension (ext_name );
289
288
return ;
290
289
},
291
- .OpExtInstImport = > blk : {
290
+ .ext_inst_import = > blk : {
292
291
const set_name_offset = self .inst .operands .items [1 ].string ;
293
292
const set_name = std .mem .sliceTo (self .inst .string_bytes .items [set_name_offset .. ], 0 );
294
293
const set_tag = std .meta .stringToEnum (spec .InstructionSet , set_name ) orelse {
295
294
return self .fail (set_name_offset , "unknown instruction set: {s}" , .{set_name });
296
295
};
297
296
break :blk .{ .value = try self .spv .importInstructionSet (set_tag ) };
298
297
},
299
- .OpExecutionMode , .OpExecutionModeId = > {
298
+ .execution_mode , .execution_mode_id = > {
300
299
assert (try self .processGenericInstruction () == null );
301
300
const entry_point_id = try self .resolveRefId (self .inst .operands .items [0 ].ref_id );
302
301
const exec_mode : spec.ExecutionMode = @enumFromInt (self .inst .operands .items [1 ].value );
@@ -314,7 +313,7 @@ fn processInstruction(self: *Assembler) !void {
314
313
return ;
315
314
},
316
315
else = > switch (self .inst .opcode .class ()) {
317
- .TypeDeclaration = > try self .processTypeInstruction (),
316
+ .type_declaration = > try self .processTypeInstruction (),
318
317
else = > (try self .processGenericInstruction ()) orelse return ,
319
318
},
320
319
};
@@ -336,9 +335,9 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
336
335
const operands = self .inst .operands .items ;
337
336
const section = & self .spv .sections .types_globals_constants ;
338
337
const id = switch (self .inst .opcode ) {
339
- .OpTypeVoid = > try self .spv .voidType (),
340
- .OpTypeBool = > try self .spv .boolType (),
341
- .OpTypeInt = > blk : {
338
+ .type_void = > try self .spv .voidType (),
339
+ .type_bool = > try self .spv .boolType (),
340
+ .type_int = > blk : {
342
341
const signedness : std.builtin.Signedness = switch (operands [2 ].literal32 ) {
343
342
0 = > .unsigned ,
344
343
1 = > .signed ,
@@ -352,7 +351,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
352
351
};
353
352
break :blk try self .spv .intType (signedness , width );
354
353
},
355
- .OpTypeFloat = > blk : {
354
+ .type_float = > blk : {
356
355
const bits = operands [1 ].literal32 ;
357
356
switch (bits ) {
358
357
16 , 32 , 64 = > {},
@@ -362,47 +361,47 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
362
361
}
363
362
break :blk try self .spv .floatType (@intCast (bits ));
364
363
},
365
- .OpTypeVector = > blk : {
364
+ .type_vector = > blk : {
366
365
const child_type = try self .resolveRefId (operands [1 ].ref_id );
367
366
break :blk try self .spv .vectorType (operands [2 ].literal32 , child_type );
368
367
},
369
- .OpTypeArray = > {
368
+ .type_array = > {
370
369
// TODO: The length of an OpTypeArray is determined by a constant (which may be a spec constant),
371
370
// and so some consideration must be taken when entering this in the type system.
372
371
return self .todo ("process OpTypeArray" , .{});
373
372
},
374
- .OpTypeRuntimeArray = > blk : {
373
+ .type_runtime_array = > blk : {
375
374
const element_type = try self .resolveRefId (operands [1 ].ref_id );
376
375
const result_id = self .spv .allocId ();
377
- try section .emit (self .spv .gpa , .OpTypeRuntimeArray , .{
376
+ try section .emit (self .spv .gpa , .type_runtime_array , .{
378
377
.id_result = result_id ,
379
378
.element_type = element_type ,
380
379
});
381
380
break :blk result_id ;
382
381
},
383
- .OpTypePointer = > blk : {
382
+ .type_pointer = > blk : {
384
383
const storage_class : StorageClass = @enumFromInt (operands [1 ].value );
385
384
const child_type = try self .resolveRefId (operands [2 ].ref_id );
386
385
const result_id = self .spv .allocId ();
387
- try section .emit (self .spv .gpa , .OpTypePointer , .{
386
+ try section .emit (self .spv .gpa , .type_pointer , .{
388
387
.id_result = result_id ,
389
388
.storage_class = storage_class ,
390
389
.type = child_type ,
391
390
});
392
391
break :blk result_id ;
393
392
},
394
- .OpTypeStruct = > blk : {
395
- const ids = try self .gpa .alloc (IdRef , operands [1.. ].len );
393
+ .type_struct = > blk : {
394
+ const ids = try self .gpa .alloc (Id , operands [1.. ].len );
396
395
defer self .gpa .free (ids );
397
396
for (operands [1.. ], ids ) | op , * id | id .* = try self .resolveRefId (op .ref_id );
398
397
const result_id = self .spv .allocId ();
399
398
try self .spv .structType (result_id , ids , null );
400
399
break :blk result_id ;
401
400
},
402
- .OpTypeImage = > blk : {
401
+ .type_image = > blk : {
403
402
const sampled_type = try self .resolveRefId (operands [1 ].ref_id );
404
403
const result_id = self .spv .allocId ();
405
- try section .emit (self .gpa , .OpTypeImage , .{
404
+ try section .emit (self .gpa , .type_image , .{
406
405
.id_result = result_id ,
407
406
.sampled_type = sampled_type ,
408
407
.dim = @enumFromInt (operands [2 ].value ),
@@ -414,28 +413,28 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
414
413
});
415
414
break :blk result_id ;
416
415
},
417
- .OpTypeSampler = > blk : {
416
+ .type_sampler = > blk : {
418
417
const result_id = self .spv .allocId ();
419
- try section .emit (self .gpa , .OpTypeSampler , .{ .id_result = result_id });
418
+ try section .emit (self .gpa , .type_sampler , .{ .id_result = result_id });
420
419
break :blk result_id ;
421
420
},
422
- .OpTypeSampledImage = > blk : {
421
+ .type_sampled_image = > blk : {
423
422
const image_type = try self .resolveRefId (operands [1 ].ref_id );
424
423
const result_id = self .spv .allocId ();
425
- try section .emit (self .gpa , .OpTypeSampledImage , .{ .id_result = result_id , .image_type = image_type });
424
+ try section .emit (self .gpa , .type_sampled_image , .{ .id_result = result_id , .image_type = image_type });
426
425
break :blk result_id ;
427
426
},
428
- .OpTypeFunction = > blk : {
427
+ .type_function = > blk : {
429
428
const param_operands = operands [2.. ];
430
429
const return_type = try self .resolveRefId (operands [1 ].ref_id );
431
430
432
- const param_types = try self .spv .gpa .alloc (IdRef , param_operands .len );
431
+ const param_types = try self .spv .gpa .alloc (Id , param_operands .len );
433
432
defer self .spv .gpa .free (param_types );
434
433
for (param_types , param_operands ) | * param , operand | {
435
434
param .* = try self .resolveRefId (operand .ref_id );
436
435
}
437
436
const result_id = self .spv .allocId ();
438
- try section .emit (self .spv .gpa , .OpTypeFunction , .{
437
+ try section .emit (self .spv .gpa , .type_function , .{
439
438
.id_result = result_id ,
440
439
.return_type = return_type ,
441
440
.id_ref_2 = param_types ,
@@ -457,17 +456,17 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
457
456
const operands = self .inst .operands .items ;
458
457
var maybe_spv_decl_index : ? SpvModule.Decl.Index = null ;
459
458
const section = switch (self .inst .opcode .class ()) {
460
- .ConstantCreation = > & self .spv .sections .types_globals_constants ,
461
- .Annotation = > & self .spv .sections .annotations ,
462
- .TypeDeclaration = > unreachable , // Handled elsewhere.
459
+ .constant_creation = > & self .spv .sections .types_globals_constants ,
460
+ .annotation = > & self .spv .sections .annotations ,
461
+ .type_declaration = > unreachable , // Handled elsewhere.
463
462
else = > switch (self .inst .opcode ) {
464
- .OpEntryPoint = > unreachable ,
465
- .OpExecutionMode , .OpExecutionModeId = > & self .spv .sections .execution_modes ,
466
- .OpVariable = > section : {
463
+ .entry_point = > unreachable ,
464
+ .execution_mode , .execution_mode_id = > & self .spv .sections .execution_modes ,
465
+ .variable = > section : {
467
466
const storage_class : spec.StorageClass = @enumFromInt (operands [2 ].value );
468
- if (storage_class == .Function ) break :section & self .func .prologue ;
467
+ if (storage_class == .function ) break :section & self .func .prologue ;
469
468
maybe_spv_decl_index = try self .spv .allocDecl (.global );
470
- if (self .spv .version .minor < 4 and storage_class != .Input and storage_class != .Output ) {
469
+ if (self .spv .version .minor < 4 and storage_class != .input and storage_class != .output ) {
471
470
// Before version 1.4, the interface’s storage classes are limited to the Input and Output
472
471
break :section & self .spv .sections .types_globals_constants ;
473
472
}
@@ -481,7 +480,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
481
480
},
482
481
};
483
482
484
- var maybe_result_id : ? IdResult = null ;
483
+ var maybe_result_id : ? Id = null ;
485
484
const first_word = section .instructions .items .len ;
486
485
// At this point we're not quite sure how many operands this instruction is going to have,
487
486
// so insert 0 and patch up the actual opcode word later.
@@ -504,12 +503,12 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
504
503
else
505
504
self .spv .allocId ();
506
505
try section .ensureUnusedCapacity (self .spv .gpa , 1 );
507
- section .writeOperand (IdResult , maybe_result_id .? );
506
+ section .writeOperand (Id , maybe_result_id .? );
508
507
},
509
508
.ref_id = > | index | {
510
509
const result = try self .resolveRef (index );
511
510
try section .ensureUnusedCapacity (self .spv .gpa , 1 );
512
- section .writeOperand (spec .IdRef , result .resultId ());
511
+ section .writeOperand (spec .Id , result .resultId ());
513
512
},
514
513
.string = > | offset | {
515
514
const text = std .mem .sliceTo (self .inst .string_bytes .items [offset .. ], 0 );
@@ -558,7 +557,7 @@ fn resolveRef(self: *Assembler, ref: AsmValue.Ref) !AsmValue {
558
557
}
559
558
}
560
559
561
- fn resolveRefId (self : * Assembler , ref : AsmValue.Ref ) ! IdRef {
560
+ fn resolveRefId (self : * Assembler , ref : AsmValue.Ref ) ! Id {
562
561
const value = try self .resolveRef (ref );
563
562
return value .resultId ();
564
563
}
@@ -600,7 +599,7 @@ fn parseInstruction(self: *Assembler) !void {
600
599
const expected_operands = inst .operands ;
601
600
// This is a loop because the result-id is not always the first operand.
602
601
const requires_lhs_result = for (expected_operands ) | op | {
603
- if (op .kind == .IdResult ) break true ;
602
+ if (op .kind == .id_result ) break true ;
604
603
} else false ;
605
604
606
605
if (requires_lhs_result and maybe_lhs_result == null ) {
@@ -614,7 +613,7 @@ fn parseInstruction(self: *Assembler) !void {
614
613
}
615
614
616
615
for (expected_operands ) | operand | {
617
- if (operand .kind == .IdResult ) {
616
+ if (operand .kind == .id_result ) {
618
617
try self .inst .operands .append (self .gpa , .{ .result_id = maybe_lhs_result .? });
619
618
continue ;
620
619
}
@@ -646,11 +645,11 @@ fn parseOperand(self: *Assembler, kind: spec.OperandKind) Error!void {
646
645
.value_enum = > try self .parseValueEnum (kind ),
647
646
.id = > try self .parseRefId (),
648
647
else = > switch (kind ) {
649
- .LiteralInteger = > try self .parseLiteralInteger (),
650
- .LiteralString = > try self .parseString (),
651
- .LiteralContextDependentNumber = > try self .parseContextDependentNumber (),
652
- .LiteralExtInstInteger = > try self .parseLiteralExtInstInteger (),
653
- .PairIdRefIdRef = > try self .parsePhiSource (),
648
+ .literal_integer = > try self .parseLiteralInteger (),
649
+ .literal_string = > try self .parseString (),
650
+ .literal_context_dependent_number = > try self .parseContextDependentNumber (),
651
+ .literal_ext_inst_integer = > try self .parseLiteralExtInstInteger (),
652
+ .pair_id_ref_id_ref = > try self .parsePhiSource (),
654
653
else = > return self .todo ("parse operand of type {s}" , .{@tagName (kind )}),
655
654
},
656
655
}
@@ -850,7 +849,7 @@ fn parseContextDependentNumber(self: *Assembler) !void {
850
849
// Currently, this operand appears in OpConstant and OpSpecConstant, where the too-be-parsed type
851
850
// is determined by the result type. That means that in this instructions we have to resolve the
852
851
// operand type early and look at the result to see how we need to proceed.
853
- assert (self .inst .opcode == .OpConstant or self .inst .opcode == .OpSpecConstant );
852
+ assert (self .inst .opcode == .constant or self .inst .opcode == .spec_constant );
854
853
855
854
const tok = self .currentToken ();
856
855
const result = try self .resolveRef (self .inst .operands .items [0 ].ref_id );
0 commit comments