/[ascend]/trunk/base/generic/compiler/ascCompiler.c
ViewVC logotype

Contents of /trunk/base/generic/compiler/ascCompiler.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 669 - (show annotations) (download) (as text)
Wed Jun 21 07:00:45 2006 UTC (13 years, 2 months ago) by johnpye
File MIME type: text/x-csrc
File size: 8279 byte(s)
Merged changes from DAE branch (revisions 702 to 819) back into trunk.
This adds the Integration API to the ASCEND solver (in base/generic).
Also provides pre-alpha support for 'IDA' from the SUNDIALS suite, a DAE solver.
Many other minor code clean-ups, including adoption of new 'ASC_NEW' and friends (to replace 'ascmalloc')
Added some very sketchy stuff providing 'DIFF(...)' syntax, although it is anticipated that this will be removed.
1 /*
2 * Basic Initializations for Ascend
3 * by Ben Allan
4 * Version: $Revision: 1.20 $
5 * Version control file: $RCSfile: ascCompiler.c,v $
6 * Date last modified: $Date: 2000/01/25 02:25:57 $
7 * Last modified by: $Author: ballan $
8 * Part of Ascend
9 *
10 * This file is part of the Ascend Language Interpreter.
11 *
12 * Copyright (C) 1997 Benjamin Andrew Allan
13 *
14 * The Ascend Language Interpreter is free software; you can redistribute
15 * it and/or modify it under the terms of the GNU General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * The Ascend Language Interpreter is distributed in hope that it will be
20 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 * General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with the program; if not, write to the Free Software Foundation,
26 * Inc., 675 Mass Ave, Cambridge, MA 02139 USA. Check the file named
27 * COPYING.
28 *
29 * This module initializes the fundamental data structures used by the rest of
30 * Ascend and pulls in system headers. Largely this means memory management.
31 */
32 #include <utilities/ascConfig.h>
33 #include <utilities/ascMalloc.h>
34 #include <utilities/ascEnvVar.h>
35 #include "compiler.h"
36 #include "ascCompiler.h"
37 #include <utilities/ascSignal.h>
38 #include <utilities/ascPanic.h>
39 #include <general/list.h>
40 #include "fractions.h"
41 #include "dimen.h"
42 #include "expr_types.h"
43 #include "name.h"
44 #include "exprs.h"
45 #include "sets.h"
46 #include "stattypes.h"
47 #include "slist.h"
48 #include "evaluate.h"
49 #include "units.h"
50 #include "symtab.h"
51 #include "notate.h"
52 #include "module.h"
53 #include "child.h"
54 #include "type_desc.h"
55 #include "type_descio.h"
56 #include "proc.h"
57 #include "typedef.h"
58 #include "value_type.h"
59 #include "temp.h"
60 #include "instance_enum.h"
61 #include "parpend.h"
62 #include "dump.h"
63 #include "prototype.h"
64 #include "library.h"
65 #include "instance_name.h"
66 #include "instquery.h"
67 #include "forvars.h"
68 #include "setinstval.h"
69 #include <general/pool.h>
70 #include "arrayinst.h"
71 #include "relation_type.h"
72 #include "relation_io.h"
73 #include "extfunc.h"
74 #include "find.h"
75 #include "relation.h"
76 #include "logical_relation.h"
77 #include "logrelation.h"
78 #include "instantiate.h"
79 #include "universal.h"
80 #include "packages.h"
81 #include "pending.h"
82 #include "scanner.h"
83 #include "simlist.h"
84 #include "numlist.h"
85 #include "bintoken.h"
86 #include "childio.h"
87 #include "redirectFile.h"
88 #include "ascCompiler.h"
89
90 #ifndef lint
91 static CONST char ascCompilerID[] = "$Id: ascCompiler.c,v 1.20 2000/01/25 02:25:57 ballan Exp $";
92 #endif
93
94
95 /*
96 * this function is passed around by pointer in the compiler.
97 */
98 /*
99 * No longer necessary as being handled properly in instance.c. This
100 * function was necessary before for the following reasons:
101 * Let us assume that there as a simulation sim, and it had a root instance,
102 * root. If refine was called on sim->root, and the instance was moved in
103 * memory, we would be notified by this function, and so that if:
104 * sim->root == old, then sim->root = new. This was only necessary for
105 * sims, as they used to be treated *NOT* as instances and so sim->root had
106 * 0 parents, with all the associated implications.
107 * Now that simulations are proper SIM_INSTances, their root instance has
108 * at *least* 1 parent, (possibly more if they are UNIVERSAL !*), and the
109 * necessary fixing up is done within the code in instance.c.
110 *
111 * For the time being it is being left to see if it gets invoked.
112 */
113 static
114 void InterfaceNotifyProc(char *ptr, struct Instance *old, struct Instance *new)
115 {
116 UNUSED_PARAMETER(ptr);
117 UNUSED_PARAMETER(new);
118 (void)old;
119 #if 0 /* is, officially, no big deal. baa .*/
120 register unsigned long c,len;
121 register struct Instance *sptr;
122 len = gl_length(g_simulation_list);
123 for(c=len;c>=1;c--) {
124 sptr = (struct Instance *)gl_fetch(g_simulation_list,c);
125 if (GetSimulationRoot(sptr) == old) {
126 FPRINTF(stderr,
127 "Simulation %s has been relocated for your information.\n",
128 GetSimulationName(sptr));
129 FPRINTF(stderr,"If you see this message please report it to\n");
130 FPRINTF(stderr,"\t%s\n",ASC_BIG_BUGMAIL);
131 }
132 }
133 #endif
134 }
135
136 /*
137 * this function is passed around by pointer in the compiler.
138 */
139 /*
140 * We don't have a use for this yet. We are being protractive
141 * in that any objects that we are referencing directly get
142 * cleaned up *before* we call any routines that could
143 * potentially move an instance.
144 */
145 static
146 void InterfacePtrDeleteProc(struct Instance *i, char *ptr)
147 {
148 (void)i; /* stop gcc whine about unused parameter */
149 (void)ptr; /* stop gcc whine about unused parameter */
150 }
151
152
153 /* if this function returns nonzero, ascend cannot run and a ton
154 * of memory might be leaked while exiting.
155 */
156 int Asc_CompilerInit(int simp)
157 {
158
159 if (simp !=0){
160 g_simplify_relations = 1;
161 }
162 Asc_RedirectCompilerDefault();
163 /* Commenting out the call to gl_init will make the system slower but
164 * easier to debug for leaks.
165 * Move the close-comment to after gl_init if debugging.
166 * Please don't ever check in this file with gl_init commented out.
167 */
168 gl_init();
169 gl_init_pool();
170 Asc_SignalInit();
171 Asc_InitEnvironment(10);
172 name_init_pool();
173 exprs_init_pool();
174 ppe_init_pool();
175 sets_init_pool();
176 RelationIO_init_pool();
177 InitSetManager();
178 InitValueManager();
179 InitRelInstantiator();
180 InitLogRelInstantiator();
181 InitPendingPool();
182 InitInstanceNanny();
183
184 InitDimenList();
185 InitSymbolTable();
186 InitBaseTypeNames();
187 InitUnitsTable();
188 InitNotesDatabase(NULL);
189 InitNotesDatabase(LibraryNote());
190 InitNotesDatabase(GlobalNote());
191 InitExternalFuncLibrary(); /* initialize external func library */
192 AddUserFunctions(); /* add user packages */
193
194 InitDump();
195 InitializePrototype();
196 /* FPRINTF(ASCERR,"...PROTO INIT\n"); */
197 InitializeLibrary();
198 /* FPRINTF(ASCERR,"...LIBRARY INIT\n"); */
199 SetUniversalTable(CreateUniversalTable());
200 /* FPRINTF(ASCERR,"...UNIV TABLE INIT\n"); */
201 DefineFundamentalTypes();
202 /* FPRINTF(ASCERR,"...FUND TYPES INIT\n"); */
203
204 InterfaceNotify = InterfaceNotifyProc;
205 InterfacePtrDelete = InterfacePtrDeleteProc;
206 g_simulation_list = gl_create(10L);
207 /* FPRINTF(ASCERR,"...COMPILER INIT\n"); */
208
209 return 0;
210 }
211
212 /* This function should not be called while there are any clients
213 * with pointers to any compiler structures, including gl_lists.
214 */
215 void Asc_CompilerDestroy(void)
216 {
217 Asc_DestroySimulations();
218 InterfaceNotify = NULL;
219 InterfacePtrDelete = NULL;
220
221 SetUniversalProcedureList(NULL);
222 DestroyUniversalTable(GetUniversalTable());
223 SetUniversalTable(NULL);
224 EmptyTrash();
225 WriteChildMissing(NULL,NULL,NULL);
226 DestroyPrototype();
227 DestroyLibrary();
228 DestroyTemporaryList();
229 DestroyNotesDatabase((void *)0x1); /* clear all that may be */
230 DestroyUnitsTable();
231 DestroyDimenList();
232 Asc_DestroyModules((DestroyFunc)DestroyStatementList);
233 DestroySymbolTable();
234 DestroyStringSpace();
235 Asc_DestroyScannerWorkBuffer();
236 DestroyExtFuncLibrary(); /* deallocate external function nodes */
237
238 /* some of the following calls are order dependent. see the headers.
239 * In general, larger complex objects should be cleared before their
240 * smaller constituents. 9 days in 10 you'll get away with mistakes here.
241 */
242
243 ClearForVarRecycle(); /* deallocate reused forvar list */
244 DestroySetManager(); /* must not be done while Expr exist */
245 DestroyValueManager();
246 DestroyRelInstantiator();
247 DestroyLogRelInstantiator();
248 BinTokenClearTables();
249 DestroyPendingPool();
250 DestroyInstanceNanny(); /* empty the reusable array children */
251 Asc_DestroyEnvironment();
252 NumpairClearPuddle();
253 RelationIO_destroy_pool();
254 sets_destroy_pool();
255 ppe_destroy_pool();
256 exprs_destroy_pool();
257 name_destroy_pool();
258 Asc_SignalDestroy();
259 gl_emptyrecycler(); /* empty the reused list pool */
260 gl_destroy_pool(); /* empty the reused list head pool */
261 ClearRecycleStack(); /* empty the reused stack list */
262 Asc_DestroyScannerInputBuffer(); /* empty lexer */
263
264 }

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