00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define _DFFCTCMP_SOURCE_
00024
00025 #include "setup.h"
00026
00027 #if DEFFACTS_CONSTRUCT && CONSTRUCT_COMPILER && (! RUN_TIME)
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031
00032 #include "conscomp.h"
00033 #include "dffctdef.h"
00034 #include "envrnmnt.h"
00035
00036 #include "dffctcmp.h"
00037
00038
00039
00040
00041
00042 static int ConstructToCode(void *,char *,char *,char *,int,FILE *,int,int);
00043 static void DeffactsToCode(void *,FILE *,struct deffacts *,
00044 int,int,int);
00045 static void DeffactsModuleToCode(void *,FILE *,struct defmodule *,int,int,int);
00046 static void CloseDeffactsFiles(void *,FILE *,FILE *,int);
00047 static void BeforeDeffactsToCode(void *);
00048
00049
00050
00051
00052
00053 globle void DeffactsCompilerSetup(
00054 void *theEnv)
00055 {
00056 DeffactsData(theEnv)->DeffactsCodeItem =
00057 AddCodeGeneratorItem(theEnv,"deffacts",0,BeforeDeffactsToCode,
00058 NULL,ConstructToCode,2);
00059 }
00060
00061
00062
00063
00064
00065
00066 static void BeforeDeffactsToCode(
00067 void *theEnv)
00068 {
00069 MarkConstructBsaveIDs(theEnv,DeffactsData(theEnv)->DeffactsModuleIndex);
00070 }
00071
00072
00073
00074
00075
00076 static int ConstructToCode(
00077 void *theEnv,
00078 char *fileName,
00079 char *pathName,
00080 char *fileNameBuffer,
00081 int fileID,
00082 FILE *headerFP,
00083 int imageID,
00084 int maxIndices)
00085 {
00086 int fileCount = 1;
00087 struct defmodule *theModule;
00088 struct deffacts *theDeffacts;
00089 int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1;
00090 int deffactsArrayCount = 0, deffactsArrayVersion = 1;
00091 FILE *moduleFile = NULL, *deffactsFile = NULL;
00092
00093
00094
00095
00096
00097 fprintf(headerFP,"#include \"dffctdef.h\"\n");
00098
00099
00100
00101
00102
00103
00104 for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00105 theModule != NULL;
00106 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))
00107 {
00108 EnvSetCurrentModule(theEnv,(void *) theModule);
00109
00110 moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
00111 moduleArrayVersion,headerFP,
00112 "struct deffactsModule",ModulePrefix(DeffactsData(theEnv)->DeffactsCodeItem),
00113 FALSE,NULL);
00114
00115 if (moduleFile == NULL)
00116 {
00117 CloseDeffactsFiles(theEnv,moduleFile,deffactsFile,maxIndices);
00118 return(0);
00119 }
00120
00121 DeffactsModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount);
00122 moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion,
00123 maxIndices,NULL,NULL);
00124
00125
00126
00127
00128
00129 for (theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,NULL);
00130 theDeffacts != NULL;
00131 theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,theDeffacts))
00132 {
00133 deffactsFile = OpenFileIfNeeded(theEnv,deffactsFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount,
00134 deffactsArrayVersion,headerFP,
00135 "struct deffacts",ConstructPrefix(DeffactsData(theEnv)->DeffactsCodeItem),
00136 FALSE,NULL);
00137 if (deffactsFile == NULL)
00138 {
00139 CloseDeffactsFiles(theEnv,moduleFile,deffactsFile,maxIndices);
00140 return(0);
00141 }
00142
00143 DeffactsToCode(theEnv,deffactsFile,theDeffacts,imageID,maxIndices,moduleCount);
00144 deffactsArrayCount++;
00145 deffactsFile = CloseFileIfNeeded(theEnv,deffactsFile,&deffactsArrayCount,
00146 &deffactsArrayVersion,maxIndices,NULL,NULL);
00147 }
00148
00149 moduleCount++;
00150 moduleArrayCount++;
00151 }
00152
00153 CloseDeffactsFiles(theEnv,moduleFile,deffactsFile,maxIndices);
00154
00155 return(1);
00156 }
00157
00158
00159
00160
00161
00162
00163 static void CloseDeffactsFiles(
00164 void *theEnv,
00165 FILE *moduleFile,
00166 FILE *deffactsFile,
00167 int maxIndices)
00168 {
00169 int count = maxIndices;
00170 int arrayVersion = 0;
00171
00172 if (deffactsFile != NULL)
00173 {
00174 count = maxIndices;
00175 CloseFileIfNeeded(theEnv,deffactsFile,&count,&arrayVersion,maxIndices,NULL,NULL);
00176 }
00177
00178 if (moduleFile != NULL)
00179 {
00180 count = maxIndices;
00181 CloseFileIfNeeded(theEnv,moduleFile,&count,&arrayVersion,maxIndices,NULL,NULL);
00182 }
00183 }
00184
00185
00186
00187
00188
00189 #if WIN_BTC
00190 #pragma argsused
00191 #endif
00192 static void DeffactsModuleToCode(
00193 void *theEnv,
00194 FILE *theFile,
00195 struct defmodule *theModule,
00196 int imageID,
00197 int maxIndices,
00198 int moduleCount)
00199 {
00200 #if MAC_MCW || WIN_MCW || MAC_XCD
00201 #pragma unused(moduleCount)
00202 #endif
00203
00204 fprintf(theFile,"{");
00205
00206 ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices,
00207 DeffactsData(theEnv)->DeffactsModuleIndex,
00208 ConstructPrefix(DeffactsData(theEnv)->DeffactsCodeItem));
00209
00210 fprintf(theFile,"}");
00211 }
00212
00213
00214
00215
00216
00217 static void DeffactsToCode(
00218 void *theEnv,
00219 FILE *theFile,
00220 struct deffacts *theDeffacts,
00221 int imageID,
00222 int maxIndices,
00223 int moduleCount)
00224 {
00225
00226
00227
00228
00229 fprintf(theFile,"{");
00230
00231 ConstructHeaderToCode(theEnv,theFile,&theDeffacts->header,imageID,maxIndices,
00232 moduleCount,ModulePrefix(DeffactsData(theEnv)->DeffactsCodeItem),
00233 ConstructPrefix(DeffactsData(theEnv)->DeffactsCodeItem));
00234
00235 fprintf(theFile,",");
00236
00237
00238
00239
00240
00241 ExpressionToCode(theEnv,theFile,theDeffacts->assertList);
00242 fprintf(theFile,"}");
00243 }
00244
00245
00246
00247
00248
00249 globle void DeffactsCModuleReference(
00250 void *theEnv,
00251 FILE *theFile,
00252 int count,
00253 int imageID,
00254 int maxIndices)
00255 {
00256 fprintf(theFile,"MIHS &%s%d_%d[%d]",
00257 ModulePrefix(DeffactsData(theEnv)->DeffactsCodeItem),
00258 imageID,
00259 (count / maxIndices) + 1,
00260 (count % maxIndices));
00261 }
00262
00263 #endif
00264
00265