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 | /**
* 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
* Fill Flat Example
* @section
* C Level Examples
* @description
* C implementation of the fillflat Userware.
* This example script demonstrates how to fill flat data
* compiled as a shared library in the starsh.
* @files
* zdb/fillflat.c
* zdb/fillflat.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/zosmem.h"
#include "zos/zerror.h"
#include "zdb/zdb.h"
#include "zdb/zflat.h"
#include "zdb/tzdb.h"
#include "zdb/zdbinitstub.h"
static zBool fillflat(DB* db, const char* fname);
/* ===========================================================================
* Declare prototypes.
* ===========================================================================
*/
#ifdef _MSC_VER
__declspec(dllexport)
#endif
int Fillflat_Init(Tcl_Interp* interp);
/**
* ============================================================================
* MASTER COMMAND
*
* COMMAND: fillflat $db $flatdatafname
* 0 1 2
* ============================================================================
*/
static int fillflatCmd(ClientData data, Tcl_Interp* interp, int objc,
Tcl_Obj* CONST objv[])
{
const char* dbName;
const char* fname;
zBool ok = zTrue;
DB* zdb;
(void) data; /* Pacify 'unused variable' warning. */
if (objc != 3) {
Tcl_WrongNumArgs(interp, 1, objv, "$db $fname");
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;
}
fname = Tcl_GetString(objv[2]);
ok = fillflat(zdb, fname);
if (!ok) {
Tcl_SetResult(interp, zGetError(), TCL_VOLATILE);
}
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 fillflat(DB* db, const char* fname) {
FILE* fp = NULL;
char** argv = NULL;
int argc;
char line[1024];
FAttr fattrs[3];
int fattrCnt = 0;
/**
* open text file
*/
fp = fopen(fname, "r");
if (!fp) {
zPrintError("problem with opening '%s", fname);
goto error;
}
/**
* init attr array.
*/
fattrs[fattrCnt].name = "@width";
fattrs[fattrCnt].nlen = zStrlen("@width");
fattrs[fattrCnt].value = NULL;
fattrCnt++;
fattrs[fattrCnt].name = "@style";
fattrs[fattrCnt].nlen = zStrlen("@style");
fattrs[fattrCnt].value = NULL;
fattrCnt++;
fattrs[fattrCnt].name = "@color";
fattrs[fattrCnt].nlen = zStrlen("@color");
fattrs[fattrCnt].value = NULL;
fattrCnt++;
/**
* read line by line
*/
while (fgets(line, sizeof(line), fp)) {
int len = zStrlen(line);
/**
* ignore newline character.
*/
if (len && (line[len-1] == '\n')) {
line[len-1] = '\0';
}
/**
* split arguments in tcl format:
* value
* type (net, netBus, pin, pinBus, port, portBus, signal or inst)
* name of top module
* path with instance names (0 .. n)
* name of object
*/
argv = zSplitTclList(line, &argc, 0);
if (argc > 3) {
const char* valStr0 = argv[0];
const char* valStr1 = argv[1];
const char* valStr2 = argv[2];
const char* type = argv[3];
const char* topName = argv[4];
char** path = argv+5;
int pathLen = argc-6;
const char* name = argv[argc-1];
Module* top;
struct FTopNode* topNode = NULL;
struct FNode* rootNode = NULL;
struct FNode* node = NULL;
int p;
/**
* search module in top
*/
top = zSearchTopModule(db, topName, zFalse, zTrue);
if (!top) {
goto error;
}
topNode = zFlatMakeTopNode(db, top, 0);
if (!topNode) {
goto error;
}
rootNode = zFlatGetRootNode(db, topNode, 0);
if (!rootNode) {
goto error;
}
/**
* create path nodes.
*/
node = rootNode;
for (p = 0; p < pathLen; p++) {
node = zFlatMakeInstNode(db, topNode, node, path[p]);
if (!node) {
goto error;
}
}
/**
* create object node.
*/
if (zStrcmp(type, "net") == 0) {
node = zFlatMakeNetNode(db, topNode, node, name);
} else if (zStrcmp(type, "netBus") == 0) {
node = zFlatMakeNetBusNode(db, topNode, node, name);
} else if (zStrcmp(type, "pin") == 0) {
node = zFlatMakePinNode(db, topNode, node, name);
} else if (zStrcmp(type, "pinBus") == 0) {
node = zFlatMakePinBusNode(db, topNode, node, name);
} else if (zStrcmp(type, "port") == 0) {
node = zFlatNewPortNode(db, topNode, node, name);
} else if (zStrcmp(type, "portBus") == 0) {
node = zFlatNewPortBusNode(db, topNode, node, name);
} else if (zStrcmp(type, "signal") == 0) {
node = zFlatMakeSignalNode(db, topNode, node, name);
} else if (zStrcmp(type, "inst") == 0) {
node = zFlatMakeInstNode(db, topNode, node, name);
} else {
zPrintError("wrong type %s", type);
goto error;
}
if (!node) {
goto error;
}
/**
* Set attributes at flat object.
*/
fattrs[0].value = valStr0;
fattrs[1].value = valStr1;
fattrs[2].value = valStr2;
if (!zFlatNodeSetAttrs(db, topNode, node, fattrs, fattrCnt)) {
goto error;
}
}
/**
* free tcl arg vector.
*/
zFree(argv);
}
return zTrue;
error:
zFree(argv);
if (fp) {
fclose(fp);
}
return zFalse;
}
/**
* ============================================================================
* Init Function - Create command "fillflat"
* ============================================================================
*/
#ifdef _MSC_VER
__declspec(dllexport)
#endif
int Fillflat_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, "fillflat init (zdb): ", buf, NULL);
return TCL_ERROR;
}
if (!zZlicenseOEMInitStub(zlicOEMstub, buf, sizeof(buf))) {
Tcl_AppendResult(interp, "fillflat init (licenseOEM): ", buf, NULL);
return TCL_ERROR;
}
if (!ce_Ce_utilitiesInitStub(ce_utilstub, buf, sizeof(buf))) {
Tcl_AppendResult(interp, "fillflat init (ce_utilities): ", buf, NULL);
return TCL_ERROR;
}
if (Tcl_PkgProvide(interp, "Fillflat", "1.0") != TCL_OK) {
return TCL_ERROR;
}
Tcl_CreateObjCommand(interp, "fillflat", &fillflatCmd, NULL, NULL);
return TCL_OK;
}
|