generateSystemC method

  1. @override
String generateSystemC({
  1. required String className,
  2. SystemCModelOptions options = const SystemCModelOptions(),
})
override

Wraps the generic SystemC model with this module's port names.

Implementation

@override
String generateSystemC({
  required String className,
  SystemCModelOptions options = const SystemCModelOptions(),
}) {
  final coreName = '${className}__RohdHclAssociativeModel';
  final twoState = options.portType == SystemCModelPortType.twoState;
  bool scalar(String port) =>
      port == 'clk' ||
      port == 'reset' ||
      port.endsWith('_en') ||
      port.endsWith('_hit') ||
      port.endsWith('_valid');
  String type(String port, int width) => twoState
      ? width == 1
          ? 'bool'
          : width <= 64
              ? 'sc_dt::sc_uint<$width>'
              : 'sc_dt::sc_biguint<$width>'
      : scalar(port)
          ? 'sc_dt::sc_logic'
          : 'sc_dt::sc_lv<$width>';
  final omitted = _omittedOutputs;
  final source = StringBuffer()
    ..writeln(model.description
        .generateSystemC(className: coreName, options: options))
    ..writeln('SC_MODULE($className) {');
  for (final (ports, direction) in [
    (model.description.inputPorts, 'in'),
    (model.description.outputPorts, 'out')
  ]) {
    for (final port in ports.entries) {
      source.writeln(omitted.contains(port.key)
          ? '  sc_core::sc_signal<${type(port.key, port.value)}> '
              '${port.key}_unused{"${port.key}_unused"};'
          : '  sc_core::sc_$direction<${type(port.key, port.value)}> '
              '${_portName(port.key)}{"${_portName(port.key)}"};');
    }
  }
  source.writeln('  $coreName core{"core"};\n  SC_CTOR($className) {');
  for (final port in [
    ...model.description.inputPorts.keys,
    ...model.description.outputPorts.keys
  ]) {
    source.writeln(omitted.contains(port)
        ? '    core.$port(${port}_unused);'
        : '    core.$port(${_portName(port)});');
  }
  source.writeln('  }\n};');
  return source.toString();
}