llvm/circt

[MooreToCore] Support format strings

fabianschuiki opened this issue · 1 comments

Lower the moore.fmt.* string formatting operations to the corresponding ops in the Sim dialect. The Sim dialect ops might need additional width, alignment, and padding arguments.

The following might be a useful test (taken from sv-tests):

module {
  moore.module @top() {
    %0 = moore.constant 90 : i8
    %p1 = moore.variable : <struct<{lo: i4, hi: i4}>>
    moore.procedure initial {
      %1 = moore.conversion %0 : !moore.i8 -> !moore.struct<{lo: i4, hi: i4}>
      moore.blocking_assign %p1, %1 : struct<{lo: i4, hi: i4}>
      %2 = moore.fmt.literal ":assert: ('"
      %3 = moore.read %p1 : <struct<{lo: i4, hi: i4}>>
      %4 = moore.conversion %3 : !moore.struct<{lo: i4, hi: i4}> -> !moore.i8
      %5 = moore.fmt.int hex_lower %4, width 2, align right, pad zero : i8
      %6 = moore.fmt.literal "' == '5a')"
      %7 = moore.fmt.literal "\0A"
      %8 = moore.fmt.concat (%2, %5, %6, %7)
      moore.builtin.display %8
      %9 = moore.fmt.literal ":assert: (('"
      %10 = moore.read %p1 : <struct<{lo: i4, hi: i4}>>
      %11 = moore.struct_extract %10, "hi" : struct<{lo: i4, hi: i4}> -> i4
      %12 = moore.fmt.int hex_lower %11, width 1, align right, pad zero : i4
      %13 = moore.fmt.literal "' == 'a') and ('"
      %14 = moore.struct_extract %10, "lo" : struct<{lo: i4, hi: i4}> -> i4
      %15 = moore.fmt.int hex_lower %14, width 1, align right, pad zero : i4
      %16 = moore.fmt.literal "' == '5'))"
      %17 = moore.fmt.concat (%9, %12, %13, %15, %16, %7)
      moore.builtin.display %17
      moore.return
    }
    moore.output
  }
}

Fixed in #7694.