| ... | @@ -37,7 +37,7 @@ decl_exports: std.AutoHashMap(*Decl, []*Export), | ... | @@ -37,7 +37,7 @@ decl_exports: std.AutoHashMap(*Decl, []*Export), |
| 37 | /// This table owns the Export memory. | 37 | /// This table owns the Export memory. |
| 38 | export_owners: std.AutoHashMap(*Decl, []*Export), | 38 | export_owners: std.AutoHashMap(*Decl, []*Export), |
| 39 | /// Maps fully qualified namespaced names to the Decl struct for them. | 39 | /// Maps fully qualified namespaced names to the Decl struct for them. |
| 40 | decl_table: std.AutoHashMap(Scope.NameHash, *Decl), | 40 | decl_table: DeclTable, |
| 41 | | 41 | |
| 42 | optimize_mode: std.builtin.Mode, | 42 | optimize_mode: std.builtin.Mode, |
| 43 | link_error_flags: link.ElfFile.ErrorFlags = .{}, | 43 | link_error_flags: link.ElfFile.ErrorFlags = .{}, |
| ... | @@ -66,6 +66,8 @@ generation: u32 = 0, | ... | @@ -66,6 +66,8 @@ generation: u32 = 0, |
| 66 | /// contains Decls that need to be deleted if they end up having no references to them. | 66 | /// contains Decls that need to be deleted if they end up having no references to them. |
| 67 | deletion_set: std.ArrayListUnmanaged(*Decl) = .{}, | 67 | deletion_set: std.ArrayListUnmanaged(*Decl) = .{}, |
| 68 | | 68 | |
| | 69 | const DeclTable = std.HashMap(Scope.NameHash, *Decl, Scope.name_hash_hash, Scope.name_hash_eql); |
| | 70 | |
| 69 | const WorkItem = union(enum) { | 71 | const WorkItem = union(enum) { |
| 70 | /// Write the machine code for a Decl to the output file. | 72 | /// Write the machine code for a Decl to the output file. |
| 71 | codegen_decl: *Decl, | 73 | codegen_decl: *Decl, |
| ... | @@ -417,6 +419,14 @@ pub const Scope = struct { | ... | @@ -417,6 +419,14 @@ pub const Scope = struct { |
| 417 | } | 419 | } |
| 418 | } | 420 | } |
| 419 | | 421 | |
| | 422 | fn name_hash_hash(x: NameHash) u32 { |
| | 423 | return @truncate(u32, @bitCast(u128, x)); |
| | 424 | } |
| | 425 | |
| | 426 | fn name_hash_eql(a: NameHash, b: NameHash) bool { |
| | 427 | return @bitCast(u128, a) == @bitCast(u128, b); |
| | 428 | } |
| | 429 | |
| 420 | pub const Tag = enum { | 430 | pub const Tag = enum { |
| 421 | /// .zir source code. | 431 | /// .zir source code. |
| 422 | zir_module, | 432 | zir_module, |
| ... | @@ -711,7 +721,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { | ... | @@ -711,7 +721,7 @@ pub fn init(gpa: *Allocator, options: InitOptions) !Module { |
| 711 | .bin_file_path = options.bin_file_path, | 721 | .bin_file_path = options.bin_file_path, |
| 712 | .bin_file = bin_file, | 722 | .bin_file = bin_file, |
| 713 | .optimize_mode = options.optimize_mode, | 723 | .optimize_mode = options.optimize_mode, |
| 714 | .decl_table = std.AutoHashMap(Scope.NameHash, *Decl).init(gpa), | 724 | .decl_table = DeclTable.init(gpa), |
| 715 | .decl_exports = std.AutoHashMap(*Decl, []*Export).init(gpa), | 725 | .decl_exports = std.AutoHashMap(*Decl, []*Export).init(gpa), |
| 716 | .export_owners = std.AutoHashMap(*Decl, []*Export).init(gpa), | 726 | .export_owners = std.AutoHashMap(*Decl, []*Export).init(gpa), |
| 717 | .failed_decls = std.AutoHashMap(*Decl, *ErrorMsg).init(gpa), | 727 | .failed_decls = std.AutoHashMap(*Decl, *ErrorMsg).init(gpa), |