00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define _GLOBLCMP_SOURCE_
00024
00025 #include "setup.h"
00026
00027 #if DEFGLOBAL_CONSTRUCT && CONSTRUCT_COMPILER && (! RUN_TIME)
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031
00032 #include "conscomp.h"
00033 #include "globldef.h"
00034 #include "envrnmnt.h"
00035 #include "globlcmp.h"
00036
00037
00038
00039
00040
00041 static int ConstructToCode(void *,char *,char *,char *,int,FILE *,int,int);
00042 static void DefglobalToCode(void *,FILE *,struct defglobal *,
00043 int,int,int);
00044 static void DefglobalModuleToCode(void *,FILE *,struct defmodule *,int,int,int);
00045 static void CloseDefglobalFiles(void *,FILE *,FILE *,int);
00046 static void BeforeDefglobalsToCode(void *);
00047 static void InitDefglobalsCode(void *,FILE *,int,int);
00048
00049
00050
00051
00052
00053 globle void DefglobalCompilerSetup(
00054 void *theEnv)
00055 {
00056 DefglobalData(theEnv)->DefglobalCodeItem =
00057 AddCodeGeneratorItem(theEnv,"defglobal",0,BeforeDefglobalsToCode,
00058 InitDefglobalsCode,ConstructToCode,2);
00059 }
00060
00061
00062
00063
00064
00065
00066 static void BeforeDefglobalsToCode(
00067 void *theEnv)
00068 {
00069 MarkConstructBsaveIDs(theEnv,DefglobalData(theEnv)->DefglobalModuleIndex);
00070 }
00071
00072
00073
00074
00075
00076 #if WIN_BTC
00077 #pragma argsused
00078 #endif
00079 static void InitDefglobalsCode(
00080 void *theEnv,
00081 FILE *initFP,
00082 int imageID,
00083 int maxIndices)
00084 {
00085 #if MAC_MCW || WIN_MCW || MAC_XCD
00086 #pragma unused(maxIndices)
00087 #pragma unused(imageID)
00088 #pragma unused(theEnv)
00089 #endif
00090 fprintf(initFP," ResetDefglobals(theEnv);\n");
00091 }
00092
00093
00094
00095
00096
00097 static int ConstructToCode(
00098 void *theEnv,
00099 char *fileName,
00100 char *pathName,
00101 char *fileNameBuffer,
00102 int fileID,
00103 FILE *headerFP,
00104 int imageID,
00105 int maxIndices)
00106 {
00107 int fileCount = 1;
00108 struct defmodule *theModule;
00109 struct defglobal *theDefglobal;
00110 int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1;
00111 int defglobalArrayCount = 0, defglobalArrayVersion = 1;
00112 FILE *moduleFile = NULL, *defglobalFile = NULL;
00113
00114
00115
00116
00117
00118 fprintf(headerFP,"#include \"globldef.h\"\n");
00119
00120
00121
00122
00123
00124
00125 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00126 theModule != NULL;
00127 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00128 {
00129 EnvSetCurrentModule(theEnv,(void *) theModule);
00130
00131 moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
00132 moduleArrayVersion,headerFP,
00133 "struct defglobalModule",ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem),
00134 FALSE,NULL);
00135
00136 if (moduleFile == NULL)
00137 {
00138 CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices);
00139 return(0);
00140 }
00141
00142 DefglobalModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount);
00143 moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion,
00144 maxIndices,NULL,NULL);
00145
00146 for (theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,NULL);
00147 theDefglobal != NULL;
00148 theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theDefglobal))
00149 {
00150 defglobalFile = OpenFileIfNeeded(theEnv,defglobalFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
00151 defglobalArrayVersion,headerFP,
00152 "struct defglobal",ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem),
00153 FALSE,NULL);
00154 if (defglobalFile == NULL)
00155 {
00156 CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices);
00157 return(0);
00158 }
00159
00160 DefglobalToCode(theEnv,defglobalFile,theDefglobal,imageID,maxIndices,moduleCount);
00161 defglobalArrayCount++;
00162 defglobalFile = CloseFileIfNeeded(theEnv,defglobalFile,&defglobalArrayCount,
00163 &defglobalArrayVersion,maxIndices,NULL,NULL);
00164 }
00165
00166 moduleCount++;
00167 moduleArrayCount++;
00168 }
00169
00170 CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices);
00171
00172 return(1);
00173 }
00174
00175
00176
00177
00178
00179
00180 static void CloseDefglobalFiles(
00181 void *theEnv,
00182 FILE *moduleFile,
00183 FILE *defglobalFile,
00184 int maxIndices)
00185 {
00186 int count = maxIndices;
00187 int arrayVersion = 0;
00188
00189 if (defglobalFile != NULL)
00190 {
00191 count = maxIndices;
00192 CloseFileIfNeeded(theEnv,defglobalFile,&count,&arrayVersion,maxIndices,NULL,NULL);
00193 }
00194
00195 if (moduleFile != NULL)
00196 {
00197 count = maxIndices;
00198 CloseFileIfNeeded(theEnv,moduleFile,&count,&arrayVersion,maxIndices,NULL,NULL);
00199 }
00200 }
00201
00202
00203
00204
00205
00206 #if WIN_BTC
00207 #pragma argsused
00208 #endif
00209 static void DefglobalModuleToCode(
00210 void *theEnv,
00211 FILE *theFile,
00212 struct defmodule *theModule,
00213 int imageID,
00214 int maxIndices,
00215 int moduleCount)
00216 {
00217 #if MAC_MCW || WIN_MCW || MAC_XCD
00218 #pragma unused(moduleCount)
00219 #endif
00220
00221 fprintf(theFile,"{");
00222
00223 ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices,
00224 DefglobalData(theEnv)->DefglobalModuleIndex,ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem));
00225
00226 fprintf(theFile,"}");
00227 }
00228
00229
00230
00231
00232
00233 static void DefglobalToCode(
00234 void *theEnv,
00235 FILE *theFile,
00236 struct defglobal *theDefglobal,
00237 int imageID,
00238 int maxIndices,
00239 int moduleCount)
00240 {
00241
00242
00243
00244
00245 fprintf(theFile,"{");
00246
00247 ConstructHeaderToCode(theEnv,theFile,&theDefglobal->header,imageID,maxIndices,
00248 moduleCount,ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem),
00249 ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem));
00250
00251 fprintf(theFile,",");
00252
00253
00254
00255
00256
00257 fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount);
00258
00259
00260
00261
00262
00263 fprintf(theFile,"{NULL,RVOID}");
00264
00265
00266
00267
00268
00269 fprintf(theFile,",");
00270 PrintHashedExpressionReference(theEnv,theFile,theDefglobal->initial,imageID,maxIndices);
00271
00272 fprintf(theFile,"}");
00273 }
00274
00275
00276
00277
00278
00279 globle void DefglobalCModuleReference(
00280 void *theEnv,
00281 FILE *theFile,
00282 int count,
00283 int imageID,
00284 int maxIndices)
00285 {
00286 fprintf(theFile,"MIHS &%s%d_%d[%d]",
00287 ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem),
00288 imageID,
00289 (count / maxIndices) + 1,
00290 (count % maxIndices));
00291 }
00292
00293
00294
00295
00296
00297 globle void DefglobalCConstructReference(
00298 void *theEnv,
00299 FILE *theFile,
00300 void *vTheGlobal,
00301 int imageID,
00302 int maxIndices)
00303 {
00304 struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;
00305
00306 if (theGlobal == NULL)
00307 { fprintf(theFile,"NULL"); }
00308 else
00309 {
00310 fprintf(theFile,"&%s%d_%ld[%ld]",ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem),
00311 imageID,
00312 (theGlobal->header.bsaveID / maxIndices) + 1,
00313 theGlobal->header.bsaveID % maxIndices);
00314 }
00315
00316 }
00317
00318 #endif
00319
00320