⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 conscomp.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
   fprintf(ConstructCompilerData(theEnv)->FixupFP,"#include \"%s.h\"\n",fileName);   fprintf(ConstructCompilerData(theEnv)->FixupFP,"\n");      fprintf(ConstructCompilerData(theEnv)->FixupFP,"\n");   fprintf(ConstructCompilerData(theEnv)->FixupFP,"/**********************************/\n");   fprintf(ConstructCompilerData(theEnv)->FixupFP,"/* CONSTRUCT IMAGE FIXUP FUNCTION */\n");   fprintf(ConstructCompilerData(theEnv)->FixupFP,"/**********************************/\n");   fprintf(ConstructCompilerData(theEnv)->FixupFP,"\nvoid FixupCImage_%d(\n",ConstructCompilerData(theEnv)->ImageID);   fprintf(ConstructCompilerData(theEnv)->FixupFP,"  void *theEnv)\n");   fprintf(ConstructCompilerData(theEnv)->FixupFP,"  {\n");   /*==================================*/   /* Generate code for atomic values, */   /* function definitions, hashed     */   /* expressions, and constructs.     */   /*==================================*/   AtomicValuesToCode(theEnv,fileName);   FunctionsToCode(theEnv,fileName);   HashedExpressionsToCode(theEnv);   ConstraintsToCode(theEnv,fileName,4,ConstructCompilerData(theEnv)->HeaderFP,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);   /*===============================*/   /* Call each code generator item */   /* for the various constructs.   */   /*===============================*/   fileVersion = 5;   for (cgPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;        cgPtr != NULL;        cgPtr = cgPtr->next)     {      if (cgPtr->generateFunction != NULL)        {         (*cgPtr->generateFunction)(theEnv,fileName,fileVersion,ConstructCompilerData(theEnv)->HeaderFP,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);         fileVersion++;        }     }   /*=========================================*/   /* Restore the atomic data bucket values   */   /* (which were set to an index reference). */   /*=========================================*/   RestoreAtomicValueBuckets(theEnv);   /*============================*/   /* Close the expression file. */   /*============================*/   if (ConstructCompilerData(theEnv)->ExpressionFP != NULL)     {      fprintf(ConstructCompilerData(theEnv)->ExpressionFP,"};\n");      GenClose(theEnv,ConstructCompilerData(theEnv)->ExpressionFP);     }   /*=======================*/   /* Close the fixup file. */   /*=======================*/   if (ConstructCompilerData(theEnv)->FixupFP != NULL)     {      fprintf(ConstructCompilerData(theEnv)->FixupFP,"  }\n");      GenClose(theEnv,ConstructCompilerData(theEnv)->FixupFP);     }   /*====================================*/   /* Write the initialization function. */   /*====================================*/   WriteInitializationFunction(theEnv,fileName);   /*========================*/   /* Close the header file. */   /*========================*/   GenClose(theEnv,ConstructCompilerData(theEnv)->HeaderFP);   /*==================================================*/   /* Return TRUE to indicate that the constructs-to-c */   /* command was successfully executed.               */   /*==================================================*/   return(TRUE);  }/*******************************************************//* WriteFunctionExternDeclarations: Loop through the   *//*   list of function definitions and generates extern *//*   declarations for them in the specified file.      *//*******************************************************/static void WriteFunctionExternDeclarations(  void *theEnv,  FILE *fp)  {   struct FunctionDefinition *theFunction;   fprintf(fp,"\n");   fprintf(fp,"/************************************/\n");   fprintf(fp,"/* EXTERNAL FUNCTION DEFINITIONS    */\n");   fprintf(fp,"/************************************/\n\n");   for (theFunction = GetFunctionList(theEnv);        theFunction != NULL;        theFunction = theFunction->next)     {      fprintf(fp,"extern ");      switch(theFunction->returnValueType)        {         case 'i':         case 'b':           fprintf(fp,"int ");           break;                    case 'g':           fprintf(fp,"long long ");           break;         case 'l':           fprintf(fp,"long ");           break;         case 'f':           fprintf(fp,"float ");           break;         case 'd':           fprintf(fp,"double ");           break;         case 'w':         case 's':         case 'o':           fprintf(fp,"void *");           break;         case 'c':           fprintf(fp,"char ");           break;         case 'a':         case 'x':           fprintf(fp,"void * ");           break;         case 'v':         case 'm':         case 'u':         case 'n':         case 'j':         case 'k':           fprintf(fp,"void ");           break;         default:           SystemError(theEnv,"CONSCOMP",1);           break;        }      fprintf(fp,"%s(",theFunction->actualFunctionName);            switch(theFunction->returnValueType)        {         case 'i':         case 'b':         case 'l':         case 'f':         case 'd':         case 'w':         case 's':         case 'o':         case 'c':         case 'a':         case 'x':         case 'v':           if (theFunction->environmentAware)              { fprintf(fp,"void *"); }           else             { fprintf(fp,"void"); }           break;         case 'm':         case 'u':         case 'n':         case 'j':         case 'k':           if (theFunction->environmentAware)              { fprintf(fp,"void *,DATA_OBJECT_PTR_ARG"); }           else             { fprintf(fp,"DATA_OBJECT_PTR_ARG"); }           break;        }      fprintf(fp,");\n");     }  }/****************************************************//* FunctionsToCode: Generates C code to represent   *//*   the function declaration data structures (used *//*   to declare system and user defined functions). *//****************************************************/static int FunctionsToCode(  void *theEnv,  char *fileName)  {   short i = 0;   FILE *fp;   int version = 1;   int newHeader = TRUE;   struct FunctionDefinition *fctnPtr;   /*=============================*/   /* Assign a reference index to */   /* each of the functions.      */   /*=============================*/   for (fctnPtr = GetFunctionList(theEnv);        fctnPtr != NULL;        fctnPtr = fctnPtr->next)     { fctnPtr->bsaveIndex = i++; }   /*=======================================*/   /* Create the file in which to store the */   /* function definition data structures.  */   /*=======================================*/   if ((fp = NewCFile(theEnv,fileName,2,version,FALSE)) == NULL)     { return(0); }   /*===============================================*/   /* Construct the definition of the function list */   /* from the definitions of the functions.        */   /*===============================================*/   fprintf(fp,"\n\n");   fprintf(fp,"/************************************/\n");   fprintf(fp,"/* FUNCTION LIST DEFINITION         */\n");   fprintf(fp,"/************************************/\n\n");   i = 1;   fctnPtr = GetFunctionList(theEnv);   while (fctnPtr != NULL)     {      if (newHeader)        {         fprintf(fp,"struct FunctionDefinition P%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,version);         fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct FunctionDefinition P%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,version);         newHeader = FALSE;        }      fprintf(fp,"{");      PrintSymbolReference(theEnv,fp,fctnPtr->callFunctionName);      fprintf(fp,",\"%s\",",fctnPtr->actualFunctionName);      fprintf(fp,"'%c',",fctnPtr->returnValueType);      fprintf(fp,"PTIF %s,",fctnPtr->actualFunctionName);      fprintf(fp,"NULL,");      if (fctnPtr->restrictions != NULL) fprintf(fp,"\"%s\",",fctnPtr->restrictions);      else fprintf(fp,"NULL,");      fprintf(fp,"0,0,%d,0,",(fctnPtr->environmentAware ? 1 : 0));      PrintFunctionReference(theEnv,fp,fctnPtr->next);      i++;      fctnPtr = fctnPtr->next;      if ((i > ConstructCompilerData(theEnv)->MaxIndices) || (fctnPtr == NULL))        {         fprintf(fp,"}};\n");         GenClose(theEnv,fp);         i = 1;         version++;         if (fctnPtr != NULL)           {            if ((fp = NewCFile(theEnv,fileName,2,version,FALSE)) == NULL) return(0);            newHeader = TRUE;           }        }      else        { fprintf(fp,"},\n"); }     }   return(TRUE);  }/************************************************************//* PrintFunctionReference: Writes the C code representation *//*   of a pointer to a function definition data structure.  *//************************************************************/globle void PrintFunctionReference(  void *theEnv,  FILE *fp,  struct FunctionDefinition *funcPtr)  {   if (funcPtr == NULL) fprintf(fp,"NULL");   else      fprintf(fp,"&P%d_%d[%d]",ConstructCompilerData(theEnv)->ImageID,                                  (funcPtr->bsaveIndex / ConstructCompilerData(theEnv)->MaxIndices) + 1,                                   funcPtr->bsaveIndex % ConstructCompilerData(theEnv)->MaxIndices);  }/******************************************//* WriteInitializationFunction: Generates *//*   the C initialization function for    *//*   this constructs-to-c module.         *//******************************************/static int WriteInitializationFunction(  void *theEnv,  char *fileName)  {   char fname[FILENAME_MAX+1];   FILE *fp;   struct CodeGeneratorItem *cgPtr;   /*===============================*/   /* Open the initialization file. */   /*===============================*/   gensprintf(fname,"%s.c",fileName);   if ((fp = GenOpen(theEnv,fname,"w")) == NULL)     {      OpenErrorMessage(theEnv,"constructs-to-c",fname);      return(FALSE);     }   /*=====================================*/   /* Write out #includes and prototypes. */   /*=====================================*/   fprintf(fp,"#include \"%s.h\"\n",fileName);   fprintf(fp,"\n");   fprintf(fp,"#include \"utility.h\"\n");   fprintf(fp,"#include \"generate.h\"\n");   fprintf(fp,"#include \"envrnmnt.h\"\n");   fprintf(fp,"#include \"expressn.h\"\n");   fprintf(fp,"#include \"extnfunc.h\"\n");   fprintf(fp,"#include \"objrtmch.h\"\n");   fprintf(fp,"#include \"rulebld.h\"\n\n");   fprintf(ConstructCompilerData(theEnv)->HeaderFP,"   void *InitCImage_%d(void);\n",ConstructCompilerData(theEnv)->ImageID);   fprintf(ConstructCompilerData(theEnv)->HeaderFP,"   void FixupCImage_%d(void *);\n",ConstructCompilerData(theEnv)->ImageID);   /*============================================*/   /* Begin writing the initialization function. */   /*============================================*/   fprintf(fp,"\n");   fprintf(fp,"/*******************************************/\n");   fprintf(fp,"/* CONSTRUCT IMAGE INITIALIZATION FUNCTION */\n");   fprintf(fp,"/*******************************************/\n");   fprintf(fp,"\nvoid *InitCImage_%d()\n",ConstructCompilerData(theEnv)->ImageID);   fprintf(fp,"  {\n");   fprintf(fp,"   static void *theEnv = NULL;\n\n");   fprintf(fp,"   if (theEnv != NULL) return(NULL);\n\n");   fprintf(fp,"   theEnv = CreateRuntimeEnvironment(sht%d,fht%d,iht%d,bmht%d);\n\n",           ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ImageID,           ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->ImageID);      fprintf(fp,"   EnvClear(theEnv);\n");   fprintf(fp,"   PeriodicCleanup(theEnv,TRUE,FALSE);\n");   fprintf(fp,"   RefreshSpecialSymbols(theEnv);\n");   fprintf(fp,"   InstallFunctionList(theEnv,P%d_1);\n\n",ConstructCompilerData(theEnv)->ImageID);   fprintf(fp,"   InitExpressionPointers(theEnv);\n");   fprintf(fp,"   FixupCImage_%d(theEnv);\n\n",ConstructCompilerData(theEnv)->ImageID);   /*==========================================*/   /* Write construct specific initialization. */   /*==========================================*/   cgPtr = ConstructCompilerData(theEnv)->ListOfCodeGeneratorItems;   while (cgPtr != NULL)     {      if (cgPtr->initFunction != NULL)        {         (*cgPtr->initFunction)(theEnv,fp,ConstructCompilerData(theEnv)->ImageID,ConstructCompilerData(theEnv)->MaxIndices);         fprintf(fp,"\n");        }      cgPtr = cgPtr->next;     }   /*================================*/   /* Close the initialization file. */   /*================================*/   fprintf(fp,"   return(theEnv);\n");   fprintf(fp,"  }\n");   GenClose(theEnv,fp);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -