@@ -338,21 +338,41 @@ uint64_t get_constant_value(const slang::ConstantValue &constant,
338
338
}
339
339
340
340
void ExprCodeGenVisitor::handle (const slang::RangeSelectExpression &expr) {
341
- if (!expr.left ().constant )
342
- throw NotSupportedException (" Only constant range select supported" ,
343
- expr.left ().syntax ->sourceRange ().start ());
344
-
345
- if (!expr.right ().constant )
346
- throw NotSupportedException (" Only constant range select supported" ,
347
- expr.right ().syntax ->sourceRange ().start ());
348
-
349
341
s << " (" ;
350
342
expr.value ().visit (*this );
351
- s << " ).slice<" ;
352
- s << get_constant_value (*expr.left ().constant , expr.left ().sourceRange .start ());
353
- s << " , " ;
354
- s << get_constant_value (*expr.right ().constant , expr.right ().sourceRange .start ());
355
- s << " >()" ;
343
+ s << " )" ;
344
+ switch (expr.selectionKind ) {
345
+ case slang::RangeSelectionKind::Simple: {
346
+ if (!expr.left ().constant )
347
+ throw NotSupportedException (" Only constant range select supported" ,
348
+ expr.left ().syntax ->sourceRange ().start ());
349
+
350
+ if (!expr.right ().constant )
351
+ throw NotSupportedException (" Only constant range select supported" ,
352
+ expr.right ().syntax ->sourceRange ().start ());
353
+
354
+ s << " .slice<" ;
355
+ s << get_constant_value (*expr.left ().constant , expr.left ().sourceRange .start ());
356
+ s << " , " ;
357
+ s << get_constant_value (*expr.right ().constant , expr.right ().sourceRange .start ());
358
+ s << " >()" ;
359
+ break ;
360
+ }
361
+ case slang::RangeSelectionKind::IndexedDown:
362
+ case slang::RangeSelectionKind::IndexedUp: {
363
+ if (!expr.right ().constant )
364
+ throw NotSupportedException (" Only constant range select supported" ,
365
+ expr.right ().syntax ->sourceRange ().start ());
366
+ auto target_size =
367
+ get_constant_value (*expr.right ().constant , expr.right ().sourceRange .start ());
368
+ const auto *increase =
369
+ expr.selectionKind == slang::RangeSelectionKind::IndexedUp ? " true" : " false" ;
370
+ s << " .slice<" ;
371
+ s << target_size << " , " << increase << " >(" ;
372
+ expr.left ().visit (*this );
373
+ s << " )" ;
374
+ }
375
+ }
356
376
}
357
377
358
378
[[maybe_unused]] void ExprCodeGenVisitor::handle (const slang::ConcatenationExpression &sym) {
0 commit comments