tiny.chant.lower
Defined in tiny.chant.
API (13)
Actions
Public operations.
Types and contracts
Public types and contracts.
Namespaces
Public namespaces.
Source
Source: lib/chant/src/lower/context.zig:11
zig
pub const Local = struct { kind: LocalKind, value: *choir.Value, c_type: *const ast.Type,};Source: lib/chant/src/lower/context.zig:5
zig
pub const LocalKind = enum { slot, pointer_param, loop_iv,};Source: lib/chant/src/lower/context.zig:19
zig
pub const Lowerer = struct { gpa: std.mem.Allocator, arena: std.mem.Allocator, ctx: *choir.Context, loc: choir.ir.Location, block: *choir.Block, scopes: std.ArrayListUnmanaged(Scope), functions: std.StringHashMapUnmanaged(*const ast.Type), terminated: bool,};Source: lib/chant/src/lower/error.zig:1
zig
pub const Error = error{ OutOfMemory, UnsupportedConstruct, UnsupportedType, UndefinedName,};Source: lib/chant/src/lower/unit.zig:15
zig
pub const Unit = struct { module: choir.dialects.BuiltinDialect.ModuleOp, lowered: std.ArrayListUnmanaged([]const u8), skipped: std.ArrayListUnmanaged(Skipped), pub const Skipped = struct { name: []const u8, reason: Error, };};Source: lib/chant/src/lower/unit.zig:26
zig
pub fn lowerFunction( gpa: std.mem.Allocator, arena: std.mem.Allocator, ctx: *choir.Context, module: choir.dialects.BuiltinDialect.ModuleOp, functions: std.StringHashMapUnmanaged(*const ast.Type), function: ast.decl.Function,) Error!void { const loc = choir.ir.Location.getUnknown(); const return_type = function.type.child orelse return error.UnsupportedType; if (return_type.kind != .void_type) return error.UnsupportedConstruct; const body = function.body orelse return error.UnsupportedConstruct; var lowerer = Lowerer{ .gpa = gpa, .arena = arena, .ctx = ctx, .loc = loc, .block = undefined, .scopes = .empty, .functions = functions, .terminated = false, }; defer { while (lowerer.scopes.items.len > 0) scope.pop(&lowerer); lowerer.scopes.deinit(gpa); } var arg_types = std.ArrayListUnmanaged(choir.Type).empty; defer arg_types.deinit(gpa); for (function.type.params) |param| { try arg_types.append(gpa, try convert.valueType(&lowerer, param.type)); } const func = FuncDialect.FuncOp.create(ctx, loc, function.name, arg_types.items, &.{}) catch return error.OutOfMemory; const entry = func.getEntryBlock(); lowerer.block = entry; var registered = false; errdefer if (!registered) func.op.erase(); try scope.push(&lowerer); for (function.type.params, 0..) |param, i| { const argument = func.getArgument(i); if (ast.types.isPointerLike(param.type)) { const element = try convert.pointerElement(param.type); const pointer_c_type = try arena.create(ast.Type); pointer_c_type.* = .{ .kind = .pointer, .child = param.type.child }; _ = element; try scope.bind(&lowerer, param.name, .{ .kind = .pointer_param, .value = argument, .c_type = pointer_c_type }); } else { const slot = try memory.allocaScalar(&lowerer, param.type); const zero = try emit.indexConstant(&lowerer, 0); try memory.storeElement(&lowerer, .{ .memref = slot, .index = zero, .c_type = param.type }, argument); try scope.bind(&lowerer, param.name, .{ .kind = .slot, .value = slot, .c_type = param.type }); } } try statement.lowerStatement(&lowerer, body); if (!lowerer.terminated) { const ret = FuncDialect.ReturnOp.create(ctx, loc, &.{}) catch return error.OutOfMemory; try emit.append(&lowerer, ret.op); } lowerer.terminated = false; module.getBodyBlock().addOperation(func.op) catch return error.OutOfMemory; registered = true;}Source: lib/chant/src/lower/unit.zig:95
zig
pub fn lowerUnit( gpa: std.mem.Allocator, arena: std.mem.Allocator, ctx: *choir.Context, translation: ast.TranslationUnit,) Error!Unit { const loc = choir.ir.Location.getUnknown(); const module = choir.dialects.BuiltinDialect.ModuleOp.create(ctx, loc) catch return error.OutOfMemory; var result = Unit{ .module = module, .lowered = .empty, .skipped = .empty, }; var functions = std.StringHashMapUnmanaged(*const ast.Type).empty; defer functions.deinit(gpa); for (translation.declarations) |decl| { switch (decl) { .function => |decl_function| try functions.put(gpa, decl_function.name, decl_function.type), .variable => {}, } } for (translation.declarations) |decl| { switch (decl) { .function => |decl_function| { if (decl_function.body == null) continue; if (lowerFunction(gpa, arena, ctx, module, functions, decl_function)) |_| { try result.lowered.append(arena, decl_function.name); } else |err| switch (err) { error.OutOfMemory => return error.OutOfMemory, else => try result.skipped.append(arena, .{ .name = decl_function.name, .reason = err }), } }, .variable => {}, } } return result;}Source: lib/chant/src/lower/root.zig
zig
const context = @import("context.zig");const unit_mod = @import("unit.zig");pub const Error = @import("error.zig").Error;pub const convert = @import("convert.zig");pub const emit = @import("emit.zig");pub const local = @import("local.zig");pub const memory = @import("memory.zig");pub const scope = @import("scope.zig");pub const LocalKind = context.LocalKind;pub const Local = context.Local;pub const Lowerer = context.Lowerer;pub const Unit = unit_mod.Unit;pub const lowerFunction = unit_mod.lowerFunction;pub const lowerUnit = unit_mod.lowerUnit;Source: lib/chant/src/root.zig:64
zig
pub const lower = @import("lower/root.zig");Complete call list for lower.lowerFunction
11 direct calls.
tiny.chant.lower.convert.pointerElement[function] atlib/chant/src/lower/convert.zig:41tiny.chant.lower.convert.valueType[function] atlib/chant/src/lower/convert.zig:50tiny.chant.lower.emit.append[function] atlib/chant/src/lower/emit.zig:9tiny.chant.lower.emit.indexConstant[function] atlib/chant/src/lower/emit.zig:13tiny.chant.lower.memory.allocaScalar[function] atlib/chant/src/lower/memory.zig:18tiny.chant.lower.memory.storeElement[function] atlib/chant/src/lower/memory.zig:59tiny.chant.lower.scope.bind[function] atlib/chant/src/lower/scope.zig:27tiny.chant.lower.scope.pop[function] atlib/chant/src/lower/scope.zig:13tiny.chant.lower.scope.push[function] atlib/chant/src/lower/scope.zig:9tiny.choir.dialects.FuncDialect.FuncOp.create[function] atlib/choir/src/dialects/func.zig:134tiny.choir.dialects.FuncDialect.ReturnOp.create[function] atlib/choir/src/dialects/func.zig:424
Audit
| Definitions | 9 |
|---|---|
| Public names | 9 |
| Members | 23 |
| Version | 26.7.0 |
| Revision | daab053ee433 |