00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "setup.h"
00027
00028 #if DEFFUNCTION_CONSTRUCT && CONSTRUCT_COMPILER && (! RUN_TIME)
00029
00030 #include "conscomp.h"
00031 #include "envrnmnt.h"
00032
00033 #define _DFFNXCMP_SOURCE_
00034 #include "dffnxcmp.h"
00035
00036
00037
00038
00039
00040
00041
00042 static void ReadyDeffunctionsForCode(void *);
00043 static int DeffunctionsToCode(void *,char *,char *,char *,int,FILE *,int,int);
00044 static void CloseDeffunctionFiles(void *,FILE *,FILE *,int);
00045 static void DeffunctionModuleToCode(void *,FILE *,struct defmodule *,int,int);
00046 static void SingleDeffunctionToCode(void *,FILE *,DEFFUNCTION *,int,int,int);
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063 globle void SetupDeffunctionCompiler(
00064 void *theEnv)
00065 {
00066 DeffunctionData(theEnv)->DeffunctionCodeItem = AddCodeGeneratorItem(theEnv,"deffunctions",0,ReadyDeffunctionsForCode,
00067 NULL,DeffunctionsToCode,2);
00068 }
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085 globle void PrintDeffunctionReference(
00086 void *theEnv,
00087 FILE *fp,
00088 DEFFUNCTION *dfPtr,
00089 int imageID,
00090 int maxIndices)
00091 {
00092 if (dfPtr == NULL)
00093 fprintf(fp,"NULL");
00094 else
00095 fprintf(fp,"&%s%d_%d[%d]",ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem),imageID,
00096 (int) ((dfPtr->header.bsaveID / maxIndices) + 1),
00097 (int) (dfPtr->header.bsaveID % maxIndices));
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 globle void DeffunctionCModuleReference(
00114 void *theEnv,
00115 FILE *theFile,
00116 int count,
00117 int imageID,
00118 int maxIndices)
00119 {
00120 fprintf(theFile,"MIHS &%s%d_%d[%d]",
00121 ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem),
00122 imageID,
00123 (count / maxIndices) + 1,
00124 (count % maxIndices));
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142 static void ReadyDeffunctionsForCode(
00143 void *theEnv)
00144 {
00145 MarkConstructBsaveIDs(theEnv,DeffunctionData(theEnv)->DeffunctionModuleIndex);
00146 }
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 static int DeffunctionsToCode(
00164 void *theEnv,
00165 char *fileName,
00166 char *pathName,
00167 char *fileNameBuffer,
00168 int fileID,
00169 FILE *headerFP,
00170 int imageID,
00171 int maxIndices)
00172 {
00173 int fileCount = 1;
00174 struct defmodule *theModule;
00175 DEFFUNCTION *theDeffunction;
00176 int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1;
00177 int deffunctionArrayCount = 0, deffunctionArrayVersion = 1;
00178 FILE *moduleFile = NULL, *deffunctionFile = NULL;
00179
00180
00181
00182
00183 fprintf(headerFP,"#include \"dffnxfun.h\"\n");
00184
00185
00186
00187
00188
00189 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00190
00191 while (theModule != NULL)
00192 {
00193 EnvSetCurrentModule(theEnv,(void *) theModule);
00194
00195 moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
00196 moduleArrayVersion,headerFP,
00197 "DEFFUNCTION_MODULE",ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem),
00198 FALSE,NULL);
00199
00200 if (moduleFile == NULL)
00201 {
00202 CloseDeffunctionFiles(theEnv,moduleFile,deffunctionFile,maxIndices);
00203 return(0);
00204 }
00205
00206 DeffunctionModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices);
00207 moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion,
00208 maxIndices,NULL,NULL);
00209
00210 theDeffunction = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,NULL);
00211
00212 while (theDeffunction != NULL)
00213 {
00214 deffunctionFile = OpenFileIfNeeded(theEnv,deffunctionFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
00215 deffunctionArrayVersion,headerFP,
00216 "DEFFUNCTION",ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem),
00217 FALSE,NULL);
00218 if (deffunctionFile == NULL)
00219 {
00220 CloseDeffunctionFiles(theEnv,moduleFile,deffunctionFile,maxIndices);
00221 return(0);
00222 }
00223
00224 SingleDeffunctionToCode(theEnv,deffunctionFile,theDeffunction,imageID,
00225 maxIndices,moduleCount);
00226 deffunctionArrayCount++;
00227 deffunctionFile = CloseFileIfNeeded(theEnv,deffunctionFile,&deffunctionArrayCount,
00228 &deffunctionArrayVersion,maxIndices,NULL,NULL);
00229
00230 theDeffunction = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,theDeffunction);
00231 }
00232
00233 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule);
00234 moduleCount++;
00235 moduleArrayCount++;
00236 }
00237
00238 CloseDeffunctionFiles(theEnv,moduleFile,deffunctionFile,maxIndices);
00239
00240 return(1);
00241 }
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255 static void CloseDeffunctionFiles(
00256 void *theEnv,
00257 FILE *moduleFile,
00258 FILE *deffunctionFile,
00259 int maxIndices)
00260 {
00261 int count = maxIndices;
00262 int arrayVersion = 0;
00263
00264 if (deffunctionFile != NULL)
00265 {
00266 count = maxIndices;
00267 CloseFileIfNeeded(theEnv,deffunctionFile,&count,&arrayVersion,maxIndices,NULL,NULL);
00268 }
00269
00270 if (moduleFile != NULL)
00271 {
00272 count = maxIndices;
00273 CloseFileIfNeeded(theEnv,moduleFile,&count,&arrayVersion,maxIndices,NULL,NULL);
00274 }
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 static void DeffunctionModuleToCode(
00291 void *theEnv,
00292 FILE *theFile,
00293 struct defmodule *theModule,
00294 int imageID,
00295 int maxIndices)
00296 {
00297 fprintf(theFile,"{");
00298 ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices,
00299 DeffunctionData(theEnv)->DeffunctionModuleIndex,ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem));
00300 fprintf(theFile,"}");
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317 static void SingleDeffunctionToCode(
00318 void *theEnv,
00319 FILE *theFile,
00320 DEFFUNCTION *theDeffunction,
00321 int imageID,
00322 int maxIndices,
00323 int moduleCount)
00324 {
00325
00326
00327
00328
00329 fprintf(theFile,"{");
00330 ConstructHeaderToCode(theEnv,theFile,&theDeffunction->header,imageID,maxIndices,moduleCount,
00331 ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem),
00332 ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem));
00333
00334
00335
00336
00337 fprintf(theFile,",0,0,0,");
00338 ExpressionToCode(theEnv,theFile,theDeffunction->code);
00339 fprintf(theFile,",%d,%d,%d",
00340 theDeffunction->minNumberOfParameters,
00341 theDeffunction->maxNumberOfParameters,
00342 theDeffunction->numberOfLocalVars);
00343
00344 fprintf(theFile,"}");
00345 }
00346
00347 #endif
00348
00349
00350
00351
00352
00353
00354
00355
00356