@@ -15,7 +15,7 @@ import {
1515 or ,
1616 xor ,
1717} from "./intrinsics/definitions" ;
18- import type { CCNodePinId } from "./nodePin" ;
18+ import type { CCNodePin , CCNodePinId } from "./nodePin" ;
1919
2020export type CCComponentPin = {
2121 readonly id : CCComponentPinId ;
@@ -47,7 +47,11 @@ export type CCPinImplementation = CCNodePinId | null;
4747
4848export type CCPinMultiplexability =
4949 | { isMultiplexable : true }
50- | { isMultiplexable : false ; multiplicity : number } ;
50+ | {
51+ isMultiplexable : false ;
52+ getMultiplicity : ( nodePins : CCNodePin [ ] ) => number ;
53+ } ;
54+ // | { isMultiplexable: false; multiplicity: number };
5155
5256export type CCComponentPinMultiplexability =
5357 | CCPinMultiplexability
@@ -264,16 +268,52 @@ export class CCComponentPinStore extends EventEmitter<CCComponentPinStoreEvents>
264268 return "undecidable" ;
265269 }
266270 case nullthrows ( aggregate . outputPin . id ) : {
267- return "undecidable" ;
271+ const getMultiplicity = ( nodePins : CCNodePin [ ] ) : number => {
272+ const multiplicity = nodePins
273+ . filter ( ( pin ) => {
274+ const componentPin = this . #store. componentPins . get (
275+ pin . componentPinId ,
276+ ) ;
277+ invariant ( componentPin ) ;
278+ return componentPin . type === "input" ;
279+ } )
280+ . reduce ( ( acc , pin ) => {
281+ invariant ( pin . userSpecifiedBitWidth ) ;
282+ return acc + pin . userSpecifiedBitWidth ;
283+ } , 0 ) ;
284+ return multiplicity ;
285+ } ;
286+ return {
287+ isMultiplexable : false ,
288+ getMultiplicity,
289+ } ;
268290 }
269291 case nullthrows ( decompose . outputPin . id ) : {
270292 return "undecidable" ;
271293 }
272294 case nullthrows ( decompose . inputPin . In . id ) : {
273- return "undecidable" ;
295+ const getMultiplicity = ( nodePins : CCNodePin [ ] ) : number => {
296+ const multiplicity = nodePins
297+ . filter ( ( pin ) => {
298+ const componentPin = this . #store. componentPins . get (
299+ pin . componentPinId ,
300+ ) ;
301+ invariant ( componentPin ) ;
302+ return componentPin . type === "output" ;
303+ } )
304+ . reduce ( ( acc , pin ) => {
305+ invariant ( pin . userSpecifiedBitWidth ) ;
306+ return acc + pin . userSpecifiedBitWidth ;
307+ } , 0 ) ;
308+ return multiplicity ;
309+ } ;
310+ return {
311+ isMultiplexable : false ,
312+ getMultiplicity,
313+ } ;
274314 }
275315 case nullthrows ( broadcast . inputPin . In . id ) : {
276- return { isMultiplexable : false , multiplicity : 1 } ;
316+ return { isMultiplexable : false , getMultiplicity : ( ) => 1 } ;
277317 }
278318 case nullthrows ( broadcast . outputPin . id ) : {
279319 return "undecidable" ;
0 commit comments