| ... | ... | @@ -238,6 +238,7 @@ pub const DeclGen = struct { |
| 238 | 238 | else => unreachable, |
| 239 | 239 | }; |
| 240 | 240 | const spv_decl_index = try self.resolveDecl(fn_decl_index); |
| 241 | try self.func.decl_deps.put(self.spv.gpa, spv_decl_index, {}); |
| 241 | 242 | return self.spv.declPtr(spv_decl_index).result_id; |
| 242 | 243 | } |
| 243 | 244 | |
| ... | ... | @@ -459,7 +460,7 @@ pub const DeclGen = struct { |
| 459 | 460 | /// If full, its flushed. |
| 460 | 461 | partial_word: std.BoundedArray(u8, @sizeOf(Word)) = .{}, |
| 461 | 462 | /// The declaration dependencies of the constant we are lowering. |
| 462 | | decl_deps: std.ArrayList(SpvModule.Decl.Index), |
| 463 | decl_deps: std.AutoArrayHashMap(SpvModule.Decl.Index, void), |
| 463 | 464 | |
| 464 | 465 | /// Utility function to get the section that instructions should be lowered to. |
| 465 | 466 | fn section(self: *@This()) *SpvSection { |
| ... | ... | @@ -582,14 +583,15 @@ pub const DeclGen = struct { |
| 582 | 583 | // just generate an empty pointer. Function pointers are represented by usize for now, |
| 583 | 584 | // though. |
| 584 | 585 | try self.addInt(Type.usize, Value.initTag(.zero)); |
| 586 | // TODO: Add dependency |
| 585 | 587 | return; |
| 586 | 588 | }, |
| 587 | 589 | .extern_fn => unreachable, // TODO |
| 588 | 590 | else => { |
| 589 | 591 | const result_id = dg.spv.allocId(); |
| 590 | | log.debug("addDeclRef {s} = {}", .{ decl.name, result_id.id }); |
| 592 | log.debug("addDeclRef: id = {}, index = {}, name = {s}", .{ result_id.id, @enumToInt(spv_decl_index), decl.name }); |
| 591 | 593 | |
| 592 | | try self.decl_deps.append(spv_decl_index); |
| 594 | try self.decl_deps.put(spv_decl_index, {}); |
| 593 | 595 | |
| 594 | 596 | const decl_id = dg.spv.declPtr(spv_decl_index).result_id; |
| 595 | 597 | // TODO: Do we need a storage class cast here? |
| ... | ... | @@ -861,7 +863,8 @@ pub const DeclGen = struct { |
| 861 | 863 | |
| 862 | 864 | assert(storage_class != .Generic and storage_class != .Function); |
| 863 | 865 | |
| 864 | | log.debug("lowerIndirectConstant: ty = {}, val = {}", .{ ty.fmt(self.module), val.fmtDebug() }); |
| 866 | const var_id = self.spv.allocId(); |
| 867 | log.debug("lowerIndirectConstant: id = {}, index = {}, ty = {}, val = {}", .{ var_id.id, @enumToInt(spv_decl_index), ty.fmt(self.module), val.fmtDebug() }); |
| 865 | 868 | |
| 866 | 869 | const section = &self.spv.globals.section; |
| 867 | 870 | |
| ... | ... | @@ -897,7 +900,7 @@ pub const DeclGen = struct { |
| 897 | 900 | .u32_ty_id = self.typeId(u32_ty_ref), |
| 898 | 901 | .members = std.ArrayList(SpvType.Payload.Struct.Member).init(self.gpa), |
| 899 | 902 | .initializers = std.ArrayList(IdRef).init(self.gpa), |
| 900 | | .decl_deps = std.ArrayList(SpvModule.Decl.Index).init(self.gpa), |
| 903 | .decl_deps = std.AutoArrayHashMap(SpvModule.Decl.Index, void).init(self.gpa), |
| 901 | 904 | }; |
| 902 | 905 | |
| 903 | 906 | defer icl.members.deinit(); |
| ... | ... | @@ -917,7 +920,6 @@ pub const DeclGen = struct { |
| 917 | 920 | .constituents = icl.initializers.items, |
| 918 | 921 | }); |
| 919 | 922 | |
| 920 | | const var_id = self.spv.allocId(); |
| 921 | 923 | self.spv.globalPtr(spv_decl_index).?.result_id = var_id; |
| 922 | 924 | try section.emit(self.spv.gpa, .OpVariable, .{ |
| 923 | 925 | .id_result_type = self.typeId(ptr_constant_struct_ty_ref), |
| ... | ... | @@ -951,7 +953,7 @@ pub const DeclGen = struct { |
| 951 | 953 | }); |
| 952 | 954 | } |
| 953 | 955 | |
| 954 | | try self.spv.declareDeclDeps(spv_decl_index, icl.decl_deps.items); |
| 956 | try self.spv.declareDeclDeps(spv_decl_index, icl.decl_deps.keys()); |
| 955 | 957 | self.spv.endGlobal(spv_decl_index, begin_inst); |
| 956 | 958 | } |
| 957 | 959 | |
| ... | ... | @@ -1007,7 +1009,8 @@ pub const DeclGen = struct { |
| 1007 | 1009 | false, |
| 1008 | 1010 | alignment, |
| 1009 | 1011 | ); |
| 1010 | | try self.func.decl_deps.append(self.spv.gpa, spv_decl_index); |
| 1012 | log.debug("indirect constant: index = {}", .{@enumToInt(spv_decl_index)}); |
| 1013 | try self.func.decl_deps.put(self.spv.gpa, spv_decl_index, {}); |
| 1011 | 1014 | |
| 1012 | 1015 | try self.func.body.emit(self.spv.gpa, .OpLoad, .{ |
| 1013 | 1016 | .id_result_type = result_ty_id, |
| ... | ... | @@ -1471,7 +1474,7 @@ pub const DeclGen = struct { |
| 1471 | 1474 | const spv_decl_index = try self.resolveDecl(self.decl_index); |
| 1472 | 1475 | |
| 1473 | 1476 | const decl_id = self.spv.declPtr(spv_decl_index).result_id; |
| 1474 | | log.debug("genDecl {s} = {}", .{ decl.name, decl_id }); |
| 1477 | log.debug("genDecl: id = {}, index = {}, name = {s}", .{ decl_id.id, @enumToInt(spv_decl_index), decl.name }); |
| 1475 | 1478 | |
| 1476 | 1479 | if (decl.val.castTag(.function)) |_| { |
| 1477 | 1480 | assert(decl.ty.zigTypeTag() == .Fn); |