Skip to documentation
SLOP

tiny.chant.lower.convert

Reference tiny.chant lower convert

Defined in lower.

API (8)

Actions

Public operations.

No direct callersNo direct callslowerconvert
Static calls · unresolved targets: unknown · external targets: unknown.

Source

Called byCallslower.localdeclareprivate sourcelib.chant.src.lower.localwriteInitializerlower.convertsameScalarlower.convertscalarTypelower.emitappendlower.convertconvert
Static calls · unresolved targets: 0 · external targets: 3.
Called byCallsNo direct callslower.convertvalueTypelowerlowerFunctionlower.convertpointerElement
Static calls · unresolved targets: 0 · external targets: 2.
No direct callersNo direct callslower.convertpromote
Static calls · unresolved targets: 0 · external targets: 2.
Called byCallsNo direct callslower.convertconvertlower.convertsameScalar
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallslower.convertscalarTypeprivate sourcelib.chant.src.lower.convertbitintScalarKindlower.convertscalarKind
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallslower.convertconvertlower.convertvalueTypeprivate sourcelib.chant.src.lower.localintValueprivate sourcelib.chant.src.lower.localzeroValuelower.memoryallocaObject+2 morelower.convertscalarKindtiny.choirdialects.ArithDialectgetScalarTypelower.convertscalarType
Static calls · unresolved targets: 0 · external targets: 0.
Called byCallsNo direct callerslower.emitappendtiny.choirdialects.ArithDialectgetIndexTypelower.converttoIndex
Static calls · unresolved targets: 0 · external targets: 3.
Called byCallslowerlowerFunctionlower.convertpointerElementlower.convertscalarTypetiny.choirdialects.MemrefDialectgetMemrefTypeDynamiclower.convertvalueType
Static calls · unresolved targets: 0 · external targets: 1.

Source: lib/chant/src/lower/convert.zig

zig
const choir = @import("choir");const ast = @import("../ast/root.zig");const context = @import("context.zig");const emit = @import("emit.zig");const Error = @import("error.zig").Error;const ArithDialect = choir.dialects.ArithDialect;const MemrefDialect = choir.dialects.MemrefDialect;const Lowerer = context.Lowerer;pub fn scalarKind(c_type: *const ast.Type) Error!choir.dialects.arith.ScalarKind {    return switch (c_type.kind) {        .enum_type => try scalarKind(c_type.child orelse &ast.types.int_type),        .char_type => if (c_type.is_unsigned) .u8 else .i8,        .short_type => if (c_type.is_unsigned) .u16 else .i16,        .int_type => if (c_type.is_unsigned) .u32 else .i32,        .long_type => if (c_type.is_unsigned) .u64 else .i64,        .bitint_type => try bitintScalarKind(c_type.bit_width, c_type.is_unsigned),        .float_type => .f32,        .double_type => .f64,        .decimal32_type => .f32,        .decimal64_type => .f64,        .decimal128_type => error.UnsupportedType,        else => error.UnsupportedType,    };}fn bitintScalarKind(width: u16, is_unsigned: bool) Error!choir.dialects.arith.ScalarKind {    if (width <= 8) return if (is_unsigned) .u8 else .i8;    if (width <= 16) return if (is_unsigned) .u16 else .i16;    if (width <= 32) return if (is_unsigned) .u32 else .i32;    if (width <= 64) return if (is_unsigned) .u64 else .i64;    return error.UnsupportedType;}pub fn scalarType(lowerer: *Lowerer, c_type: *const ast.Type) Error!choir.Type {    const kind = try scalarKind(c_type);    return ArithDialect.getScalarType(lowerer.ctx, kind) catch return error.OutOfMemory;}pub fn pointerElement(c_type: *const ast.Type) Error!*const ast.Type {    var current = ast.types.element(c_type) orelse return error.UnsupportedType;    while (current.kind == .array) {        current = ast.types.element(current) orelse return error.UnsupportedType;    }    if (!ast.types.isArithmetic(current)) return error.UnsupportedType;    return current;}pub fn valueType(lowerer: *Lowerer, c_type: *const ast.Type) Error!choir.Type {    if (ast.types.isPointerLike(c_type)) {        const element = try pointerElement(c_type);        const element_type = try scalarType(lowerer, element);        return MemrefDialect.getMemrefTypeDynamic(lowerer.ctx, element_type, .host) catch return error.OutOfMemory;    }    return scalarType(lowerer, c_type);}pub fn sameScalar(lhs: *const ast.Type, rhs: *const ast.Type) bool {    if (lhs.kind == .enum_type and rhs.kind == .enum_type) {        return sameScalar(lhs.child orelse &ast.types.int_type, rhs.child orelse &ast.types.int_type);    }    return lhs.kind == rhs.kind and lhs.is_unsigned == rhs.is_unsigned and lhs.bit_width == rhs.bit_width;}pub fn promote(c_type: *const ast.Type) *const ast.Type {    if (c_type.kind == .bitint_type) return c_type;    if (c_type.kind == .enum_type) return promote(c_type.child orelse &ast.types.int_type);    if (ast.types.isInteger(c_type) and ast.types.integerRank(c_type) < ast.types.integerRank(&ast.types.int_type)) {        return &ast.types.int_type;    }    return c_type;}pub fn convert(    lowerer: *Lowerer,    value: *choir.Value,    from: *const ast.Type,    to: *const ast.Type,) Error!*choir.Value {    if (sameScalar(from, to)) return value;    if (!ast.types.isArithmetic(from) or !ast.types.isArithmetic(to)) return error.UnsupportedType;    const target = try scalarType(lowerer, to);    const cast = ArithDialect.CastOp.create(lowerer.ctx, lowerer.loc, value, target) catch return error.OutOfMemory;    try emit.append(lowerer, cast.op);    var mutable = cast;    return mutable.getResult();}pub fn toIndex(lowerer: *Lowerer, value: *choir.Value, from: *const ast.Type) Error!*choir.Value {    if (!ast.types.isInteger(from)) return error.UnsupportedType;    const index_type = ArithDialect.getIndexType(lowerer.ctx) catch return error.OutOfMemory;    const cast = ArithDialect.CastOp.create(lowerer.ctx, lowerer.loc, value, index_type) catch return error.OutOfMemory;    try emit.append(lowerer, cast.op);    var mutable = cast;    return mutable.getResult();}

Source: lib/chant/src/lower/root.zig:5

zig
pub const convert = @import("convert.zig");

Complete caller list for lower.convert.scalarType

7 direct callers.

Audit

Definitions9
Public names9
Members0
Version26.7.0
Revisiondaab053ee433