1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380 | /**
* Copyright (c) 2006-2024 by Altair Engineering, Inc.
* All rights reserved.
*
* Altair Engineering, Inc. makes this software available as part of the Vision
* tool platform. As long as you are a licensee of the Vision tool platform
* you may make copies of the software and modify it to be used within the
* Vision tool platform, but you must include all of this notice on any copy.
* Redistribution without written permission to any third party, with or
* without modification, is not permitted.
* Altair Engineering, Inc. does not warrant that this software is error free
* or fit for any purpose. Altair Engineering, Inc. disclaims any liability for
* all claims, expenses, losses, damages and costs any user may incur as a
* result of using, copying or modifying the software.
* ============================================================================
* @c-code
* Floating Nodes Example
* @section
* C Level Examples
* @description
* C implementation of the floatingNodes Userware.
* This example script demonstrates how to use the userware extension
* compiled as a shared library in the *Vision GUI as well as in the
* starsh.
* @files
* zdb/userware.c
* zdb/userware.tcl
* @tag
* spice zdb
*/
#define USE_TCL_STUBS
#include <tcl.h>
/**
* There is an issue with the Tcl_SetResult() stubs prototype in tcl-8.6.14.
*/
#if (TCL_MAJOR_VERSION == 8) && \
(TCL_MINOR_VERSION == 6) && \
(TCL_RELEASE_SERIAL == 14)
#undef Tcl_SetResult
#define Tcl_SetResult ((void (*)(Tcl_Interp *, char *, Tcl_FreeProc *)) \
(tclStubsPtr->tcl_SetResult))
#endif
#define USE_UTIL_STUBS
#define USE_ZDB_STUBS
#define USE_CE_UTILITIES_STUBS
#include "util/zlicenseOEM.h"
#include "util/zlicenseOEMinitstub.h"
#include "ce_utilities/ce_File.h"
#include "ce_utilities/ce_utilitiesinitstub.h"
#include "zos/zos.h"
#include "zos/zerror.h"
#include "zdb/zdb.h"
#include "zdb/zflat.h"
#include "zdb/tzdb.h"
#include "zdb/zdbinitstub.h"
static zBool floatingNodes (DB* db, OID** resultList);
static zBool flatfloatNodes(DB* db, OID** resultList);
/* ===========================================================================
* Declare prototypes.
* ===========================================================================
*/
#ifdef _MSC_VER
__declspec(dllexport)
#endif
int Userware_Init(Tcl_Interp* interp);
/**
* ============================================================================
* MASTER COMMAND
*
* COMMAND: userware $db floatingNodes ?-flat?
* 0 1 2 3
* ============================================================================
*/
static int userwareCmd(ClientData data, Tcl_Interp* interp, int objc,
Tcl_Obj* CONST objv[])
{
static CONST84 char* subCmds[] = {"floatingNodes", NULL};
const char* dbName;
int index;
int flat = 0;
int r, rlen;
zBool ok = zTrue;
DB* zdb;
OID* resultList = NULL;
Tcl_Obj *result = Tcl_GetObjResult(interp);
(void) data; /* Pacify 'unused variable' warning. */
if (objc < 3 || objc > 4) {
Tcl_WrongNumArgs(interp, 1, objv, "$db floatingNodes ?-flat?");
return TCL_ERROR;
}
dbName = Tcl_GetString(objv[1]);
if (zStringIsEqual(dbName, "")) {
/* empty db has empty result */
return TCL_OK;
}
zdb = zT_GetDbFromName(interp, dbName);
if (zdb == NULL) {
zT_ErrorSetResult(interp, "$db", objv[1], zGetError());
return TCL_ERROR;
}
if (objc == 4 && zStringIsEqual(Tcl_GetString(objv[3]), "-flat")) {
flat = 1;
}
if (Tcl_GetIndexFromObj(interp, objv[2], subCmds,
"option", TCL_EXACT, &index) == TCL_ERROR)
{
return TCL_ERROR;
}
zArrayAlloc(&resultList, 32);
switch (index) {
case 0: /* floatingNodes ?-flat? */
if (flat) {
ok = flatfloatNodes(zdb, &resultList);
} else {
ok = floatingNodes (zdb, &resultList);
}
break;
default:
zAssert(0);
break;
}
if (!ok) {
Tcl_SetResult(interp, zGetError(), TCL_VOLATILE);
}
rlen = ARRAYLEN(resultList);
for (r=0; r < rlen; r++) {
if (ok) {
Tcl_Obj* theObj = Tcl_NewObj();
zT_SetOIDObj(zdb, theObj, resultList+r);
if (Tcl_ListObjAppendElement(interp, result, theObj) != TCL_OK) {
ok = zFalse;
}
}
zOID_unref(resultList+r);
}
zArrayFree(resultList);
return ok ? TCL_OK : TCL_ERROR;
}
/**
* ============================================================================
* The floatingNodes function loops over all modules and count the number
* of pins for each net. Power/Ground nets are skipped. All nets
* with exactly one pin are stored in the resultList.
* ============================================================================
*/
static zBool floatingNodes(DB* db, OID** resultList) {
int nMod = LISTLEN(db->cellList);
int m;
int n;
/**
* Try to checkout feature.
*/
if (!zLicenseCheckoutFeature("Userware_Demo")) {
return zFalse;
}
/**
* Loop over all nets in all modules
*/
for (m = 0; m < nMod; m++) {
Cell* cell = db->cellList[m];
Module* module;
if (!zCellIsModule(cell)) {
continue;
}
module = (Module*)cell;
for (n = 0; n < LISTLEN(module->netList); n++) {
Net* net = module->netList[n];
int nPin = LISTLEN(net->pinRefList);
/* skip power, ground and negpower nets */
if (net->flags & NetFPower) {
continue;
}
if (net->flags & NetFGround) {
continue;
}
if (net->flags & NetFNegPower) {
continue;
}
if (nPin == 1) {
OID oid;
zOID_setType(&oid, OidNet);
oid.flags = OidFNone;
oid.p.module = module;
oid.o.net = net;
zOID_ref(&oid);
zArrayAppend(resultList, &oid);
}
}
}
return zTrue;
}
/**
* ============================================================================
* The flatfloatNodes function loops over all signals and count the number
* of pins for each signal. Power/Ground nets are skipped. All signals
* with exactly one pin are stored in the resultList.
* ============================================================================
*/
static int countPinCB(void* signalPinCntCtx, const struct OID* oid) {
int* cnt = (int*)signalPinCntCtx;
(void)oid; /* Pacify 'unused variable' warning. */
(*cnt)++;
if (*cnt > 1) {
return 1; /* break */
}
return 0;
}
struct FloatSignalCtx {
DB* db;
OID** resultList;
};
static int checkFloatSignalCB(void* foreachCtx, const OID* sigOID){
struct FloatSignalCtx* ctx = (struct FloatSignalCtx*)foreachCtx;
int cnt = 0;
int ret = zFlatForeachPin(ctx->db, sigOID, zFalse, zFalse, zFalse, zFalse,
countPinCB, &cnt);
if (ret == -1) {
return -1;
}
/* skip power, ground and negpower nets */
if (sigOID->o.net->flags & NetFPower) {
return 0;
}
if (sigOID->o.net->flags & NetFGround) {
return 0;
}
if (sigOID->o.net->flags & NetFNegPower) {
return 0;
}
/* skip multiple instantiations of this net */
if (sigOID->o.net->flags & NetFYellow) {
return 0;
}
sigOID->o.net->flags |= NetFYellow;
if (cnt == 1) {
zOID_ref(sigOID);
zArrayAppend(ctx->resultList, sigOID);
}
return 0;
}
struct FloatCtx {
DB* db;
OID** resultList;
};
static zBool flatfloatNodes(DB* db, OID** resultList) {
int nMod = LISTLEN(db->cellList);
int m;
OID top;
struct FloatCtx ctx;
zOID_setType(&top, OidModule);
top.flags = 0;
top.p.module = db->topList[0];
/* clear the "yellow" flag (used to skip multiple instantiations) */
for (m = 0; m < nMod; m++) {
int n;
Cell* cell = db->cellList[m];
Module* module;
if (!zCellIsModule(cell)) {
continue;
}
module = (Module*)cell;
for (n = 0; n < LISTLEN(module->netList); n++) {
Net* net = module->netList[n];
net->flags &= ~NetFYellow;
}
}
ctx.db = db;
ctx.resultList = resultList;
zFlatForeachSignal(db, &top, zFalse, zTrue, zFalse,
checkFloatSignalCB, &ctx);
return zTrue;
}
/**
* ============================================================================
* Init Function - Create command "userware"
* ============================================================================
*/
#ifdef _MSC_VER
__declspec(dllexport)
#endif
int Userware_Init(Tcl_Interp* interp) {
char buf[128];
void* zdbstub = NULL;
void* zlicOEMstub = NULL;
void* ce_utilstub = NULL;
ClientData* d = (ClientData*)&zdbstub;
ClientData* l = (ClientData*)&zlicOEMstub;
ClientData* u = (ClientData*)&ce_utilstub;
if (Tcl_InitStubs(interp, "8.6", 0) == NULL) {
return TCL_ERROR;
}
if (Tcl_PkgRequire(interp, "Tcl", "8.6", 0) == NULL) {
return TCL_ERROR;
}
if (Tcl_PkgRequire(interp, "Zos", "1.0", 0) == NULL) {
return TCL_ERROR;
}
if (Tcl_PkgRequireEx(interp, "Zdb", "1.0", 0, d) == NULL) {
return TCL_ERROR;
}
if (Tcl_PkgRequireEx(interp, "ZLicenseOEM", "1.0", 0, l) == NULL) {
return TCL_ERROR;
}
if (Tcl_PkgRequireEx(interp, "CE_Utilities", "1.0", 0, u) == NULL) {
return TCL_ERROR;
}
if (!zZdbInitStub(zdbstub, buf, sizeof(buf))) {
Tcl_AppendResult(interp, "userware init (zdb): ", buf, NULL);
return TCL_ERROR;
}
if (!zZlicenseOEMInitStub(zlicOEMstub, buf, sizeof(buf))) {
Tcl_AppendResult(interp, "userware init (licenseOEM): ", buf, NULL);
return TCL_ERROR;
}
if (!ce_Ce_utilitiesInitStub(ce_utilstub, buf, sizeof(buf))) {
Tcl_AppendResult(interp, "userware init (ce_utilities): ", buf, NULL);
return TCL_ERROR;
}
if (Tcl_PkgProvide(interp, "Userware", "1.0") != TCL_OK) {
return TCL_ERROR;
}
Tcl_CreateObjCommand(interp, "userware", &userwareCmd, NULL, NULL);
return TCL_OK;
}
|