File tree Expand file tree Collapse file tree 3 files changed +29
-0
lines changed
Expand file tree Collapse file tree 3 files changed +29
-0
lines changed Original file line number Diff line number Diff line change @@ -753,6 +753,14 @@ absl::Status BytecodeEmitter::HandleBuiltinBitCount(const Invocation* node) {
753753 return absl::OkStatus ();
754754}
755755
756+ absl::Status BytecodeEmitter::HandleBuiltinArraySize (const Invocation* node) {
757+ XLS_ASSIGN_OR_RETURN (InterpValue default_or_override_interp_value,
758+ type_info_->GetConstExpr (node));
759+ bytecode_.push_back (Bytecode (node->span (), Bytecode::Op::kLiteral ,
760+ default_or_override_interp_value));
761+ return absl::OkStatus ();
762+ }
763+
756764absl::Status BytecodeEmitter::HandleBuiltinElementCount (
757765 const Invocation* node) {
758766 VLOG (5 ) << " BytecodeEmitter::HandleInvocation - ElementCount @ "
@@ -1107,6 +1115,9 @@ absl::Status BytecodeEmitter::HandleInvocation(const Invocation* node) {
11071115 name_ref != nullptr && name_ref->IsBuiltin ()) {
11081116 VLOG (10 ) << " HandleInvocation; builtin name_ref: " << name_ref->ToString ();
11091117
1118+ if (name_ref->identifier () == " array_size" ) {
1119+ return HandleBuiltinArraySize (node);
1120+ }
11101121 if (name_ref->identifier () == " bit_count" ) {
11111122 return HandleBuiltinBitCount (node);
11121123 }
Original file line number Diff line number Diff line change @@ -151,6 +151,7 @@ class BytecodeEmitter : public ExprVisitor {
151151 absl::Status HandleXlsTuple (const XlsTuple* node) override ;
152152
153153 // keep-sorted start
154+ absl::Status HandleBuiltinArraySize (const Invocation* node);
154155 absl::Status HandleBuiltinBitCount (const Invocation* node);
155156 absl::Status HandleBuiltinCheckedCast (const Invocation* node);
156157 absl::Status HandleBuiltinConfiguredValueOr (const Invocation* node);
Original file line number Diff line number Diff line change @@ -9010,5 +9010,22 @@ fn main() -> u32 {
90109010 EXPECT_EQ (result.tm .warnings .warnings ().size (), 0 );
90119011}
90129012
9013+ TEST (TypecheckV2Test, ParametricArraySizeInRange) {
9014+ EXPECT_THAT (
9015+ R"(
9016+ fn sum_elements<N: u32>(elements: u32[N]) -> u32 {
9017+ let result: u32 = for (i, accum) in u32:0..array_size(elements) {
9018+ accum + elements[i]
9019+ }(u32:0);
9020+ result
9021+ }
9022+
9023+ pub fn sum_elements_2(elements: u32[2]) -> u32 {
9024+ sum_elements(elements)
9025+ }
9026+ )" ,
9027+ TypecheckSucceeds (HasNodeWithType (" sum_elements(elements)" , " uN[32]" )));
9028+ }
9029+
90139030} // namespace
90149031} // namespace xls::dslx
You can’t perform that action at this time.
0 commit comments