Example #1
0
/* WriteErrorPosition : write a position onto a stream in a GCC like format,
   if the file list has the same value as the previous invocation don't reprint.
   Use format:  filename:line:column:
   or:          In file imported from filename_n:
   from ...
   filename:line:column:
   where the file list has a different value from previous invocation,
   where the file list is NULL just write --:line:column */
void WriteErrorPosition (FILE * stream, tPosition pos)
{
    static FILE *lastStream = NULL;
    static PtrIdentList lastIdentList = NULL;

    if (!pos.File)
    {
        if (pos.Line == 0)      /* line == 0, no idea where we are */
            fprintf (stream, "?:");
        else
            fprintf (stream, "?:%d:%d:", pos.Line, pos.Column);
        return;
    }
    /* Not same as before, at least one other file */
    if ((pos.File != lastIdentList || stream != lastStream) && CDR (pos.File))
    {
        fprintf (stream, "In file imported from ");
        StrPtrIdentList (stream, CDR (pos.File), ":\n                 from ");
        fprintf (stream, ":\n");
    }
    WriteIdent (stream, CAR (pos.File).ident);
    fputc (':', stream);
    if (pos.Line && pos.Column)
        fprintf (stream, "%d:%d:", pos.Line, pos.Column);

    lastStream = stream;
    lastIdentList = pos.File;
}
Example #2
0
/* StrSBreezePosition : write a position to stream in the Breeze format */
extern void StrSBreezePosition (FILE * stream, tPosition pos)
{
    fprintf (stream, "(at %d %d \"", pos.Line, pos.Column);
    if (pos.File)
        WriteIdent (stream, CAR (pos.File).ident);
    fprintf (stream, "\" %d)", pos.CallContext ? ((CallContext *) pos.CallContext)->seqnum : 0);
    if (CallContexts)
    {
        CallContext *callContext = (CallContext *) pos.CallContext; //g_ptr_array_index (CallContexts, pos.CallContext);

        if (callContext)
            callContext->used = TRUE;
    }
}
Example #3
0
static void loop ()
{
   char string [256];
   tIdent ident;

   (void) printf ("enter strings, one per line, - terminates\n");
   do {
      (void) scanf ("%s", string);
      ident = MakeIdent (string, strlen (string));
      WriteIdent (stdout, ident);
      (void) printf ("\n");
   } while (string [0] != '-' || string [1] != '\0');
   (void) printf ("\n");
   WriteIdents ();
}
Example #4
0
/* StrPtrSBreezeProcedure : like StrPtrProcedure but prints in a SBreeze compatible format,
   NB. longForm is ignored */
