clash-compiler
clash-compiler copied to clipboard
Allow rich error messages in `clashCompileError` for simulation
Clash.Magic.clashCompileError
only works if the argument is a literal string. But sometimes I want to provide a richer error message, for example I want to write this function:
ascii :: Char -> Word8
ascii c
| code <= 0x7f = fromIntegral code
| otherwise = clashCompileError (printf "Not an ASCII code point: %s (0x%08x)" (show c) code)
where
code = ord c
Now, of course this doesn't work at compile time. But it could work in simulation! So I propose a "two-level" clashCompileError
: taking a static string (as a type parameter, perhaps?) and a runtime string, and using the former during compilation and the latter during simulation:
| otherwise = clashCompileError @"Not an ASCII code point" $ printf "Not an ASCII code point: %s (0x%08x)" (show c) code