Skip to content

Commit f43f89a

Browse files
alichraghialexrp
authored andcommitted
spirv: snake-case the spec
1 parent 2f3cd17 commit f43f89a

File tree

13 files changed

+12495
-10635
lines changed

13 files changed

+12495
-10635
lines changed

src/codegen/spirv.zig

Lines changed: 258 additions & 292 deletions
Large diffs are not rendered by default.

src/codegen/spirv/Assembler.zig

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ const assert = std.debug.assert;
77
const spec = @import("spec.zig");
88
const Opcode = spec.Opcode;
99
const Word = spec.Word;
10-
const IdRef = spec.IdRef;
11-
const IdResult = spec.IdResult;
10+
const Id = spec.Id;
1211
const StorageClass = spec.StorageClass;
1312

1413
const SpvModule = @import("Module.zig");
@@ -127,10 +126,10 @@ const AsmValue = union(enum) {
127126
unresolved_forward_reference,
128127

129128
/// This result-value is a normal result produced by a different instruction.
130-
value: IdRef,
129+
value: Id,
131130

132131
/// This result-value represents a type registered into the module's type system.
133-
ty: IdRef,
132+
ty: Id,
134133

135134
/// This is a pre-supplied constant integer value.
136135
constant: u32,
@@ -141,7 +140,7 @@ const AsmValue = union(enum) {
141140
/// Retrieve the result-id of this AsmValue. Asserts that this AsmValue
142141
/// is of a variant that allows the result to be obtained (not an unresolved
143142
/// forward declaration, not in the process of being declared, etc).
144-
pub fn resultId(self: AsmValue) IdRef {
143+
pub fn resultId(self: AsmValue) Id {
145144
return switch (self) {
146145
.just_declared,
147146
.unresolved_forward_reference,
@@ -314,7 +313,7 @@ fn processInstruction(self: *Assembler) !void {
314313
return;
315314
},
316315
else => switch (self.inst.opcode.class()) {
317-
.TypeDeclaration => try self.processTypeInstruction(),
316+
.type_declaration => try self.processTypeInstruction(),
318317
else => (try self.processGenericInstruction()) orelse return,
319318
},
320319
};
@@ -392,7 +391,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
392391
break :blk result_id;
393392
},
394393
.OpTypeStruct => blk: {
395-
const ids = try self.gpa.alloc(IdRef, operands[1..].len);
394+
const ids = try self.gpa.alloc(Id, operands[1..].len);
396395
defer self.gpa.free(ids);
397396
for (operands[1..], ids) |op, *id| id.* = try self.resolveRefId(op.ref_id);
398397
const result_id = self.spv.allocId();
@@ -429,7 +428,7 @@ fn processTypeInstruction(self: *Assembler) !AsmValue {
429428
const param_operands = operands[2..];
430429
const return_type = try self.resolveRefId(operands[1].ref_id);
431430

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);
433432
defer self.spv.gpa.free(param_types);
434433
for (param_types, param_operands) |*param, operand| {
435434
param.* = try self.resolveRefId(operand.ref_id);
@@ -457,17 +456,17 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
457456
const operands = self.inst.operands.items;
458457
var maybe_spv_decl_index: ?SpvModule.Decl.Index = null;
459458
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.
463462
else => switch (self.inst.opcode) {
464463
.OpEntryPoint => unreachable,
465464
.OpExecutionMode, .OpExecutionModeId => &self.spv.sections.execution_modes,
466465
.OpVariable => section: {
467466
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;
469468
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) {
471470
// Before version 1.4, the interface’s storage classes are limited to the Input and Output
472471
break :section &self.spv.sections.types_globals_constants;
473472
}
@@ -481,7 +480,7 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
481480
},
482481
};
483482

484-
var maybe_result_id: ?IdResult = null;
483+
var maybe_result_id: ?Id = null;
485484
const first_word = section.instructions.items.len;
486485
// At this point we're not quite sure how many operands this instruction is going to have,
487486
// so insert 0 and patch up the actual opcode word later.
@@ -504,12 +503,12 @@ fn processGenericInstruction(self: *Assembler) !?AsmValue {
504503
else
505504
self.spv.allocId();
506505
try section.ensureUnusedCapacity(self.spv.gpa, 1);
507-
section.writeOperand(IdResult, maybe_result_id.?);
506+
section.writeOperand(Id, maybe_result_id.?);
508507
},
509508
.ref_id => |index| {
510509
const result = try self.resolveRef(index);
511510
try section.ensureUnusedCapacity(self.spv.gpa, 1);
512-
section.writeOperand(spec.IdRef, result.resultId());
511+
section.writeOperand(spec.Id, result.resultId());
513512
},
514513
.string => |offset| {
515514
const text = std.mem.sliceTo(self.inst.string_bytes.items[offset..], 0);
@@ -558,7 +557,7 @@ fn resolveRef(self: *Assembler, ref: AsmValue.Ref) !AsmValue {
558557
}
559558
}
560559

561-
fn resolveRefId(self: *Assembler, ref: AsmValue.Ref) !IdRef {
560+
fn resolveRefId(self: *Assembler, ref: AsmValue.Ref) !Id {
562561
const value = try self.resolveRef(ref);
563562
return value.resultId();
564563
}
@@ -600,7 +599,7 @@ fn parseInstruction(self: *Assembler) !void {
600599
const expected_operands = inst.operands;
601600
// This is a loop because the result-id is not always the first operand.
602601
const requires_lhs_result = for (expected_operands) |op| {
603-
if (op.kind == .IdResult) break true;
602+
if (op.kind == .id_result) break true;
604603
} else false;
605604

606605
if (requires_lhs_result and maybe_lhs_result == null) {
@@ -614,7 +613,7 @@ fn parseInstruction(self: *Assembler) !void {
614613
}
615614

616615
for (expected_operands) |operand| {
617-
if (operand.kind == .IdResult) {
616+
if (operand.kind == .id_result) {
618617
try self.inst.operands.append(self.gpa, .{ .result_id = maybe_lhs_result.? });
619618
continue;
620619
}
@@ -646,11 +645,11 @@ fn parseOperand(self: *Assembler, kind: spec.OperandKind) Error!void {
646645
.value_enum => try self.parseValueEnum(kind),
647646
.id => try self.parseRefId(),
648647
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(),
654653
else => return self.todo("parse operand of type {s}", .{@tagName(kind)}),
655654
},
656655
}

0 commit comments

Comments
 (0)