@@ -101,6 +101,20 @@ let compSlot_ (compSlotName:CompSlotName) : Optics.Lens<Component, int> =
101101 | Input1 ( busWidth, _) -> busWidth
102102 | Output busWidth -> busWidth
103103 | _ -> failwithf $" Invalid component {comp.Type} for IO"
104+ | SplitNWidth idx ->
105+ match comp.Type with
106+ | SplitN (_, widths, _) ->
107+ if idx >= 0 && idx < List.length widths then
108+ widths[ idx]
109+ else failwithf $" SplitNWidth index %d {idx} out of range"
110+ | _ -> failwithf $" Invalid component {comp.Type} for SplitNWidth"
111+ | SplitNLSB idx ->
112+ match comp.Type with
113+ | SplitN (_, _, lsbs) ->
114+ if idx >= 0 && idx < List.length lsbs then
115+ lsbs[ idx]
116+ else failwithf $" SplitNLSB index %d {idx} out of range"
117+ | _ -> failwithf $" Invalid component {comp.Type} for SplitNLSB"
104118 | CustomCompParam paramName ->
105119 match comp.Type with
106120 | Custom customComp ->
@@ -152,6 +166,20 @@ let compSlot_ (compSlotName:CompSlotName) : Optics.Lens<Component, int> =
152166 | Input1 (_, defaultValue) -> Input1 ( value, defaultValue)
153167 | Output _ -> Output value
154168 | _ -> failwithf $" Invalid component {comp.Type} for IO"
169+ | SplitNWidth idx ->
170+ match comp.Type with
171+ | SplitN ( n, widths, lsbs) ->
172+ if idx < 0 || idx >= List.length widths then failwithf $" SplitNWidth index %d {idx} out of range"
173+ let newWidths = widths |> List.mapi ( fun i w -> if i = idx then value else w)
174+ SplitN ( n, newWidths, lsbs)
175+ | _ -> failwithf $" Invalid component {comp.Type} for SplitNWidth"
176+ | SplitNLSB idx ->
177+ match comp.Type with
178+ | SplitN ( n, widths, lsbs) ->
179+ if idx < 0 || idx >= List.length lsbs then failwithf $" SplitNLSB index %d {idx} out of range"
180+ let newLsbs = lsbs |> List.mapi ( fun i l -> if i = idx then value else l)
181+ SplitN ( n, widths, newLsbs)
182+ | _ -> failwithf $" Invalid component {comp.Type} for SplitNLSB"
155183 | CustomCompParam paramName ->
156184 match comp.Type with
157185 | Custom customComp ->
@@ -232,8 +260,8 @@ let evaluateConstraints
232260 else Error result
233261
234262
235- /// Generates a ParameterExpression from input text
236- /// Operators are left-associative
263+ // Generates a ParameterExpression from input text
264+ // Operators are left-associative
237265// parseExpression has been moved to ParameterTypes module
238266
239267
@@ -306,6 +334,20 @@ let updateComponent dispatch model slot value =
306334 match comp.Type with
307335 | GateN ( gateType, _) -> model.Sheet.ChangeGate sheetDispatch compId gateType value
308336 | _ -> failwithf $" Gate cannot have type {comp.Type}"
337+ | SplitNWidth idx ->
338+ match comp.Type with
339+ | SplitN ( n, widths, lsbs) ->
340+ if idx < 0 || idx >= List.length widths then failwithf $" SplitNWidth index %d {idx} out of range"
341+ let newWidths = widths |> List.mapi ( fun i w -> if i = idx then value else w)
342+ model.Sheet.ChangeSplitN sheetDispatch compId n newWidths lsbs
343+ | _ -> failwithf $" SplitNWidth cannot be applied to {comp.Type}"
344+ | SplitNLSB idx ->
345+ match comp.Type with
346+ | SplitN ( n, widths, lsbs) ->
347+ if idx < 0 || idx >= List.length lsbs then failwithf $" SplitNLSB index %d {idx} out of range"
348+ let newLsbs = lsbs |> List.mapi ( fun i l -> if i = idx then value else l)
349+ model.Sheet.ChangeSplitN sheetDispatch compId n widths newLsbs
350+ | _ -> failwithf $" SplitNLSB cannot be applied to {comp.Type}"
309351 | CustomCompParam paramName ->
310352 // For custom component parameters, we need to update the parameter bindings
311353 match comp.Type with
@@ -885,7 +927,19 @@ let resolveParametersForComponent
885927 | Buswidth -> currentType |> ( evaluatedValue ^= buswidthPrism)
886928 | NGateInputs -> currentType |> ( evaluatedValue ^= ngateInputsPrism)
887929 | IO _ -> currentType |> ( evaluatedValue ^= ioPortPrism)
888- | _ -> currentType
930+ | SplitNWidth idx ->
931+ match currentType with
932+ | SplitN ( n, widths, lsbs) when idx >= 0 && idx < List.length widths ->
933+ let newWidths = widths |> List.mapi ( fun i w -> if i = idx then evaluatedValue else w)
934+ SplitN ( n, newWidths, lsbs)
935+ | _ -> currentType
936+ | SplitNLSB idx ->
937+ match currentType with
938+ | SplitN ( n, widths, lsbs) when idx >= 0 && idx < List.length lsbs ->
939+ let newLsbs = lsbs |> List.mapi ( fun i l -> if i = idx then evaluatedValue else l)
940+ SplitN ( n, widths, newLsbs)
941+ | _ -> currentType
942+ | CustomCompParam _ -> currentType
889943 ( newType, None)
890944 | Error err -> ( currentType, Some err)
891945 )
@@ -1127,6 +1181,8 @@ let private makeSlotsField (model: ModelType.Model) (comp:LoadedComponent) dispa
11271181 | Buswidth -> " Buswidth"
11281182 | NGateInputs -> " Num inputs"
11291183 | IO label -> $" Input/output {label}"
1184+ | SplitNWidth idx -> $" SplitN output {idx} width"
1185+ | SplitNLSB idx -> $" SplitN output {idx} LSB"
11301186 | CustomCompParam paramName -> $" Custom parameter {paramName}"
11311187
11321188 let name = if Map.containsKey ( ComponentId slot.CompId) model.Sheet.Wire.Symbol.Symbols then
0 commit comments