tiny.choir.Attribute
Defined in ir.attribute.
API (37)
Actions
Public operations.
ArrayAttr.getValuesBoolAttr.getValueFloatAttr.getF32ValueFloatAttr.getValueIntegerAttr.getUnsignedValueIntegerAttr.getValueInterfaceHandleStringAttr.getValueStringListAttr.getValuesSymbolRefAttr.getLeafReferenceSymbolRefAttr.getNestedReferencesSymbolRefAttr.getRootReferenceSymbolRefAttr.isFlatTypeListAttr.getValuesattrIdFromIntcasteqlformatgetAbstractAttributegetInterfacehasStorageTypeinterfaceisa
Types and contracts
Public types and contracts.
ArrayAttrAttrIDBoolAttrDialectAttrFloatAttrIntegerAttrStringAttrStringListAttrSymbolRefAttrTypeListAttrfirst_dynamic_attr_id
Fields and members
Public fields and members.
Source
Source: lib/choir/src/core/attribute.zig:5
zig
pub const Attribute = struct { attr_id: AttrID, impl: *const anyopaque, abstract: *const interfaces.AbstractAttribute, pub const AttrID = enum(u32) { invalid = 0, _, }; pub const first_dynamic_attr_id: u32 = @backingInt(AttrID.invalid) + 1; pub const DialectAttr = struct { payload: []const u8, context: *const anyopaque, }; pub const IntegerAttr = struct { value: i64, width: u8, is_signed: bool, context: *const anyopaque, pub fn getValue(self: *const IntegerAttr) i64 { return self.value; } pub fn getUnsignedValue(self: *const IntegerAttr) u64 { return @bitCast(self.value); } }; pub const FloatAttr = struct { value: f64, width: u8, context: *const anyopaque, pub fn getValue(self: *const FloatAttr) f64 { return self.value; } pub fn getF32Value(self: *const FloatAttr) f32 { return @floatCast(self.value); } }; pub const BoolAttr = struct { value: bool, context: *const anyopaque, pub fn getValue(self: *const BoolAttr) bool { return self.value; } }; pub const StringAttr = struct { value: []const u8, context: *const anyopaque, pub fn getValue(self: *const StringAttr) []const u8 { return self.value; } }; pub const SymbolRefAttr = struct { root_reference: []const u8, nested_references: []const []const u8, context: *const anyopaque, pub fn getRootReference(self: *const SymbolRefAttr) []const u8 { return self.root_reference; } pub fn getNestedReferences(self: *const SymbolRefAttr) []const []const u8 { return self.nested_references; } pub fn getLeafReference(self: *const SymbolRefAttr) []const u8 { if (self.nested_references.len == 0) return self.root_reference; return self.nested_references[self.nested_references.len - 1]; } pub fn isFlat(self: *const SymbolRefAttr) bool { return self.nested_references.len == 0; } }; pub const StringListAttr = struct { values: []const []const u8, context: *const anyopaque, pub fn getValues(self: *const StringListAttr) []const []const u8 { return self.values; } }; pub const TypeListAttr = struct { values: []const Type, context: *const anyopaque, pub fn getValues(self: *const TypeListAttr) []const Type { return self.values; } }; pub const ArrayAttr = struct { values: []const Attribute, context: *const anyopaque, pub fn getValues(self: *const ArrayAttr) []const Attribute { return self.values; } }; pub fn attrIdFromInt(id: u32) AttrID { return @fromBackingInt(@intCast(id)); } pub fn isa(self: Attribute, comptime attr_id: AttrID) bool { return self.attr_id == attr_id; } pub fn eql(self: Attribute, other: Attribute) bool { if (self.attr_id != other.attr_id) return false; if (self.impl == other.impl) return true; if (self.getInterface(interfaces.AttributeEqualInterface)) |vtable| { return vtable.eql(self.impl, other.impl); } return false; } pub fn getInterface(self: Attribute, comptime IFace: type) ?*const IFace.VTable { if (self.abstract.getInterface(IFace.id)) |iface| { return @ptrCast(@alignCast(iface)); } return null; } pub fn InterfaceHandle(comptime IFace: type) type { return struct { attr: Attribute, vtable: *const IFace.VTable, fn returnType(comptime fn_ptr_type: type) type { const ptr_info = @typeInfo(fn_ptr_type); const fn_type = switch (ptr_info) { .pointer => |p| p.child, else => @compileError("expected interface vtable field to be a function pointer"), }; const fn_info = switch (@typeInfo(fn_type)) { .@"fn" => |f| f, else => @compileError("expected interface vtable field to be a function pointer"), }; return fn_info.return_type orelse @compileError("generic interface vtable methods are not supported"); } fn methodFnPtrType(comptime method: std.meta.FieldEnum(IFace.VTable)) type { const dummy: IFace.VTable = undefined; return @TypeOf(@field(dummy, @tagName(method))); } pub inline fn call( self: @This(), comptime method: std.meta.FieldEnum(IFace.VTable), args: anytype, ) returnType(methodFnPtrType(method)) { const fn_ptr = @field(self.vtable, @tagName(method)); return @call(.auto, fn_ptr, .{self.attr.impl} ++ args); } }; } pub fn interface(self: Attribute, comptime IFace: type) ?InterfaceHandle(IFace) { const vtable = self.getInterface(IFace) orelse return null; return .{ .attr = self, .vtable = vtable }; } pub fn getAbstractAttribute(self: Attribute) *const interfaces.AbstractAttribute { return self.abstract; } pub fn hasStorageType(self: Attribute, comptime T: type) bool { return storageTypeMatchesName(T, self.abstract.name); } pub fn cast(self: Attribute, comptime T: type) ?*const T { if (!self.hasStorageType(T)) return null; return @ptrCast(@alignCast(self.impl)); } pub fn format(self: Attribute, writer: *std.Io.Writer) std.Io.Writer.Error!void { if (self.getInterface(interfaces.AttributePrintInterface)) |vtable| { return vtable.print(self.impl, writer); } if (self.abstract.name.len > 0) { try writer.print("#attr<{s}>", .{self.abstract.name}); } else { try writer.print("#attr<{d}>", .{@backingInt(self.attr_id)}); } }};Source: lib/choir/src/root.zig:48
zig
pub const Attribute = ir.Attribute;Also reachable as
backends.wasm.emission.module_encoding.common.ir.Attribute, backends.wasm.emission.module_encoding.common.ir.attribute.Attribute, ir.Attribute.
Complete caller list for Attribute.attrIdFromInt
13 direct callers.
lib.choir.src.core.attribute.test_Attribute.cast_checks_comptime_storage_type[function] — test source atlib/choir/src/core/attribute.zig:481in nearest public ownertiny.choir.ir.attributelib.choir.src.core.attribute.test_NamedAttributeList_grows_spilled_dictionaries_geometrically[function] — test source atlib/choir/src/core/attribute.zig:428in nearest public ownertiny.choir.ir.attributelib.choir.src.core.attribute.test_NamedAttributeList_keeps_dictionary_semantics[function] — test source atlib/choir/src/core/attribute.zig:338in nearest public ownertiny.choir.ir.attributelib.choir.src.core.attribute.test_NamedAttributeList_stores_small_dictionaries_without_allocation[function] — test source atlib/choir/src/core/attribute.zig:389in nearest public ownertiny.choir.ir.attributelib.choir.src.core.context.attrs.getArrayAttr[function] — private source atlib/choir/src/core/context/attrs.zig:436in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getBoolAttr[function] — private source atlib/choir/src/core/context/attrs.zig:213in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getDialectAttr[function] — private source atlib/choir/src/core/context/attrs.zig:76in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getFloatAttr[function] — private source atlib/choir/src/core/context/attrs.zig:166in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getIntegerAttr[function] — private source atlib/choir/src/core/context/attrs.zig:116in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getStringAttr[function] — private source atlib/choir/src/core/context/attrs.zig:242in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getStringListAttr[function] — private source atlib/choir/src/core/context/attrs.zig:358in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getSymbolRefAttr[function] — private source atlib/choir/src/core/context/attrs.zig:276in nearest public ownerlib.choir.src.core.context.attrslib.choir.src.core.context.attrs.getTypeListAttr[function] — private source atlib/choir/src/core/context/attrs.zig:399in nearest public ownerlib.choir.src.core.context.attrs
Audit
| Definitions | 35 |
|---|---|
| Public names | 175 |
| Members | 27 |
| Version | 26.7.0 |
| Revision | daab053ee433 |