/[ascend]/trunk/ascend/compiler/simlist.c
ViewVC logotype

Contents of /trunk/ascend/compiler/simlist.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2336 - (show annotations) (download) (as text)
Sun Dec 26 03:44:24 2010 UTC (11 years, 6 months ago) by jpye
File MIME type: text/x-csrc
File size: 5616 byte(s)
Suppress some debug output.
In mtx_vector, initialise some members of mtx_vector class, because otherwise they trigger valgrind errors.
1 /* ASCEND modelling environment
2 Copyright (C) 1997 Benjamin Andrew Allan
3 Copyright 1997, Carnegie Mellon University
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later 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; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 *//**
20 @file
21 This module initializes manages a global list simulations,
22 which may be interrelated in very twisty ways due to UNIVERSAL and
23 parameter passing.
24 *//*
25 by Ben Allan
26 by Kirk Abbott and Ben Allan
27 Last in CVS: $Revision: 1.3 $ $Date: 1997/07/18 12:34:53 $ $Author: mthomas $
28 */
29
30 #include <ascend/general/platform.h>
31
32 #include "instance_enum.h"
33 #include "destroyinst.h"
34 #include "simlist.h"
35 #include "instquery.h"
36 #include "expr_types.h"
37 #include "symtab.h"
38 #include "extinst.h"
39 #include "cmpfunc.h"
40 #include "instantiate.h"
41
42 #include <ascend/general/list.h>
43 #include <ascend/general/tm_time.h>
44
45 struct gl_list_t *g_simulation_list = NULL;
46
47 void sim_destroy(struct Instance *sim){
48 if (sim) {
49 #ifdef SIMLIST_DEBUG
50 CONSOLE_DEBUG("Destroying instance %s", SCP(GetSimulationName(sim)) );
51 #endif
52 DestroyInstance(sim,NULL);
53 }
54 }
55
56
57 void Asc_DestroySimulations(void){
58 if (g_simulation_list) {
59 gl_iterate(g_simulation_list,(void (*)(VOIDPTR))sim_destroy);
60 gl_destroy(g_simulation_list); /* sim_destroy takes care of the
61 * memory -- see SimsProc.c */
62 g_simulation_list = NULL;
63 }else{
64 CONSOLE_DEBUG("g_simulation_list is null");
65 }
66 }
67
68 int g_compiler_timing=0;
69
70 #define MAXIMUM_INST_NAME 256
71
72 /*
73 * unheadered stuff from instantiate.c
74 * changed g_cursim to extern -- JP
75 */
76 extern struct Instance *g_cursim;
77 struct gl_list_t *ArrayIndices(struct Name *name, struct Instance *parent);
78
79 void Asc_SetCurrentSim(struct Instance *sim)
80 {
81 g_cursim = sim;
82 return;
83 }
84
85 struct Instance *Asc_GetCurrentSim()
86 {
87 return g_cursim;
88 }
89
90 int Asc_SimsUniqueName(symchar *str)
91 {
92 unsigned long c;
93 struct Instance *ptr;
94 for(c=gl_length(g_simulation_list);c>=1;c--) {
95 ptr = (struct Instance *)gl_fetch(g_simulation_list,c);
96 if (GetSimulationName(ptr) == str) {
97 return 0;
98 }
99 }
100 return 1;
101 }
102
103 /*
104 *
105 */
106 int Asc_SimsCmpSim(struct Instance *sim1, struct Instance *sim2)
107 {
108 assert(sim1&&sim2);
109 return CmpSymchar(GetSimulationName(sim1),GetSimulationName(sim2));
110 }
111
112 /*
113 * Find the simulation list entry to a named simulation. Return
114 * null if no simulation of that name found. Sims are inserted sorted
115 * so we should do a gl_search here.
116 */
117 struct Instance *Asc_FindSimulationTop(symchar *str)
118 {
119 unsigned long len,c;
120 struct Instance *ptr;
121
122 len = gl_length(g_simulation_list);
123 for (c=len;c>=1;c--) {
124 ptr = (struct Instance *)gl_fetch(g_simulation_list,c);
125 if (GetSimulationName(ptr) == str) {
126 return ptr;
127 }
128 }
129 return NULL;
130 }
131
132
133 /*
134 * This function setups up to call instantiate with different
135 * compiler settings. In all cases Instantiate will make a copy of
136 * the name that is given. format should perhaps be an array of enums
137 * or a bit structure to deal with multiple compilation flags. At the moment
138 * it is just an int.
139 */
140 struct Instance *SimsCreateInstance(symchar *type,
141 symchar *name,
142 enum CreateInst_format format,
143 symchar *defmethod)
144 {
145 struct Instance *result;
146 unsigned int oldflags;
147 double comptime;
148
149 if ((NULL == type) ||(NULL == name)) {
150 return NULL;
151 }
152 g_ExtVariablesTable = NULL; /* defined in extinst.[ch] */
153 comptime = tm_cpu_time();
154 switch (format) {
155 case e_normal:
156 result = Instantiate(type,name,0,defmethod);
157 break;
158 case e_no_relations:
159 oldflags = GetInstantiationRelnFlags();
160 SetInstantiationRelnFlags(NORELS);
161 result = Instantiate(type,name,0,defmethod);
162 SetInstantiationRelnFlags(oldflags);
163 break;
164 case e_patch:
165 result = InstantiatePatch(type,name,0);
166 break;
167 default:
168 FPRINTF(stderr,"Warning: doing standard compilation\n");
169 result = Instantiate(type,name,0,defmethod);
170 break;
171 }
172 comptime = tm_cpu_time() - comptime;
173 if (g_compiler_timing) {
174 FPRINTF(stderr,"Instantiation CPU time = %g seconds\n",comptime);
175 }
176 return result;
177 }
178
179
180 /*
181 * This function searches the simulation list for
182 * the *root* instance of the simulation.
183 */
184 struct Instance *Asc_FindSimulationRoot(symchar *str)
185 {
186 unsigned long c,len;
187 struct Instance *ptr;
188
189 len = gl_length(g_simulation_list);
190 for (c = len; c >= 1; c--) {
191 ptr = (struct Instance *)gl_fetch(g_simulation_list,c);
192 if (GetSimulationName(ptr) == str) {
193 return GetSimulationRoot(ptr);
194 }
195 }
196 return NULL;
197 }
198
199 symchar *Asc_SimsFindSimulationName(CONST struct Instance *root)
200 {
201 unsigned long len,c;
202 struct Instance *ptr;
203
204 if (!root) {
205 return NULL;
206 }
207 len = gl_length(g_simulation_list);
208 for(c=len;c>=1;c--) {
209 ptr = (struct Instance *)gl_fetch(g_simulation_list,c);
210 if (GetSimulationRoot(ptr)==root) {
211 return GetSimulationName(ptr);
212 }
213 }
214 return NULL;
215 }
216

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22