Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / tas / stm / stm_modfct_eval.c
1 /****************************************************************************/
2 /* */
3 /* Chaine de CAO & VLSI AVERTEC */
4 /* */
5 /* Produit : STM Version 1.00 */
6 /* Fichier : stm_modfct_eval.c */
7 /* */
8 /* (c) copyright 2000 AVERTEC */
9 /* Tous droits reserves */
10 /* */
11 /* Auteur(s) : Gilles Augustins */
12 /* */
13 /****************************************************************************/
14
15 /****************************************************************************/
16 /* includes */
17 /****************************************************************************/
18
19 #include "stm.h"
20 #include GEN_H
21
22 /****************************************************************************/
23 /* functions */
24 /****************************************************************************/
25
26 ExecutionContext *STM_EC = NULL;
27
28 ExecutionContext *Get_stm_C_context ()
29 {
30 lib_entry *le;
31 char path[200], lib[200], *str;
32 if (STM_EC != NULL)
33 return STM_EC;
34
35 APIInit ();
36 STM_EC = APINewExecutionContext ();
37
38 str = V_STR_TAB[__GENIUS_LIB_PATH].VALUE;
39 if (str == NULL)
40 strcpy (lib, "cells");
41 else
42 strcpy (lib, str);
43
44 sprintf (path, "%s/%s/", WORK_LIB, lib);
45
46 str = V_STR_TAB[__GENIUS_LIB_NAME].VALUE;
47 if (str == NULL)
48 sprintf (lib, "%sLIBRARY", path);
49 else
50 sprintf (lib, "%s%s", path, str);
51
52 le = APIReadLibrary (lib, path, NULL);
53 if (ReadAllCorVHDL (STM_EC, le, NULL)) {
54 printf ("stmfct could not read rule files\n");
55 EXIT (3);
56 }
57 // call user init function
58 {
59 APICallFunc cf;
60 t_arg *ret;
61 cf.NAME="GnsInit";
62 cf.ARGS=NULL;
63 if (APIExecAPICallFunc(STM_EC, &cf, &ret, 1)==0)
64 APIFreeTARG(ret);
65 }
66
67 APIFreeLibrary (le);
68 return STM_EC;
69 }
70
71 /*
72 ht *ALL_FCT_FILES=NULL;
73
74 ExecutionContext *Get_stm_C_context(char *file)
75 {
76 long l;
77 ExecutionContext *ec;
78 FILE *f;
79 char *name;
80 tree_list *tr;
81
82 if (ALL_FCT_FILES==NULL) ALL_FCT_FILES=addht(10);
83
84 name=sensitive_namealloc(file);
85 if ((l=gethtitem(ALL_FCT_FILES, name))!=EMPTYHT) return (ExecutionContext *)l;
86
87 if (!(f = mbkfopen (name, NULL, READ_TEXT))) {
88 fprintf (stderr, "Cannot open file '%s'\n", name);
89 return NULL;
90 }
91
92 APIInit ();
93 ec = APINewExecutionContext ();
94 tr = APIParseFile (f, name, ec);
95 APIVerify_C_Functions (ec);
96 if (APICheckCFunctions (ec)) { fclose(f); return NULL;}
97 addhtitem(ALL_FCT_FILES, name, (long)ec);
98 fclose(f);
99 return ec;
100 }
101
102 void Free_stm_C_context()
103 {
104 chain_list *cl, *ch;
105
106 cl=GetAllHTElems(ALL_FCT_FILES);
107
108 for (ch=cl; ch!=NULL; ch=ch->NEXT)
109 APIFreeExecutionContext ((ExecutionContext *)ch->DATA);
110
111 freechain(cl);
112
113 delht(ALL_FCT_FILES);
114 ALL_FCT_FILES=NULL;
115 }
116 */
117
118 static double __STM_DELAY__, __STM_INPUT_SLOPE__, __STM_COMMAND_SLOPE__;
119 static double __STM_SLOPE__, __STM_OUTPUT_LOAD__;
120 static timing_function *__STM_ARC__=NULL;
121
122
123 timing_function *stm_get_current_arc()
124 {
125 return __STM_ARC__;
126 }
127
128 void stm_set_current_arc(timing_function *arc)
129 {
130 __STM_ARC__=arc;
131 }
132
133 void stm_set_computed_delay (double value)
134 {
135 __STM_DELAY__ = value;
136 }
137
138 void stm_set_computed_slope (double value)
139 {
140 __STM_SLOPE__ = value;
141 }
142
143 double stm_get_computed_delay ()
144 {
145 return __STM_DELAY__;
146 }
147
148 double stm_get_computed_slope ()
149 {
150 return __STM_SLOPE__;
151 }
152
153 double stm_get_output_load ()
154 {
155 return __STM_OUTPUT_LOAD__;
156 }
157
158 double stm_get_input_slope ()
159 {
160 return __STM_INPUT_SLOPE__;
161 }
162
163 double stm_get_command_slope ()
164 {
165 return __STM_COMMAND_SLOPE__;
166 }
167
168 void stm_set_output_load (double val)
169 {
170 __STM_OUTPUT_LOAD__ = val;
171 }
172
173 void stm_set_input_slope (double val)
174 {
175 __STM_INPUT_SLOPE__ = val;
176 }
177
178 void stm_set_command_slope (double val)
179 {
180 __STM_COMMAND_SLOPE__ = val;
181 }
182
183 void stm_call_simulation()
184 {
185 timing_function *tf;
186 HierLofigInfo *hli;
187 t_arg *ta;
188 ArcInfo *ai;
189 if ((tf=stm_get_current_arc())==NULL)
190 {
191 avt_errmsg (STM_ERRMSG, "042", AVT_ERROR);
192 return;
193 }
194 hli=gethierlofiginfo(CUR_HIER_LOFIG);
195 ai=getarcinfo(hli, tf->LOCALNAME);
196 if (ai->SIM==NULL)
197 {
198 avt_errmsg (STM_ERRMSG, "043", AVT_ERROR, CUR_HIER_LOFIG, tf->LOCALNAME);
199 return;
200 }
201 if (APIExecAPICallFunc (Get_stm_C_context (), ai->SIM, &ta, 0)) EXIT (1);
202 APIFreeTARG (ta);
203 }
204
205 void stm_call_simulation_env()
206 {
207 timing_function *tf;
208 HierLofigInfo *hli;
209 t_arg *ta;
210 ArcInfo *ai;
211 if ((tf=stm_get_current_arc())==NULL)
212 {
213 avt_errmsg (STM_ERRMSG, "044", AVT_ERROR);
214 return;
215 }
216 hli=gethierlofiginfo(CUR_HIER_LOFIG);
217 ai=getarcinfo(hli, tf->LOCALNAME);
218 if (ai->ENV==NULL)
219 {
220 avt_errmsg (STM_ERRMSG, "045", AVT_ERROR, CUR_HIER_LOFIG, tf->LOCALNAME);
221 return;
222 }
223 if (APIExecAPICallFunc (Get_stm_C_context (), ai->ENV, &ta, 0)) EXIT (1);
224 APIFreeTARG (ta);
225 }
226
227 void stm_call_ctk_env()
228 {
229 timing_function *tf;
230 HierLofigInfo *hli;
231 t_arg *ta;
232 ArcInfo *ai;
233 if ((tf=stm_get_current_arc())==NULL)
234 {
235 avt_errmsg (STM_ERRMSG, "046", AVT_ERROR);
236 return;
237 }
238 hli=gethierlofiginfo(CUR_HIER_LOFIG);
239 ai=getarcinfo(hli, tf->LOCALNAME);
240 if (ai->CTK_ENV==NULL)
241 {
242 avt_errmsg (STM_ERRMSG, "047", AVT_ERROR, tf->LOCALNAME);
243 return;
244 }
245 if (APIExecAPICallFunc (Get_stm_C_context (), ai->CTK_ENV, &ta, 0)) EXIT (1);
246 APIFreeTARG (ta);
247 }
248
249 /****************************************************************************/
250 /* function stm_modfct_slew() */
251 /****************************************************************************/
252
253 float stm_modfct_slew (timing_function * fct, float slew, float load)
254 {
255 subinst_t *sins;
256
257 if (!fct || !fct->FCT)
258 return 0.0;
259
260 //printf ("stmfct SLEW recompute request instance = '%s' slope = %g load = %g\n", fct->INS, slew, load);
261 if (LATEST_GNS_RUN==NULL)
262 {
263 avt_errmsg (STM_ERRMSG, "048", AVT_ERROR);
264 return 1e-12;
265 }
266 sins = gen_get_hier_instance (LATEST_GNS_RUN, fct->INS);
267 if (!sins) {
268 avt_errmsg (STM_ERRMSG, "049", AVT_ERROR, fct->INS);
269 return 0.0;
270 }
271
272 in_genius_context_of (LATEST_GNS_RUN, sins);
273 APICallApiInitFunctions();
274 stm_set_input_slope (slew * 1e-12);
275 stm_set_output_load (load * 1e-15);
276 stm_set_current_arc(fct);
277 stm_call_func (Get_stm_C_context (), fct);
278 stm_set_current_arc(NULL);
279 APICallApiTerminateFunctions();
280 out_genius_context_of ();
281 /*
282 if ( stm_get_computed_slope ()>10000e-12)
283 {
284 printf("big slope returned : %g\n",stm_get_computed_slope());
285 EXIT(89);
286 }
287 */
288 return stm_get_computed_slope () * 1e12;
289 }
290
291 /****************************************************************************/
292 /* function stm_call_func () */
293 /****************************************************************************/
294
295 void stm_call_func (ExecutionContext * ec, timing_function * fct)
296 {
297 t_arg *ta;
298 if (APIExecAPICallFunc (ec, fct->FCT, &ta, 0))
299 EXIT (1);
300 APIFreeTARG (ta);
301 }
302
303 /****************************************************************************/
304 /* function stm_modfct_delay () */
305 /****************************************************************************/
306
307 float stm_modfct_delay (timing_function * fct, float slew, float load)
308 {
309 subinst_t *sins;
310
311 if (!fct || !fct->FCT)
312 return 0.0;
313
314 //printf ("stmfct DELAY recompute request instance = '%s' slope = %g load = %g\n", fct->INS, slew, load);
315 if (LATEST_GNS_RUN==NULL)
316 {
317 avt_errmsg (STM_ERRMSG, "048", AVT_ERROR);
318 return 0;
319 }
320 sins = gen_get_hier_instance (LATEST_GNS_RUN, fct->INS);
321 if (!sins) {
322 avt_errmsg (STM_ERRMSG, "049", AVT_ERROR, fct->INS);
323 return 0.0;
324 }
325
326 in_genius_context_of (LATEST_GNS_RUN, sins);
327 APICallApiInitFunctions();
328 stm_set_input_slope (slew * 1e-12);
329 stm_set_output_load (load * 1e-15);
330 stm_set_current_arc(fct);
331 stm_call_func (Get_stm_C_context (), fct);
332 stm_set_current_arc(NULL); // pour etre sur de voir une erreur hors context
333 APICallApiTerminateFunctions();
334 out_genius_context_of ();
335 /*
336 if ( stm_get_computed_delay ()>10000e-12)
337 {
338 printf("big delay returned : %g\n",stm_get_computed_delay());
339 EXIT(88);
340 }
341 */
342 return stm_get_computed_delay () * 1e12;
343 }
344
345 /****************************************************************************/
346 /* function stm_modfct_constraint() */
347 /****************************************************************************/
348
349 float stm_modfct_constraint (timing_function * fct, float inslew, float ckslew)
350 {
351 subinst_t *sins;
352
353 if (!fct || !fct->FCT)
354 return 0.0;
355
356 // printf ("stmfct CONSTRAINT recompute request instance = '%s' inslope = %g comslope = %g\n", fct->INS, inslew, ckslew);
357 if (LATEST_GNS_RUN==NULL)
358 {
359 avt_error("stm", 1, AVT_ERR, "Gns informations not loaded, can't compute constraint\n");
360 return 0;
361 }
362 sins = gen_get_hier_instance (LATEST_GNS_RUN, fct->INS);
363 if (!sins) {
364 avt_errmsg (STM_ERRMSG, "049", AVT_ERROR, fct->INS);
365 return 0.0;
366 }
367
368 in_genius_context_of (LATEST_GNS_RUN, sins);
369 APICallApiInitFunctions();
370 stm_set_input_slope (inslew * 1e-12);
371 stm_set_command_slope (ckslew * 1e-15);
372 stm_set_current_arc(fct);
373 stm_call_func (Get_stm_C_context (), fct);
374 stm_set_current_arc(NULL); // pour etre sur de voir une erreur hors context
375 APICallApiTerminateFunctions();
376 out_genius_context_of ();
377
378 return stm_get_computed_delay () * 1e12;
379 }