@@ -4,22 +4,9 @@ import invariant from "tiny-invariant";
44import type { Opaque } from "type-fest" ;
55import type CCStore from "." ;
66import type { CCComponentId } from "./component" ;
7- import {
8- aggregate ,
9- and ,
10- broadcast ,
11- decompose ,
12- false_ ,
13- flipflop ,
14- input ,
15- not ,
16- or ,
17- output ,
18- true_ ,
19- xor ,
20- } from "./intrinsics/definitions" ;
7+ import { IntrinsicComponentDefinition } from "./intrinsics/base" ;
8+ import { aggregate , decompose , input , output } from "./intrinsics/definitions" ;
219import type { CCNodePinId } from "./nodePin" ;
22- // import { IntrinsicComponentDefinition } from "./intrinsics/base";
2310
2411export type CCComponentPin = {
2512 readonly id : CCComponentPinId ;
@@ -228,71 +215,51 @@ export class CCComponentPinStore extends EventEmitter<CCComponentPinStoreEvents>
228215 const pin = this . #pins. get ( pinId ) ;
229216 invariant ( pin ) ;
230217
231- // const intrinsicPinAttributes =
232- // IntrinsicComponentDefinition.getPinAttributesByPinId(pin.id);
233- // if (intrinsicPinAttributes) {
234- // if (intrinsicPinAttributes.bitWidthPolicy.type === "inferred")
235- // return { isFixed: false, fixMode: "automatic" };
236- // if (intrinsicPinAttributes.bitWidthPolicy.type === "configurable")
237- // return { isFixed: false, fixMode: "manual" };
238- // if (intrinsicPinAttributes.bitWidthPolicy.type === "fixed") {
239- // const definition = nullthrows(IntrinsicComponentDefinition.getByComponentId(pin.componentId));
240- // }
241- // throw new Error(`Unknown bit width policy: ${intrinsicPinAttributes.bitWidthPolicy}`);
242- // }
243-
244- // TODO: Remove hardcoded intrinsic component pin IDs and replace with a more flexible system, such as metadata on the component definitions.
245- switch ( pin . id ) {
246- case nullthrows ( and . inputPin . A . id ) :
247- case nullthrows ( and . inputPin . B . id ) :
248- case nullthrows ( and . outputPin . Out . id ) :
249- case nullthrows ( or . inputPin . A . id ) :
250- case nullthrows ( or . inputPin . B . id ) :
251- case nullthrows ( or . outputPin . Out . id ) :
252- case nullthrows ( not . inputPin . In . id ) :
253- case nullthrows ( not . outputPin . Out . id ) :
254- case nullthrows ( xor . inputPin . A . id ) :
255- case nullthrows ( xor . inputPin . B . id ) :
256- case nullthrows ( xor . outputPin . Out . id ) :
257- case nullthrows ( input . outputPin . Out . id ) :
258- case nullthrows ( output . inputPin . In . id ) :
259- case nullthrows ( flipflop . inputPin . In . id ) :
260- case nullthrows ( flipflop . outputPin . Out . id ) :
261- case nullthrows ( true_ . outputPin . Out . id ) :
262- case nullthrows ( false_ . outputPin . Out . id ) : {
263- return { isFixed : false , fixMode : "automatic" } ;
264- }
265- case nullthrows ( aggregate . inputPin . In . id ) : {
218+ // Intrinsic components
219+ const intrinsicPinAttributes =
220+ IntrinsicComponentDefinition . getPinAttributesByPinId ( pin . id ) ;
221+ if ( intrinsicPinAttributes ) {
222+ // TODO: This is a temporary workaround to allow the bit width of aggregate and decompose pins to be calculated outside of the normal inference process.
223+ // We should eventually refactor the bit width inference process to handle these cases more elegantly.
224+ if ( pin . id === aggregate . outputPin . Out . id )
266225 return { isFixed : false , fixMode : "manual" } ;
267- }
268- case nullthrows ( aggregate . outputPin . Out . id ) : {
226+ if ( pin . id === decompose . inputPin . In . id )
269227 return { isFixed : false , fixMode : "manual" } ;
270- }
271- case nullthrows ( decompose . outputPin . Out . id ) : {
272- return { isFixed : false , fixMode : "manual" } ;
273- }
274- case nullthrows ( decompose . inputPin . In . id ) : {
275- return { isFixed : false , fixMode : "manual" } ;
276- }
277- case nullthrows ( broadcast . inputPin . In . id ) : {
278- return { isFixed : true , bitWidth : 1 } ;
279- }
280- case nullthrows ( broadcast . outputPin . Out . id ) : {
228+
229+ if ( intrinsicPinAttributes . bitWidthPolicy . type === "inferred" )
230+ return { isFixed : false , fixMode : "automatic" } ;
231+ if ( intrinsicPinAttributes . bitWidthPolicy . type === "configurable" )
281232 return { isFixed : false , fixMode : "manual" } ;
282- }
283- default : {
284- if ( pin . implementation === null ) {
285- throw new Error ( "unreachable" ) ;
286- }
287- const bitWidthStatus = this . #store. nodePins . getNodePinBitWidthStatus (
288- pin . implementation ,
233+ if ( intrinsicPinAttributes . bitWidthPolicy . type === "fixed" ) {
234+ const definition = nullthrows (
235+ IntrinsicComponentDefinition . getByComponentId ( pin . componentId ) ,
236+ `Intrinsic component definition not found for component ID: ${ pin . componentId } ` ,
289237 ) ;
290- if ( bitWidthStatus . isFixed ) {
291- return bitWidthStatus ;
292- } else {
293- return { isFixed : false , fixMode : "automatic" } ;
294- }
238+ return {
239+ isFixed : true ,
240+ bitWidth : intrinsicPinAttributes . bitWidthPolicy . calculateBitWidth (
241+ definition . initialConfig ,
242+ { } ,
243+ ) ,
244+ } ;
295245 }
246+ throw new Error (
247+ `Unknown bit width policy: ${ intrinsicPinAttributes . bitWidthPolicy satisfies never } ` ,
248+ ) ;
249+ }
250+
251+ // User-defined components
252+ invariant (
253+ pin . implementation ,
254+ "Pin implementation must be defined for user-defined components" ,
255+ ) ;
256+ const bitWidthStatus = this . #store. nodePins . getNodePinBitWidthStatus (
257+ pin . implementation ,
258+ ) ;
259+ if ( bitWidthStatus . isFixed ) {
260+ return bitWidthStatus ;
261+ } else {
262+ return { isFixed : false , fixMode : "automatic" } ;
296263 }
297264 }
298265
0 commit comments