1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 ****************************************************************************/
18 #ifndef __module_h
19 #define __module_h
20 
21 #define MSP_STEPSIZE	8
22 
23 /*
24  * Port position types
25  */
26 #define PPT_FIXED	0		/* Fixed port positions */
27 #define PPT_SCALED	1		/* Scaled port positions */
28 
29 #define MT_NETLIST	0		/* Module is a netlist */
30 #define MT_TEXTHDL	1		/* Module is textual HDL */
31 
32 /*****************************************************************************
33  *
34  * Simulation time in epochs.
35  *
36  *****************************************************************************/
37 typedef unsigned long long simtime_t;
38 
39 /*****************************************************************************
40  *
41  * Module timescale
42  *
43  *****************************************************************************/
44 typedef struct {
45   simtime_t	ts_units;
46   simtime_t	ts_precision;
47 } Timescale;
48 
49 
50 /*****************************************************************************
51  *
52  * GModuleDef - Data structure for specifying a functional block definition.
53  *
54  *****************************************************************************/
55 typedef struct GModuleDef_str {
56   char		*m_name;		/* Module name */
57   char		*m_fileName;		/* Name of file in which module was defined */
58   char		*m_libName;		/* Name of library (if applicable) */
59   unsigned	m_type;			/* Module type */
60   int		m_lineno;		/* Base line number for HDL modules */
61 
62   /*
63    * Module interface data
64    */
65   unsigned	m_pptype;		/* Port position type */
66   GCElement	*m_interface;		/* Module interface */
67   GCElement	*m_altInterface;	/* Alternate interface (symbol if m_interface is block and vice versa) */
68 
69   /*
70    * Declared module parameter ports and their default values
71    */
72   SHash		*m_parmPorts;		/* Table of parameter ports and default values */
73 
74   /*
75    * Module property flags
76    */
77   unsigned	m_used : 1;		/* Mark to see if used in circuit */
78   unsigned	m_isLib : 1;		/* This is a library module */
79   unsigned	m_isModload : 1;	/* Has this module been changed since loading */
80   unsigned	m_isModsave : 1;	/* Has this module been changed since last save */
81   unsigned	m_protData : 1;		/* Module data is read-only */
82   unsigned	m_protIntf : 1;		/* Module interface is read-only  */
83   unsigned	m_protEdit : 1;		/* Module interface is protected in edit mode. */
84   unsigned	m_hidden : 1;		/* Internal data is "hidden" (i.e., can not be opened) */
85   unsigned	m_isSpecial : 1;	/* This is a "special" module (i.e., cut buffer, interface list, etc.) */
86 
87   /*
88    * These members are used for netlist modules.
89    */
90   GWireList	*m_wires;		/* Wires in module */
91   SHash		*m_gates;		/* Table of gates in module */
92   SHash		*m_nets;		/* Table of nets in module */
93 
94   /*
95    * These members are used for text RTL modules.
96    */
97   char		*m_text;		/* Textual module description */
98   int		m_textSize;		/* Size of buffer allocated for m_text */
99   int		m_curLine;		/* Current line number in text buffer */
100   int		m_curChar;		/* Current char number in text buffer */
101   int		m_needScan;		/* Module needs to be rescanned */
102 } GModuleDef;
103 
104 int block_getPortDir(GCElement *g,GWire *w);
105 int block_getPad(GCElement *g,GWire *w);
106 void block_scalewirelist(GWire *w,GCElement *g,int isY,int portsFixed);
107 void block_movewirelist(GWire *w,int x,int y);
108 void block_name(GCElement *g,EditState *es);
109 void block_namefunction(GCElement *g,EditState *es);
110 int block_in(int x,int y,GCElement *g);
111 int block_setPortName(GCElement *g,GWire *w,EditState *es);
112 void block_getwirexy(GWire *w,int d,int *x,int *y,int *p);
113 void block_free(GCElement *g);
114 void block_explode(GCElement *g);
115 int block_connect(GCElement *g,GWireNode *n,int Dir);
116 GWire *block_addwire(GWire *w,GWire *wl);
117 void block_changefunction(EditState *es,GCElement *g);
118 void block_changename(EditState *es,GCElement *g);
119 void block_deletewire(GWire *w);
120 void block_newport(EditState *es,int iodir);
121 void block_changedir(GWireNode *n,EditState *es);
122 void block_setdir(GWireNode *n,EditState *es,int);
123 int block_attach(GModuleDef *env,GCElement *g,GWire *w1,GWire *w2,
124 	     int x,int y,const char *name,int Dir);
125 int block_edgehit(GCElement *g,int x,int y);
126 GCElement *block_replicate(GCElement *g,GModuleDef *M,int x,int y);
127 void block_canonicalizewire(GCElement *g,GWire *w);
128 int block_insidep(const char *n,EditState *es);
129 char *block_reportname(GCElement *g);
130 int block_isDataProtected(GCElement *g);
131 int block_isIntfProtected(GCElement *g);
132 int block_isFixedPort(GCElement *g);
133 void block_resetAllWireEnds(GCElement *g);
134 void block_cutoffwire(GWire *w,EditState *es);
135 
136 void modint_flush();
137 void modint_reset(EditState *es,GCElement *g);
138 int modint_setInterface(GModuleDef *M,GCElement *g);
139 void modint_arrange(EditState *es);
140 void modint_update(EditState *es);
141 void modint_edit(EditState **es,GModuleDef *M);
142 GCElement *modint_findDisplay(const char*);
143 GCElement *modint_find(const char *name);
144 GCElement *modint_findInAlt(const char *name);
145 void modint_deleteInterface(GModuleDef *);
146 void modint_renameInterface(GModuleDef *);
147 void modint_syncDisplay(GModuleDef*);
148 void modint_makeSymbolInterface(GModuleDef *M,GModSymbol *ms);
149 void modint_openSelected(const char *modName);
150 void modint_close();
151 void modint_center();
152 
153 GModuleDef *new_GModuleDef(const char *name);
154 void delete_GModuleDef(GModuleDef *M);
155 
156 GNet *GModuleDef_findNet(GModuleDef *M,const char *name);
157 GCElement *GModuleDef_findGate(GModuleDef *M,const char *name);
158 void GModuleDef_getBBX(GModuleDef *M,TargetDev_e target, int *minX,int *maxX,int *minY,int *maxY);
159 void GModuleDef_copyInto(GModuleDef *D,GModuleDef *S,int dx,int dy,int selOnly,int selDst);
160 void GModuleDef_copy(GModuleDef *D,GModuleDef *S);
161 void GModuleDef_setLibrary(GModuleDef *M,const char *name);
162 void GModuleDef_setFileName(GModuleDef *M,const char *name);
163 void GModuleDef_claim(GModuleDef *M);
164 int GModuleDef_isDataProtected(GModuleDef *M);
165 int GModuleDef_isIntfProtected(GModuleDef *M);
166 void GModuleDef_flush(GModuleDef *M);
167 #define GModuleDef_getName(M) ((M)->m_name)
168 #define GModuleDef_getType(M) ((M)->m_type)
169 #define GModuleDef_isLibrary(M) ((M)->m_isLib)
170 #define GModuleDef_isTop(M) ((M) == TkGate.circuit->root_mod || (M) == TkGate.circuit->mid_mod)
171 int GModuleDef_hasSubModules(GModuleDef *M);
172 GModuleDef *GModuleDef_isRecursive(GModuleDef *M);
173 void GModuleDef_getPropsToTcl(GModuleDef *M, Tcl_Interp *tcl,char *aname);
174 void GModuleDef_setPropsFromTcl(GModuleDef *M, Tcl_Interp *tcl,char *aname);
175 int GModuleDef_scanHDLModule(GModuleDef *M);
176 void GModuleDef_saveText(GModuleDef *M,const char *text);
177 void GModuleDef_allocText(GModuleDef *M,int n);
178 int GModuleDef_numHdlLines(GModuleDef *M);
179 void GModuleDef_listNets(GModuleDef *mdef);
180 void GModuleDef_listPorts(GModuleDef *mdef);
181 GNet *GModuleDef_labelHit(GModuleDef *m,int x,int y);
182 int GModuleDef_grabLabel(GModuleDef *m,int x,int y,GrabbedLabel *gl);
183 
184 GCElement *SymBlock_convert(GCElement *g,GModSymbol *ms,GModuleDef *M,int doWires);
185 void SymBlock_remakePorts(GCElement *g,GModuleDef *M);
186 
187 void Block_EditParmProps(GCElement *g, int isLoadDialog);
188 void Block_VerSaveModParms(FILE *f,GCElement *g);
189 void Block_setParmPort(GCElement *g,const char *parmName,const char *newValue);
190 void Block_unsetParmPort(GCElement *g,const char *parmName);
191 const char *Block_getParmPort(GCElement *g,const char *name);
192 
193 #endif
194