| ... | @@ -75,7 +75,8 @@ sections: struct { | ... | @@ -75,7 +75,8 @@ sections: struct { |
| 75 | execution_modes: Section = .{}, | 75 | execution_modes: Section = .{}, |
| 76 | /// OpString, OpSourcExtension, OpSource, OpSourceContinued. | 76 | /// OpString, OpSourcExtension, OpSource, OpSourceContinued. |
| 77 | debug_strings: Section = .{}, | 77 | debug_strings: Section = .{}, |
| 78 | // OpName, OpMemberName - skip for now. | 78 | // OpName, OpMemberName. |
| | 79 | debug_names: Section = .{}, |
| 79 | // OpModuleProcessed - skip for now. | 80 | // OpModuleProcessed - skip for now. |
| 80 | /// Annotation instructions (OpDecorate etc). | 81 | /// Annotation instructions (OpDecorate etc). |
| 81 | annotations: Section = .{}, | 82 | annotations: Section = .{}, |
| ... | @@ -115,6 +116,7 @@ pub fn deinit(self: *Module) void { | ... | @@ -115,6 +116,7 @@ pub fn deinit(self: *Module) void { |
| 115 | self.sections.entry_points.deinit(self.gpa); | 116 | self.sections.entry_points.deinit(self.gpa); |
| 116 | self.sections.execution_modes.deinit(self.gpa); | 117 | self.sections.execution_modes.deinit(self.gpa); |
| 117 | self.sections.debug_strings.deinit(self.gpa); | 118 | self.sections.debug_strings.deinit(self.gpa); |
| | 119 | self.sections.debug_names.deinit(self.gpa); |
| 118 | self.sections.annotations.deinit(self.gpa); | 120 | self.sections.annotations.deinit(self.gpa); |
| 119 | self.sections.types_globals_constants.deinit(self.gpa); | 121 | self.sections.types_globals_constants.deinit(self.gpa); |
| 120 | self.sections.functions.deinit(self.gpa); | 122 | self.sections.functions.deinit(self.gpa); |
| ... | @@ -154,6 +156,7 @@ pub fn flush(self: Module, file: std.fs.File) !void { | ... | @@ -154,6 +156,7 @@ pub fn flush(self: Module, file: std.fs.File) !void { |
| 154 | self.sections.entry_points.toWords(), | 156 | self.sections.entry_points.toWords(), |
| 155 | self.sections.execution_modes.toWords(), | 157 | self.sections.execution_modes.toWords(), |
| 156 | self.sections.debug_strings.toWords(), | 158 | self.sections.debug_strings.toWords(), |
| | 159 | self.sections.debug_names.toWords(), |
| 157 | self.sections.annotations.toWords(), | 160 | self.sections.annotations.toWords(), |
| 158 | self.sections.types_globals_constants.toWords(), | 161 | self.sections.types_globals_constants.toWords(), |
| 159 | self.sections.functions.toWords(), | 162 | self.sections.functions.toWords(), |
| ... | @@ -244,12 +247,25 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { | ... | @@ -244,12 +247,25 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { |
| 244 | const result_id = self.allocId(); | 247 | const result_id = self.allocId(); |
| 245 | const ref_id = result_id.toRef(); | 248 | const ref_id = result_id.toRef(); |
| 246 | const types = &self.sections.types_globals_constants; | 249 | const types = &self.sections.types_globals_constants; |
| | 250 | const debug_names = &self.sections.debug_names; |
| 247 | const annotations = &self.sections.annotations; | 251 | const annotations = &self.sections.annotations; |
| 248 | const result_id_operand = .{ .id_result = result_id }; | 252 | const result_id_operand = .{ .id_result = result_id }; |
| 249 | | 253 | |
| 250 | switch (ty.tag()) { | 254 | switch (ty.tag()) { |
| 251 | .void => try types.emit(self.gpa, .OpTypeVoid, result_id_operand), | 255 | .void => { |
| 252 | .bool => try types.emit(self.gpa, .OpTypeBool, result_id_operand), | 256 | try types.emit(self.gpa, .OpTypeVoid, result_id_operand); |
| | 257 | try debug_names.emit(self.gpa, .OpName, .{ |
| | 258 | .target = result_id.toRef(), |
| | 259 | .name = "void", |
| | 260 | }); |
| | 261 | }, |
| | 262 | .bool => { |
| | 263 | try types.emit(self.gpa, .OpTypeBool, result_id_operand); |
| | 264 | try debug_names.emit(self.gpa, .OpName, .{ |
| | 265 | .target = result_id.toRef(), |
| | 266 | .name = "bool", |
| | 267 | }); |
| | 268 | }, |
| 253 | .u8, | 269 | .u8, |
| 254 | .u16, | 270 | .u16, |
| 255 | .u32, | 271 | .u32, |
| ... | @@ -260,6 +276,7 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { | ... | @@ -260,6 +276,7 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { |
| 260 | .i64, | 276 | .i64, |
| 261 | .int, | 277 | .int, |
| 262 | => { | 278 | => { |
| | 279 | const bits = ty.intFloatBits(); |
| 263 | const signedness: spec.LiteralInteger = switch (ty.intSignedness()) { | 280 | const signedness: spec.LiteralInteger = switch (ty.intSignedness()) { |
| 264 | .unsigned => 0, | 281 | .unsigned => 0, |
| 265 | .signed => 1, | 282 | .signed => 1, |
| ... | @@ -267,14 +284,37 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { | ... | @@ -267,14 +284,37 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { |
| 267 | | 284 | |
| 268 | try types.emit(self.gpa, .OpTypeInt, .{ | 285 | try types.emit(self.gpa, .OpTypeInt, .{ |
| 269 | .id_result = result_id, | 286 | .id_result = result_id, |
| 270 | .width = ty.intFloatBits(), | 287 | .width = bits, |
| 271 | .signedness = signedness, | 288 | .signedness = signedness, |
| 272 | }); | 289 | }); |
| | 290 | |
| | 291 | const ui: []const u8 = switch (signedness) { |
| | 292 | 0 => "u", |
| | 293 | 1 => "i", |
| | 294 | else => unreachable, |
| | 295 | }; |
| | 296 | const name = try std.fmt.allocPrint(self.gpa, "{s}{}", .{ ui, bits }); |
| | 297 | defer self.gpa.free(name); |
| | 298 | |
| | 299 | try debug_names.emit(self.gpa, .OpName, .{ |
| | 300 | .target = result_id.toRef(), |
| | 301 | .name = name, |
| | 302 | }); |
| | 303 | }, |
| | 304 | .f16, .f32, .f64 => { |
| | 305 | const bits = ty.intFloatBits(); |
| | 306 | try types.emit(self.gpa, .OpTypeFloat, .{ |
| | 307 | .id_result = result_id, |
| | 308 | .width = bits, |
| | 309 | }); |
| | 310 | |
| | 311 | const name = try std.fmt.allocPrint(self.gpa, "f{}", .{bits}); |
| | 312 | defer self.gpa.free(name); |
| | 313 | try debug_names.emit(self.gpa, .OpName, .{ |
| | 314 | .target = result_id.toRef(), |
| | 315 | .name = name, |
| | 316 | }); |
| 273 | }, | 317 | }, |
| 274 | .f16, .f32, .f64 => try types.emit(self.gpa, .OpTypeFloat, .{ | | |
| 275 | .id_result = result_id, | | |
| 276 | .width = ty.intFloatBits(), | | |
| 277 | }), | | |
| 278 | .vector => try types.emit(self.gpa, .OpTypeVector, .{ | 318 | .vector => try types.emit(self.gpa, .OpTypeVector, .{ |
| 279 | .id_result = result_id, | 319 | .id_result = result_id, |
| 280 | .component_type = self.typeResultId(ty.childType()).toRef(), | 320 | .component_type = self.typeResultId(ty.childType()).toRef(), |