Skip to content

Commit

Permalink
Compile Prim nodes into Hugr DFG
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Oct 4, 2024
1 parent 2a86b70 commit 1eb8be4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions brat/Brat/Compile/Hugr.hs
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,18 @@ compileWithInputs parent name = gets compiled <&> M.lookup name >>= \case
-- This should only have one outgoing wire which leads to an `Id` node for
-- the brat representation of the function, and that wire should have a
-- function type
Prim _ -> error $ "TODO: Compiling a Prim node being used as a thunk, not directly Evaled."
++ " Should construct trivial 4-node DFG+I/O+CustomOp Hugr."
Prim (ext,op) -> do
let n = ext ++ ('_':op)
let [] = ins
let [(_, VFun Braty cty)] = outs
box_sig@(FunctionType inputTys outputTys) <- body <$> compileSig Braty cty
((p, _ty), ()) <- compileConstDfg parent n box_sig $ \dfg_id -> do
ins <- addNodeWithInputs ("Inputs" ++ n) (OpIn (InputNode dfg_id inputTys)) [] inputTys
outs <- addNodeWithInputs n (OpCustom (CustomOp dfg_id ext op box_sig [])) ins outputTys
addNodeWithInputs ("Outputs" ++ n) (OpOut (OutputNode dfg_id outputTys)) outs [] >>= \case
[] -> pure ()
case p of
(Port loadConst 0) -> pure $ default_edges loadConst

-- Check if the node has prefix "globals", hence should be a direct call
Eval (Ex outNode outPort) -> do
Expand Down

0 comments on commit 1eb8be4

Please sign in to comment.