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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2323 - (show annotations) (download) (as text)
Wed Dec 15 06:35:43 2010 UTC (13 years, 7 months ago) by jpye
File MIME type: text/x-csrc
File size: 8273 byte(s)
Refactor some more stuff from 'utilities' into 'general' with goal that 'general' never refers to 'utilities'.
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 <ascend/general/platform.h>
33 #include <ascend/general/ascMalloc.h>
34 #include <ascend/utilities/ascEnvVar.h>
35
36 #include "ascCompiler.h"
37 #include <ascend/utilities/ascSignal.h>
38 #include <ascend/general/panic.h>
39 #include <ascend/general/list.h>
40
41
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 <ascend/general/pool.h>
70 #include "arrayinst.h"
71 #include "relation_type.h"
72 #include "relation_io.h"
73 #include "find.h"
74 #include "rel_blackbox.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 }
130 }
131 #endif
132 }
133
134 /*
135 * this function is passed around by pointer in the compiler.
136 */
137 /*
138 * We don't have a use for this yet. We are being protractive
139 * in that any objects that we are referencing directly get
140 * cleaned up *before* we call any routines that could
141 * potentially move an instance.
142 */
143 static
144 void InterfacePtrDeleteProc(struct Instance *i, char *ptr)
145 {
146 (void)i; /* stop gcc whine about unused parameter */
147 (void)ptr; /* stop gcc whine about unused parameter */
148 }
149
150
151 /* if this function returns nonzero, ascend cannot run and a ton
152 * of memory might be leaked while exiting.
153 */
154 int Asc_CompilerInit(int simp)
155 {
156
157 if (simp !=0){
158 g_simplify_relations = 1;
159 }
160
161 #ifdef REIMPLEMENT_STREAMS
162 Asc_RedirectCompilerDefault();
163 #endif /* REIMPLEMENT_STREAMS */
164
165 /* Commenting out the call to gl_init will make the system slower but
166 * easier to debug for leaks.
167 * Move the close-comment to after gl_init if debugging.
168 * Please don't ever check in this file with gl_init commented out.
169 */
170 gl_init();
171 gl_init_pool();
172 #ifdef ASC_SIGNAL_TRAPS
173 Asc_SignalInit();
174 #endif
175 Asc_InitEnvironment(10);
176 name_init_pool();
177 exprs_init_pool();
178 ppe_init_pool();
179 sets_init_pool();
180 RelationIO_init_pool();
181 InitSetManager();
182 InitValueManager();
183 InitRelInstantiator();
184 InitLogRelInstantiator();
185 InitPendingPool();
186 InitInstanceNanny();
187
188 InitDimenList();
189 InitSymbolTable();
190 InitBaseTypeNames();
191 InitUnitsTable();
192 InitNotesDatabase(NULL);
193 InitNotesDatabase(LibraryNote());
194 InitNotesDatabase(GlobalNote());
195 InitExternalFuncLibrary(); /* initialize external func library */
196 AddUserFunctions(); /* add user packages */
197
198 InitDump();
199 InitializePrototype();
200 /* FPRINTF(ASCERR,"...PROTO INIT\n"); */
201 InitializeLibrary();
202 /* FPRINTF(ASCERR,"...LIBRARY INIT\n"); */
203 SetUniversalTable(CreateUniversalTable());
204 /* FPRINTF(ASCERR,"...UNIV TABLE INIT\n"); */
205 DefineFundamentalTypes();
206 /* FPRINTF(ASCERR,"...FUND TYPES INIT\n"); */
207
208 InterfaceNotify = InterfaceNotifyProc;
209 InterfacePtrDelete = InterfacePtrDeleteProc;
210 g_simulation_list = gl_create(10L);
211 /* FPRINTF(ASCERR,"...COMPILER INIT\n"); */
212
213 return 0;
214 }
215
216 /* This function should not be called while there are any clients
217 * with pointers to any compiler structures, including gl_lists.
218 */
219 void Asc_CompilerDestroy(void)
220 {
221 Asc_DestroySimulations();
222 InterfaceNotify = NULL;
223 InterfacePtrDelete = NULL;
224
225 SetUniversalProcedureList(NULL);
226 DestroyUniversalTable(GetUniversalTable());
227 SetUniversalTable(NULL);
228 EmptyTrash();
229 WriteChildMissing(NULL,NULL,NULL);
230 DestroyPrototype();
231 DestroyLibrary();
232 DestroyTemporaryList();
233 DestroyNotesDatabase((void *)0x1); /* clear all that may be */
234 DestroyUnitsTable();
235 DestroyDimenList();
236 Asc_DestroyModules((DestroyFunc)DestroyStatementList);
237 DestroySymbolTable();
238 DestroyStringSpace();
239 Asc_DestroyScannerWorkBuffer();
240 DestroyExtFuncLibrary(); /* deallocate external function nodes */
241
242 /* some of the following calls are order dependent. see the headers.
243 * In general, larger complex objects should be cleared before their
244 * smaller constituents. 9 days in 10 you'll get away with mistakes here.
245 */
246
247 ClearForVarRecycle(); /* deallocate reused forvar list */
248 DestroySetManager(); /* must not be done while Expr exist */
249 DestroyValueManager();
250 DestroyRelInstantiator();
251 DestroyLogRelInstantiator();
252 BinTokenClearTables();
253 DestroyPendingPool();
254 DestroyInstanceNanny(); /* empty the reusable array children */
255 Asc_DestroyEnvironment();
256 NumpairClearPuddle();
257 RelationIO_destroy_pool();
258 sets_destroy_pool();
259 ppe_destroy_pool();
260 exprs_destroy_pool();
261 name_destroy_pool();
262 #ifdef ASC_SIGNAL_TRAPS
263 Asc_SignalDestroy();
264 #endif
265 gl_emptyrecycler(); /* empty the reused list pool */
266 gl_destroy_pool(); /* empty the reused list head pool */
267 ClearRecycleStack(); /* empty the reused stack list */
268 Asc_DestroyScannerInputBuffer(); /* empty lexer */
269
270 }

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