| ... | ... | @@ -75,7 +75,8 @@ sections: struct { |
| 75 | 75 | execution_modes: Section = .{}, |
| 76 | 76 | /// OpString, OpSourcExtension, OpSource, OpSourceContinued. |
| 77 | 77 | debug_strings: Section = .{}, |
| 78 | | // OpName, OpMemberName - skip for now. |
| 78 | // OpName, OpMemberName. |
| 79 | debug_names: Section = .{}, |
| 79 | 80 | // OpModuleProcessed - skip for now. |
| 80 | 81 | /// Annotation instructions (OpDecorate etc). |
| 81 | 82 | annotations: Section = .{}, |
| ... | ... | @@ -115,6 +116,7 @@ pub fn deinit(self: *Module) void { |
| 115 | 116 | self.sections.entry_points.deinit(self.gpa); |
| 116 | 117 | self.sections.execution_modes.deinit(self.gpa); |
| 117 | 118 | self.sections.debug_strings.deinit(self.gpa); |
| 119 | self.sections.debug_names.deinit(self.gpa); |
| 118 | 120 | self.sections.annotations.deinit(self.gpa); |
| 119 | 121 | self.sections.types_globals_constants.deinit(self.gpa); |
| 120 | 122 | self.sections.functions.deinit(self.gpa); |
| ... | ... | @@ -154,6 +156,7 @@ pub fn flush(self: Module, file: std.fs.File) !void { |
| 154 | 156 | self.sections.entry_points.toWords(), |
| 155 | 157 | self.sections.execution_modes.toWords(), |
| 156 | 158 | self.sections.debug_strings.toWords(), |
| 159 | self.sections.debug_names.toWords(), |
| 157 | 160 | self.sections.annotations.toWords(), |
| 158 | 161 | self.sections.types_globals_constants.toWords(), |
| 159 | 162 | self.sections.functions.toWords(), |
| ... | ... | @@ -244,12 +247,25 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { |
| 244 | 247 | const result_id = self.allocId(); |
| 245 | 248 | const ref_id = result_id.toRef(); |
| 246 | 249 | const types = &self.sections.types_globals_constants; |
| 250 | const debug_names = &self.sections.debug_names; |
| 247 | 251 | const annotations = &self.sections.annotations; |
| 248 | 252 | const result_id_operand = .{ .id_result = result_id }; |
| 249 | 253 | |
| 250 | 254 | switch (ty.tag()) { |
| 251 | | .void => try types.emit(self.gpa, .OpTypeVoid, result_id_operand), |
| 252 | | .bool => try types.emit(self.gpa, .OpTypeBool, result_id_operand), |
| 255 | .void => { |
| 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 | 269 | .u8, |
| 254 | 270 | .u16, |
| 255 | 271 | .u32, |
| ... | ... | @@ -260,6 +276,7 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { |
| 260 | 276 | .i64, |
| 261 | 277 | .int, |
| 262 | 278 | => { |
| 279 | const bits = ty.intFloatBits(); |
| 263 | 280 | const signedness: spec.LiteralInteger = switch (ty.intSignedness()) { |
| 264 | 281 | .unsigned => 0, |
| 265 | 282 | .signed => 1, |
| ... | ... | @@ -267,14 +284,37 @@ pub fn emitType(self: *Module, ty: Type) !IdResultType { |
| 267 | 284 | |
| 268 | 285 | try types.emit(self.gpa, .OpTypeInt, .{ |
| 269 | 286 | .id_result = result_id, |
| 270 | | .width = ty.intFloatBits(), |
| 287 | .width = bits, |
| 271 | 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 | 318 | .vector => try types.emit(self.gpa, .OpTypeVector, .{ |
| 279 | 319 | .id_result = result_id, |
| 280 | 320 | .component_type = self.typeResultId(ty.childType()).toRef(), |