@@ -32,6 +32,7 @@ import GHC.Stack (HasCallStack)
3232
3333import Clash.Backend
3434 (Backend , hdlTypeErrValue , expr , blockDecl )
35+ import Clash.Core.TermInfo (isVar )
3536import Clash.Core.Type
3637 (Type (LitTy ), LitTy (NumTy ), coreView )
3738import Clash.Netlist.BlackBox (isLiteral )
@@ -241,21 +242,21 @@ foldTF' args =
241242 error $ " Unexpected number of arguments: " ++ show (length (bbInputs args))
242243
243244indexIntVerilog :: BlackBoxFunction
244- indexIntVerilog _isD _primName args _ty = return ((meta,) <$> bb)
245+ indexIntVerilog _isD _primName args _ty = return bb
245246 where
246- meta = emptyBlackBoxMeta{bbKind= bbKi}
247-
248- bbKi = case args of
249- [_nTy,_aTy,_kn,_v,Left ix]
250- | isLiteral ix -> TExpr
251- _ -> TDecl
247+ meta bbKi = emptyBlackBoxMeta{bbKind= bbKi}
252248
253249 bb = case args of
250+ [_nTy,_aTy,_kn,Left v,Left ix] | isLiteral ix && isVar v ->
251+ Right (meta TExpr , BBFunction " Clash.Primitives.Sized.Vector.indexIntVerilogTF" 0 indexIntVerilogTF)
254252 [_nTy,_aTy,_kn,_v,Left ix] | isLiteral ix ->
255- Right (BBFunction " Clash.Primitives.Sized.Vector.indexIntVerilogTF" 0 indexIntVerilogTF)
253+ case runParse (pack (I. unindent bbTextLitIx)) of
254+ Success t -> Right (meta TDecl , BBTemplate t)
255+ _ -> Left " internal error: parse fail"
256+
256257 _ ->
257- BBTemplate <$> case runParse (pack (I. unindent bbText)) of
258- Success t -> Right t
258+ case runParse (pack (I. unindent bbText)) of
259+ Success t -> Right (meta TDecl , BBTemplate t)
259260 _ -> Left " internal error: parse fail"
260261
261262 bbText = [I. i |
@@ -270,6 +271,12 @@ indexIntVerilog _isD _primName args _ty = return ((meta,) <$> bb)
270271 assign ~RESULT = ~SYM[0][~ARG[2]];~ELSEassign ~RESULT = ~ERRORO;~FI
271272 // index end|]
272273
274+ bbTextLitIx = [I. i |
275+ // index lit begin
276+ ~IF~SIZE[~TYP[1]]~THENassign ~RESULT = ~VAR[vec][1][~SIZE[~TYP[1]]-1-~LIT[2]*~SIZE[~TYPO] -: ~SIZE[~TYPO]];~ELSEassign ~RESULT = ~ERRORO;~FI
277+ // index lit end|]
278+
279+
273280indexIntVerilogTF :: TemplateFunction
274281indexIntVerilogTF = TemplateFunction used valid indexIntVerilogTemplate
275282 where
0 commit comments