Skip to content

Annotate attributes for types must be in normal form #1742

Description

@thoughtpolice

Consider the following attempt to abstract out an unwieldly use of Annotate into an easy-to-use Pin type:

import           Clash.Prelude
import           Clash.Signal

import           Clash.Annotations.SynthesisAttributes
import           Clash.Annotations.TopEntity
import           Clash.Annotations.TH

createDomain vSystem{vName="Bank2C", vPeriod=20000, vResetKind=Asynchronous, vResetPolarity=ActiveLow}

type Pin t x y = t `Annotate` 'StringAttr "chip_pin" x
                   `Annotate` 'StringAttr "altera_attribute" ("-name IO_STANDARD \"" `AppendSymbol` y `AppendSymbol` "\"")

top :: HiddenClockResetEnable dom => Signal dom (BitVector 4)
top = s where s = register 0 (s + 1)

topEntity
  :: "CLK_50_B2C"  ::: Pin (Clock Bank2C) "PIN_AW38" "1.2 V"
  -> "CPU_RESET_n" ::: Signal Bank2C Bool
  -> "LED"         ::: Signal Bank2C (BitVector 4)
topEntity clk rstnButton = exposeClockResetEnable top clk rst en where
  en = enableGen
  rst = unsafeFromLowPolarity rstnButton
  rstSync = resetSynchronizer clk rst en
makeTopEntityWithName 'topEntity "shell"

Using the tip of the 1.4 branch, I get:

$ clash --verilog DE10Pro
GHC: Parsing and optimising modules took: 1.584s
GHC: Loading external modules from interface files took: 0.000s
GHC: Parsing annotations took: 0.000s
Clash: Parsing and compiling primitives took 0.147s

<no location info>: error:
    Clash error call:
    Could not unpack given type to string: AppendSymbol (AppendSymbol "-name IO_STANDARD \"" "1.2 V") "\""
    CallStack (from HasCallStack):
      error, called at src-ghc/Clash/GHC/GHC2Core.hs:775:19 in clash-ghc-1.4.0-DkSmlpJFpg8Ad9ypRSNVx8:Clash.GHC.GHC2Core

I don't see why this can't be supported; it seems that the evaluator merely assumes that the string type is already in normal form, which isn't the case here. My actual goal is to use closed type families to write a more sophisticated version of Pin, but the basic idea here is all the same.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions