Example #1
0
static int HashTablesToCode(
  void *theEnv,
  EXEC_STATUS,
  char *fileName,
  char *pathName,
  char *fileNameBuffer)
  {
   unsigned long i;
   FILE *fp;
   struct symbolHashNode **symbolTable;
   struct floatHashNode **floatTable;
   struct integerHashNode **integerTable;
   struct bitMapHashNode **bitMapTable;

   /*======================================*/
   /* Write the code for the symbol table. */
   /*======================================*/

   symbolTable = GetSymbolTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,1,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct symbolHashNode *sht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct symbolHashNode *sht%d[%ld] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,SYMBOL_HASH_SIZE);

   for (i = 0; i < SYMBOL_HASH_SIZE; i++)
      {
       PrintSymbolReference(theEnv,execStatus,fp,symbolTable[i]);

       if (i + 1 != SYMBOL_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

   /*=====================================*/
   /* Write the code for the float table. */
   /*=====================================*/

   floatTable = GetFloatTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,2,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct floatHashNode *fht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct floatHashNode *fht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,FLOAT_HASH_SIZE);

   for (i = 0; i < FLOAT_HASH_SIZE; i++)
      {
       if (floatTable[i] == NULL) { fprintf(fp,"NULL"); }
       else PrintFloatReference(theEnv,execStatus,fp,floatTable[i]);

       if (i + 1 != FLOAT_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

   /*=======================================*/
   /* Write the code for the integer table. */
   /*=======================================*/

   integerTable = GetIntegerTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,3,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct integerHashNode *iht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct integerHashNode *iht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,INTEGER_HASH_SIZE);

   for (i = 0; i < INTEGER_HASH_SIZE; i++)
      {
       if (integerTable[i] == NULL) { fprintf(fp,"NULL"); }
       else PrintIntegerReference(theEnv,execStatus,fp,integerTable[i]);

       if (i + 1 != INTEGER_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

   /*======================================*/
   /* Write the code for the bitmap table. */
   /*======================================*/

   bitMapTable = GetBitMapTable(theEnv,execStatus);

   if ((fp = NewCFile(theEnv,execStatus,fileName,pathName,fileNameBuffer,1,4,FALSE)) == NULL) return(0);

   fprintf(ConstructCompilerData(theEnv,execStatus)->HeaderFP,"extern struct bitMapHashNode *bmht%d[];\n",ConstructCompilerData(theEnv,execStatus)->ImageID);
   fprintf(fp,"struct bitMapHashNode *bmht%d[%d] = {\n",ConstructCompilerData(theEnv,execStatus)->ImageID,BITMAP_HASH_SIZE);

   for (i = 0; i < BITMAP_HASH_SIZE; i++)
      {
       PrintBitMapReference(theEnv,execStatus,fp,bitMapTable[i]);

       if (i + 1 != BITMAP_HASH_SIZE) fprintf(fp,",\n");
      }

    fprintf(fp,"};\n");

    GenClose(theEnv,execStatus,fp);

    return(1);
   }
Example #2
0
/***********************************************************
  NAME         : AlphaPatternNodesToCode
  DESCRIPTION  : Writes out data structures for run-time
                 creation of object pattern alpha memories
  INPUTS       : 1) The base image output file name
                 2) The base image file id
                 3) A pointer to the header output file
                 4) The id of constructs-to-c image
                 5) The maximum number of indices
                    allowed in any single array
                    in the image
  RETURNS      : Next version file to open, 0 if error
  SIDE EFFECTS : Object patterns code written to files
  NOTES        : None
 ***********************************************************/
static int AlphaPatternNodesToCode(
  void *theEnv,
  char *fileName,
  int fileID,
  FILE *headerFP,
  int imageID,
  int maxIndices,
  int version)
  {
   FILE *fp;
   int arrayVersion;
   int newHeader;
   int i;
   OBJECT_ALPHA_NODE *thePattern;

   /* ================
      Create the file.
      ================ */
   if (ObjectNetworkTerminalPointer(theEnv) == NULL)
     return(version);

   /* =================================
      Dump the pattern node structures.
      ================================= */
   if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL)
     return(0);
   newHeader = TRUE;

   arrayVersion = 1;
   i = 1;

   thePattern = ObjectNetworkTerminalPointer(theEnv);
   while (thePattern != NULL)
     {
      if (newHeader)
        {
         fprintf(fp,"OBJECT_ALPHA_NODE %s%d_%d[] = {\n",
                    ObjectANPrefix(),imageID,arrayVersion);
         fprintf(headerFP,"extern OBJECT_ALPHA_NODE %s%d_%d[];\n",
                          ObjectANPrefix(),imageID,arrayVersion);
         newHeader = FALSE;
        }

      fprintf(fp,"{");

      PatternNodeHeaderToCode(theEnv,fp,&thePattern->header,imageID,maxIndices);

      fprintf(fp,",0L,");
      PrintBitMapReference(theEnv,fp,thePattern->classbmp);
      fprintf(fp,",");
      PrintBitMapReference(theEnv,fp,thePattern->slotbmp);
      fprintf(fp,",");
      IntermediatePatternNodeReference(theEnv,thePattern->patternNode,fp,imageID,maxIndices);
      fprintf(fp,",");
      ObjectPatternNodeReference(theEnv,thePattern->nxtInGroup,fp,imageID,maxIndices);
      fprintf(fp,",");
      ObjectPatternNodeReference(theEnv,thePattern->nxtTerminal,fp,imageID,maxIndices);
      fprintf(fp,",0L}");

      i++;
      thePattern = thePattern->nxtTerminal;

      if ((i > maxIndices) || (thePattern == NULL))
        {
         fprintf(fp,"};\n");
         GenClose(fp);
         i = 1;
         version++;
         arrayVersion++;
         if (thePattern != NULL)
           {
            if ((fp = NewCFile(theEnv,fileName,fileID,version,FALSE)) == NULL)
              return(0);
            newHeader = TRUE;
           }
        }
      else if (thePattern != NULL)
        { fprintf(fp,",\n"); }
     }

   return(version);
  }
Example #3
0
static void DumpExpression(
  struct expr *exprPtr)
  {

   while (exprPtr != NULL)
     {
      fprintf(ExpressionFP,"{");
      fprintf(ExpressionFP,"%d,",exprPtr->type);
      fprintf(ExpressionFP,"VS ");
      switch (exprPtr->type)
        {
         case FCALL:
           PrintFunctionReference(ExpressionFP,(struct FunctionDefinition *) exprPtr->value);
           break;

         case INTEGER:
           PrintIntegerReference(ExpressionFP,(INTEGER_HN *) exprPtr->value);
           break;

         case FLOAT:
           PrintFloatReference(ExpressionFP,(FLOAT_HN *) exprPtr->value);
           break;

         case PCALL:
#if DEFFUNCTION_CONSTRUCT
           PrintDeffunctionReference(ExpressionFP,(DEFFUNCTION *) exprPtr->value,
                                     ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case GCALL:
#if DEFGENERIC_CONSTRUCT
           PrintGenericFunctionReference(ExpressionFP,(DEFGENERIC *) exprPtr->value,
                                         ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case DEFTEMPLATE_PTR:
#if DEFTEMPLATE_CONSTRUCT
           DeftemplateCConstructReference(ExpressionFP,exprPtr->value,ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case DEFGLOBAL_PTR:
#if DEFGLOBAL_CONSTRUCT
           DefglobalCConstructReference(ExpressionFP,exprPtr->value,ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case DEFCLASS_PTR:
#if OBJECT_SYSTEM
           PrintClassReference(ExpressionFP,(DEFCLASS *) exprPtr->value,ImageID,MaxIndices);
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

          case FACT_ADDRESS:
#if DEFTEMPLATE_CONSTRUCT
           fprintf(ExpressionFP,"&DummyFact");
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case INSTANCE_ADDRESS:
#if OBJECT_SYSTEM
           fprintf(ExpressionFP,"&DummyInstance");
#else
           fprintf(ExpressionFP,"NULL");
#endif
           break;

         case STRING:
         case SYMBOL:
         case INSTANCE_NAME:
         case GBL_VARIABLE:
           PrintSymbolReference(ExpressionFP,(SYMBOL_HN *) exprPtr->value);
           break;

         case RVOID:
           fprintf(ExpressionFP,"NULL");
           break;

         default:
           if (PrimitivesArray[exprPtr->type] == NULL)
             { fprintf(ExpressionFP,"NULL"); }
           else if (PrimitivesArray[exprPtr->type]->bitMap)
             { PrintBitMapReference(ExpressionFP,(BITMAP_HN *) exprPtr->value); }
           else
             { fprintf(ExpressionFP,"NULL"); }
           break;
        }

      fprintf(ExpressionFP,",");

      ExpressionCount++;
      if (exprPtr->argList == NULL)
        { fprintf(ExpressionFP,"NULL,"); }
      else
        {
         fprintf(ExpressionFP,"&E%d_%d[%ld],",ImageID,ExpressionVersion,
                                                       ExpressionCount);
        }

      if (exprPtr->nextArg == NULL)
        { fprintf(ExpressionFP,"NULL}"); }
      else
        {
         fprintf(ExpressionFP,"&E%d_%d[%ld]}",ImageID,ExpressionVersion,
                              ExpressionCount + ExpressionSize(exprPtr->argList));
        }

      if (exprPtr->argList != NULL)
        {
         fprintf(ExpressionFP,",\n");
         DumpExpression(exprPtr->argList);
        }

      exprPtr = exprPtr->nextArg;
      if (exprPtr != NULL) fprintf(ExpressionFP,",\n");
     }
  }
Example #4
0
static int HashTablesToCode(
    char *fileName)
{
    int i;
    FILE *fp;
    struct symbolHashNode **symbolTable;
    struct floatHashNode **floatTable;
    struct integerHashNode **integerTable;
    struct bitMapHashNode **bitMapTable;
#if FUZZY_DEFTEMPLATES
    struct fuzzyValueHashNode **fuzzyValueTable;
#endif

    /*======================================*/
    /* Write the code for the symbol table. */
    /*======================================*/

    symbolTable = GetSymbolTable();

    if ((fp = NewCFile(fileName,1,1,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct symbolHashNode *sht%d[];\n",ImageID);
    fprintf(fp,"struct symbolHashNode *sht%d[%d] = {\n",ImageID,SYMBOL_HASH_SIZE);

    for (i = 0; i < SYMBOL_HASH_SIZE; i++)
    {
        PrintSymbolReference(fp,symbolTable[i]);

        if (i + 1 != SYMBOL_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

    /*=====================================*/
    /* Write the code for the float table. */
    /*=====================================*/

    floatTable = GetFloatTable();

    if ((fp = NewCFile(fileName,1,2,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct floatHashNode *fht%d[];\n",ImageID);
    fprintf(fp,"struct floatHashNode *fht%d[%d] = {\n",ImageID,FLOAT_HASH_SIZE);

    for (i = 0; i < FLOAT_HASH_SIZE; i++)
    {
        if (floatTable[i] == NULL) {
            fprintf(fp,"NULL");
        }
        else PrintFloatReference(fp,floatTable[i]);

        if (i + 1 != FLOAT_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

    /*=======================================*/
    /* Write the code for the integer table. */
    /*=======================================*/

    integerTable = GetIntegerTable();

    if ((fp = NewCFile(fileName,1,3,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct integerHashNode *iht%d[];\n",ImageID);
    fprintf(fp,"struct integerHashNode *iht%d[%d] = {\n",ImageID,INTEGER_HASH_SIZE);

    for (i = 0; i < INTEGER_HASH_SIZE; i++)
    {
        if (integerTable[i] == NULL) {
            fprintf(fp,"NULL");
        }
        else PrintIntegerReference(fp,integerTable[i]);

        if (i + 1 != INTEGER_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

    /*======================================*/
    /* Write the code for the bitmap table. */
    /*======================================*/

    bitMapTable = GetBitMapTable();

    if ((fp = NewCFile(fileName,1,4,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct bitMapHashNode *bmht%d[];\n",ImageID);
    fprintf(fp,"struct bitMapHashNode *bmht%d[%d] = {\n",ImageID,BITMAP_HASH_SIZE);

    for (i = 0; i < BITMAP_HASH_SIZE; i++)
    {
        PrintBitMapReference(fp,bitMapTable[i]);

        if (i + 1 != BITMAP_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

#if FUZZY_DEFTEMPLATES

    /*=============================*/
    /* Dump the fuzzy value table. */
    /*=============================*/

    fuzzyValueTable = GetFuzzyValueTable();

    if ((fp = NewCFile(fileName,1,5,FALSE)) == NULL) return(0);

    fprintf(HeaderFP,"extern struct fuzzyValueHashNode *fvht%d[];\n",ImageID);
    fprintf(fp,"struct fuzzyValueHashNode *fvht%d[%d] = {\n",ImageID,FUZZY_VALUE_HASH_SIZE);

    for (i = 0; i < FUZZY_VALUE_HASH_SIZE; i++)
    {
        PrintFuzzyValueReference(fp,fuzzyValueTable[i]);

        if (i + 1 != FUZZY_VALUE_HASH_SIZE) fprintf(fp,",\n");
    }

    fprintf(fp,"};\n");

    fclose(fp);

#endif /* FUZZY_DEFTEMPLATES */

    return(1);
}