void StrPtrSBreezeProcedure (FILE * stream, PtrProcedure proc, bool longForm)
{
    if (proc)
    {
        switch (proc->nature)
        {
        case ContextMarkerProcedure:
            fprintf (stream, ";;; context-marker\n");
            break;
        case ParameterisedProcedure:
            PrettyPrintStream = stream;
            fprintf (stream, "(balsa\n  (");
            PrettyPrintProcedureDecl (proc->info.parameterisedProcedure.tree, 1);
            fprintf (stream, ")\n)\n");
            break;
        case ParameterisedBuiltinFunction:
            PrettyPrintStream = stream;
            fprintf (stream, "(balsa\n  (");
            PrettyPrintBuiltinFunctionDecl (proc->info.parameterisedFunction.tree, 1);
            fprintf (stream, ")\n)\n");
            break;
        case UnSharedProcedure:
            CallContext_Str_Reset ();
            fprintf (stream, "(breeze-part \"");
            WriteIdent (stream, proc->ident);
            fprintf (stream, "\"\n  (ports\n    (sync-port \"activate\" passive");
            StrBreezePortOptions (stream, proc->activationOptions, proc->position);
            putc (')', stream);
            if (proc->ports)
            {
                fprintf (stream, "\n    ");
                StrPtrBreezePortList (stream, proc->ports, "\n    ");
            }
            fprintf (stream, "\n  )\n");
            fprintf (stream, "  (attributes\n    (is-procedure)");
            if (proc->isExternal)
                fprintf (stream, "\n    (is-external)");
            if (proc->info.procedure.attributes.permanent)
                fprintf (stream, "\n    (is-permanent)");
            fprintf (stream, "\n    ");
            StrSBreezePosition (stream, proc->position);
            if (proc->userAttributes)
            {
                fprintf (stream, "\n    ");
                StrPtrLispList (stream, proc->userAttributes, "\n    ", " ");
            }
            fprintf (stream, "\n  )\n");
            /* Channels */
            fprintf (stream, "  (channels\n");
            StrPtrSBreezeWires (stream, proc->info.procedure.attributes.wires, "    ");
            fprintf (stream, "  )\n");
            /* Components */
            fprintf (stream, "  (components\n    ");
            StrPtrSBreezeComponentList (stream, proc->info.procedure.attributes.components, "\n    ");
            fprintf (stream, "\n  )\n");
            CallContext_Str_Proc (BreezeOutputFile, proc);
            fprintf (stream, ")\n");
            break;
        case UnSharedFunction:
            CallContext_Str_Reset ();
            fprintf (stream, "(breeze-part \"");
            WriteIdent (stream, proc->ident);
            fprintf (stream, "\"\n  (ports\n    (port \"activate\" passive output ");
            StrPtrSBreezeTypeName (stream, proc->info.function.attributes.value.type);
            StrBreezePortOptions (stream, proc->activationOptions, proc->position);
            putc (')', stream);
            if (proc->ports)
            {
                fprintf (stream, "\n    ");
                StrPtrBreezePortList (stream, proc->ports, "\n    ");
            }
            fprintf (stream, "\n  )\n");
            fprintf (stream, "  (attributes\n    (is-function)");
            if (proc->isExternal)
                fprintf (stream, "\n    (is-external)");
            fprintf (stream, "\n    ");
            StrSBreezePosition (stream, proc->position);
            if (proc->userAttributes)
            {
                fprintf (stream, "\n    ");
                StrPtrLispList (stream, proc->userAttributes, "\n    ", " ");
            }
            fprintf (stream, "\n  )\n");
            /* Channels */
            fprintf (stream, "  (channels\n");
            StrPtrSBreezeWires (stream, proc->info.function.attributes.wires, "    ");
            fprintf (stream, "  )\n");
            /* Components */
            fprintf (stream, "  (components\n    ");
            StrPtrSBreezeComponentList (stream, proc->info.function.attributes.components, "\n    ");
            fprintf (stream, "\n  )\n");
            CallContext_Str_Proc (BreezeOutputFile, proc);
            fprintf (stream, ")\n");
            break;
        case BuiltinFunction:
            fprintf (stream, "(breeze-part \"");
            WriteIdent (stream, proc->ident);
            fprintf (stream, "\"\n  (ports\n    (port \"activate\" passive output ");
            StrPtrSBreezeTypeName (stream, proc->info.function.returnType);
            StrBreezePortOptions (stream, proc->activationOptions, proc->position);
            putc (')', stream);
            if (proc->ports)
            {
                fprintf (stream, "\n    ");
                StrPtrBreezePortList (stream, proc->ports, "\n    ");
            }
            fprintf (stream, "\n  )\n");
            fprintf (stream, "  (attributes\n    (is-builtin-function)");
            if (proc->isExternal)
                fprintf (stream, "\n    (is-external)");
            fprintf (stream, "\n    ");
            StrSBreezePosition (stream, proc->position);
            if (proc->userAttributes)
            {
                fprintf (stream, "\n    ");
                StrPtrLispList (stream, proc->userAttributes, "\n    ", " ");
            }
            fprintf (stream, "\n  )\n");
            /* Channels */
            fprintf (stream, "  (channels\n");
            StrPtrSBreezeWires (stream, proc->info.procedure.attributes.wires, "    ");
            fprintf (stream, "  )\n");
            /* Components */
            fprintf (stream, "  (components)\n");
            fprintf (stream, ")\n");
            break;
        default:
            break;
        }
    }
}
Example #5
0
/* StrPtrBreezePortList : print out the given list's port elements in the SBreeze format */
void StrPtrBreezePortList (FILE * stream, PtrInstanceList ports, char *separator)
{
    while (ports && CAR (ports)->nature != ContextMarkerInstance)
    {
        PtrType type = CAR (ports)->type;

        /* Port format: (sync-port "name" sense) (port "name" passive input type), with arrayed port
           (arrayed-sync-port "name" sense lowIndex n) (arrayed-port "name" sense direction type lowIndex n ) */
        bool isArrayed = type->nature == ArrayedType;
        bool isSync;

        putc ('(', stream);

        if (isArrayed)
            type = type->info.arrayed.baseType; /* Use the base type for arrayed ports */
        isSync = type->nature == SyncType;

        fprintf (stream, "%s%sport \"", (isArrayed ? "arrayed-" : ""), (isSync ? "sync-" : ""));
        WriteIdent (stream, CAR (ports)->ident);
        fprintf (stream, "\" %s", (CAR (ports)->info.port.sense == PassivePortSense ? "passive" : "active"));

        if (!isSync)
        {
            fprintf (stream, " %s ", (CAR (ports)->nature == InputChannelInstance ? "input" : "output"));
            StrPtrBreezeTopLevelType (stream, type);
        }

        if (isArrayed)
        {
            PtrMP_INT arraySize = NewMP_INT (0);

            mpz_sub (arraySize, CAR (ports)->type->info.arrayed.range.upperBound, CAR (ports)->type->info.arrayed.range.lowerBound);
            mpz_add_ui (arraySize, arraySize, 1);

            putc (' ', stream);
            StrPtrMP_INT (stream, CAR (ports)->type->info.arrayed.range.lowerBound);
            putc (' ', stream);
            StrPtrMP_INT (stream, arraySize);
            putc (' ', stream);

            StrPtrBreezeTopLevelType (stream, CAR (ports)->type->info.arrayed.range.boundingType);

            DeleteMP_INT (arraySize);
        }

        if (CAR (ports)->info.port.position.Line != 0)
        {
            putc (' ', stream);
            StrSBreezePosition (stream, CAR (ports)->info.port.position);
        }
        if (CAR (ports)->info.port.options)
        {
            putc (' ', stream);
            StrPtrLispList (stream, CAR (ports)->info.port.options, " ", " ");
        }

        putc (')', stream);
        if (CDR (ports) && CAR (CDR (ports))->nature != ContextMarkerInstance)
            fprintf (stream, "%s", separator);
        ports = CDR (ports);
    }
}