matthijsr / til-vhdl

A prototype toolchain for demonstrating and exploring an intermediate representation for defining components using the Tydi interface specification.
Apache License 2.0
3 stars 1 forks source link

Generics? #47

Open matthijsr opened 2 years ago

matthijsr commented 2 years ago

Do we want Generics? If so, what should they look like and where should they apply? At the IR level? (So potentially propagated down to the target language?) Or just at the IR grammar/parser level? (So eventually emitted as fixed types/interfaces/w.e.)

matthijsr commented 2 years ago

These would have to be constants (not types), e.g. having a generic_bits type of Bits(N). Would also need to be for specific target properties (i.e., can't use that same N to also specify complexity or throughput, or vice versa).

matthijsr commented 2 years ago

Well... they could still be types, but they'd also have to be specific. E.g.:

type genericstream<a: bitcount, b: type, c: complexity, d: throughput, e: keep> = Stream(
  data: Group(a: Bits(a), b: b),
  complexity: c,
  throughput: d,
  keep: e,
);

Then propagate these generics to streamlets... Might also tie into #40 : Instead of, or in addition to the <'a> syntax, could use <a: domain>.

matthijsr commented 2 years ago

Generics can work on the language level, through constant evaluation, rather than the IR level, I think. With an explicit keyword to indicate a type, interface or streamlet is "generic". Anything generic won't actually be included in the query storage, e.g.:

generic type base_bits<N: bitcount> = Bits(N);
type byte = base_bits<8>;

Can't use generics without assigning their parameter. (But you can obviously have nested generics, which just assign the parameter with their own parameter.)

This doesn't necessarily avoid having to generate names, though, if it's possible to use generics for streamlet instances in structural implementations... but not supporting that workflow seems very limiting. If I do choose to limit that, though, I'd have to limit it such that "generic" is only supported on type and interface, and not on streamlet and impl.

Alternatively, leave the "name generation" up to the designer. (I.e., in order to instantiate a generic, you also need to specify a pre-/suffix)