Index: trunk/src/libcschem/abstract.c =================================================================== --- trunk/src/libcschem/abstract.c (revision 694) +++ trunk/src/libcschem/abstract.c (revision 695) @@ -37,6 +37,7 @@ { memset(abs, 0, sizeof(csch_abstract_t)); htsp_init(&abs->nets, strhash, strkeyeq); + htsp_init(&abs->comps, strhash, strkeyeq); } /* Initialize an object by setting the common header fields; the only purpose @@ -63,7 +64,22 @@ return net; } +csch_acomp_t *csch_acomp_get(csch_abstract_t *abs, const char *name, int alloc) +{ + csch_acomp_t *comp; + comp = htsp_get(&abs->comps, name); + if ((comp != NULL) || (!alloc)) + return comp; + + comp = calloc(sizeof(csch_acomp_t), 1); + csch_aobj_init(&comp->hdr, CSCH_ATYPE_COMP); + comp->name = csch_strdup(name); + htsp_set(&abs->comps, comp->name, comp); + return comp; +} + + static void dump_attr(const csch_attribs_t *attr, FILE *f, const char *prefix1, const char *prefix2) { htsp_entry_t *e; @@ -84,4 +100,11 @@ fprintf(f, "%s %s\n", prefix, net->netname); dump_attr(&net->hdr.attr, f, prefix, " "); } + + fprintf(f, "%sComponents:\n", prefix); + for(e = htsp_first(&abs->comps); e != NULL; e = htsp_next(&abs->comps, e)) { + csch_acomp_t *comp = e->value; + fprintf(f, "%s %s\n", prefix, comp->name); + dump_attr(&comp->hdr.attr, f, prefix, " "); + } } Index: trunk/src/libcschem/abstract.h =================================================================== --- trunk/src/libcschem/abstract.h (revision 694) +++ trunk/src/libcschem/abstract.h (revision 695) @@ -40,7 +40,8 @@ htip_t id2obj; /* id -> object pointer (primary storage) */ htul_t uid2id; /* UID -> object id (cache) */ htsl_t net2id; /* (global) net name -> net object ID */ - htsp_t nets; /* netname -> csch_anet_s */ + htsp_t nets; /* netname -> csch_anet_t */ + htsp_t comps; /* name -> csch_acomp_t */ csch_oid_t next_id; } csch_abstract_t; @@ -110,6 +111,7 @@ /* type = CSCH_ATYPE_COMP */ struct csch_acomp_s { csch_ahdr_t hdr; + char *name; htsp_t ports; /* of csch_aport_t, key is ->name */ htsp_t busports; /* of csch_abusport_t, key is ->name */ }; @@ -127,4 +129,7 @@ /*** net ***/ csch_anet_t *csch_anet_get(csch_abstract_t *abs, const char *netname, int alloc); +/*** component ***/ +csch_acomp_t *csch_acomp_get(csch_abstract_t *abs, const char *name, int alloc); + #endif Index: trunk/src/libcschem/compile.c =================================================================== --- trunk/src/libcschem/compile.c (revision 694) +++ trunk/src/libcschem/compile.c (revision 695) @@ -75,6 +75,28 @@ return compile_attributes(&net->hdr, &src->hdr.attr); } +static int compile_symbol(csch_abstract_t *dst, const csch_sheet_t *sheet, const csch_cgrp_t *src) +{ + char tmpname[128]; + const char *name; + const csch_attrib_t *aname; + csch_acomp_t *comp; + + aname = csch_attrib_get(&src->hdr.attr, "name"); + if ((aname == NULL) || (aname->key == NULL) || (*aname->key == '\0')) { +#warning TODO: needs better naming + sprintf(tmpname, "anon_%p", src); + name = tmpname; + } + else + name = aname->key; + + comp = csch_acomp_get(dst, name, 1); + if (comp == NULL) + return -1; + return compile_attributes(&comp->hdr, &src->hdr.attr); +} + int csch_compile_sheet(csch_abstract_t *dst, const csch_sheet_t *src) { int res = 0; @@ -86,6 +108,7 @@ continue; #warning TODO: use an enum... if (strcmp(grp->role, "wire-net") == 0) res |= compile_wire_net(dst, src, grp); + if (strcmp(grp->role, "symbol") == 0) res |= compile_symbol(dst, src, grp); } return res;