1 /* "NETGEN", a netlist-specification tool for VLSI
2    Copyright (C) 1989, 1990   Massimo A. Sivilotti
3    Author's address: mass@csvax.cs.caltech.edu;
4                      Caltech 256-80, Pasadena CA 91125.
5 
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation (any version).
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; see the file copying.  If not, write to
17 the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
18 
19 /* ccode.c  -- Output routines to write a cell as NETGEN embedded C code */
20 
21 #include "config.h"
22 
23 #include <stdio.h>
24 #include <stdarg.h>
25 
26 #include "netgen.h"
27 #include "hash.h"
28 #include "objlist.h"
29 #include "netfile.h"
30 #include "print.h"
31 
ccodeCell(char * name)32 void ccodeCell(char *name)
33 {
34   struct nlist *tp, *tp2;
35   struct objlist *ob, *ob2;
36 
37   tp = LookupCell(name);
38   if (tp == NULL) {
39     Printf("No cell '%s' found.\n", name);
40     return;
41   }
42 
43   /* do NOT dump primitive cells */
44   if (tp->class != CLASS_SUBCKT) return;
45 
46   /* check to see that all children have been dumped */
47   for (ob = tp->cell; ob != NULL; ob = ob->next) {
48     tp2 = LookupCell(ob->model.class);
49     if ((tp2 != NULL) && !(tp2->dumped))
50       ccodeCell(tp2->name);
51   }
52 
53   /* print out header list */
54   FlushString("CellDef(\"%s\", -1);\n", tp->name);
55   for (ob = tp->cell; ob != NULL; ob = ob->next) {
56     switch (ob->type) {
57     case PORT: FlushString("   Port(\"%s\");\n", ob->name);
58       break;
59     case GLOBAL: FlushString("   Global(\"%s\");\n", ob->name);
60       break;
61     case UNIQUEGLOBAL: FlushString("   UniqueGlobal(\"%s\");\n", ob->name);
62       break;
63     default: break;
64     }
65   }
66 
67   /* now run through cell's contents, print instances */
68   for (ob = tp->cell; ob != NULL; ob = ob->next) {
69     if (ob->type == FIRSTPIN) {
70       /* this is an instance, so print out a cell */
71       FlushString("   Cell(\"%s\"", ob->model.class);
72       ob2 = ob;
73       do {
74 	FlushString(", \"%s\"", NodeAlias(tp, ob2));
75 	ob2 = ob2->next;
76       } while ((ob2 != NULL) && (ob2->type > FIRSTPIN));
77       FlushString(");\n");
78     }
79   }
80   FlushString ("EndDef();\n\n");
81   tp->dumped = 1;		/* set dumped flag */
82 }
83 
84 
Ccode(char * name,char * filename)85 void Ccode(char *name, char *filename)
86 {
87   char FileName[500];
88 
89   if (filename == NULL || strlen(filename) == 0)
90     SetExtension(FileName, name, CCODE_EXTENSION);
91   else
92     SetExtension(FileName, filename, CCODE_EXTENSION);
93 
94   if (!OpenFile(FileName, 80)) {
95     Printf("Unable to open CCODE file %s\n", FileName);
96     return;
97   }
98   ClearDumpedList();
99 
100   /* create top level call */
101   if (LookupCell(name) != NULL) {
102     FlushString("/* Cell: %s;  code generated by NETGEN */\n", name);
103     ccodeCell(name);
104   }
105 
106   CloseFile(FileName);
107 }
108 
109 
110 
111 
112