[IR] adding runtime array support
Mirror Gitea refs to GitHub / mirror (push) Successful in 16s
Test / build_and_test (push) Failing after 1m39s
Build / build (push) Successful in 5m4s

This commit is contained in:
2026-08-30 00:56:02 +02:00
parent e40db08357
commit a6c6295d87
10 changed files with 451 additions and 147 deletions
+27
View File
@@ -375,6 +375,23 @@ fn validateOperation(module: *const module_ir.Module, function_id: ids.FunctionI
} else if (result_type == null or result_type.? != callee.return_type)
return ValidationError.WrongResultType;
},
.array_length => |op| {
const resource = module.resources.get(op.resource) orelse return ValidationError.InvalidValue;
if (resource.kind != .storage_buffer)
return ValidationError.WrongResourceKind;
if (!isUnsignedInteger(module, try operandType(module, function_id, op.byte_offset)))
return ValidationError.WrongOperandType;
if (op.stride == 0)
return ValidationError.InvalidInstruction;
const result = result_type orelse return ValidationError.WrongResultPresence;
if (!isArrayLengthResultType(module, result))
return ValidationError.WrongResultType;
},
}
}
@@ -506,6 +523,16 @@ fn isBufferAccessibleType(module: *const module_ir.Module, type_id: ids.TypeId)
};
}
fn isArrayLengthResultType(module: *const module_ir.Module, type_id: ids.TypeId) bool {
const ty = module.types.get(type_id) orelse return false;
return switch (ty.*) {
.integer => |integer| integer.signedness == .unsigned and (integer.bits == 32 or integer.bits == 64),
else => false,
};
}
fn targetsBlock(terminator: module_ir.Terminator, target: ids.BlockId) bool {
return switch (terminator) {
.branch => |edge| edge.target == target,