Ejemplo n.º 1
0
Export* ReadExport (FILE* F, ObjData* O)
/* Read an export from a file */
{
    unsigned      ConDesCount;
    Export* E;

    /* Read the type */
    unsigned char Type = Read8 (F);

    /* Read the address size */
    unsigned char AddrSize = Read8 (F);

    /* Create a new export without a name */
    E = NewExport (Type, AddrSize, INVALID_STRING_ID, O);

    /* Read the constructor/destructor decls if we have any */
    ConDesCount = GET_EXP_CONDES_COUNT (Type);
    if (ConDesCount > 0) {

	unsigned char ConDes[CD_TYPE_COUNT];
	unsigned I;

	/* Read the data into temp storage */
	ReadData (F, ConDes, ConDesCount);

	/* Re-order the data. In the file, each decl is encoded into a byte
	 * which contains the type and the priority. In memory, we will use
	 * an array of types which contain the priority. This array was
	 * cleared by the constructor (NewExport), so we must only set the
	 * fields that contain values.
	 */
	for (I = 0; I < ConDesCount; ++I) {
	    unsigned ConDesType = CD_GET_TYPE (ConDes[I]);
	    unsigned ConDesPrio = CD_GET_PRIO (ConDes[I]);
	    E->ConDes[ConDesType] = ConDesPrio;
	}
    }

    /* Read the name */
    E->Name = MakeGlobalStringId (O, ReadVar (F));

    /* Read the value */
    if (IS_EXP_EXPR (Type)) {
       	E->Expr = ReadExpr (F, O);
    } else {
     	E->Expr = LiteralExpr (Read32 (F), O);
    }

    /* Last is the file position where the definition was done */
    ReadFilePos (F, &E->Pos);

    /* Return the new export */
    return E;
}
Ejemplo n.º 2
0
static const char* GetExportFlags (unsigned Flags, const unsigned char* ConDes)
/* Get the export flags as a (static) string */
{
    /* Static buffer */
    static char TypeDesc[256];
    static char* T;

    unsigned Count;
    unsigned I;

    /* Symbol type */
    TypeDesc[0] = '\0';
    switch (Flags & SYM_MASK_TYPE) {
       	case SYM_STD:         strcat (TypeDesc, "SYM_STD");         break;
       	case SYM_CHEAP_LOCAL: strcat (TypeDesc, "SYM_CHEAP_LOCAL"); break;
    }

    /* Symbol usage */
    switch (Flags & SYM_MASK_LABEL) {
       	case SYM_EQUATE: strcat (TypeDesc, ",SYM_EQUATE"); break;
       	case SYM_LABEL:  strcat (TypeDesc, ",SYM_LABEL");  break;
    }

    /* Type of expression */
    switch (Flags & SYM_MASK_VAL) {
       	case SYM_CONST: strcat (TypeDesc, ",SYM_CONST"); break;
       	case SYM_EXPR:  strcat (TypeDesc, ",SYM_EXPR");   break;
    }

    /* Size available? */
    if (SYM_HAS_SIZE (Flags)) {
        strcat (TypeDesc, ",SYM_SIZE");
    }


    /* Constructor/destructor declarations */
    T = TypeDesc + strlen (TypeDesc);
    Count = SYM_GET_CONDES_COUNT (Flags);
    if (Count > 0 && ConDes) {
     	T += sprintf (T, ",SYM_CONDES=");
     	for (I = 0; I < Count; ++I) {
     	    unsigned Type = CD_GET_TYPE (ConDes[I]);
     	    unsigned Prio = CD_GET_PRIO (ConDes[I]);
     	    if (I > 0) {
     		*T++ = ',';
     	    }
       	    T += sprintf (T, "[%u,%u]", Type, Prio);
     	}
    }

    /* Return the result */
    return TypeDesc;
}
Ejemplo n.º 3
0
Export* ReadExport (FILE* F, ObjData* O)
/* Read an export from a file */
{
    unsigned    ConDesCount;
    unsigned    I;
    Export*     E;

    /* Read the type */
    unsigned Type = ReadVar (F);

    /* Read the address size */
    unsigned char AddrSize = Read8 (F);

    /* Create a new export without a name */
    E = NewExport (Type, AddrSize, INVALID_STRING_ID, O);

    /* Read the constructor/destructor decls if we have any */
    ConDesCount = SYM_GET_CONDES_COUNT (Type);
    if (ConDesCount > 0) {

        unsigned char ConDes[CD_TYPE_COUNT];

        /* Read the data into temp storage */
        ReadData (F, ConDes, ConDesCount);

        /* Re-order the data. In the file, each decl is encoded into a byte
        ** which contains the type and the priority. In memory, we will use
        ** an array of types which contain the priority.
        */
        for (I = 0; I < ConDesCount; ++I) {
            E->ConDes[CD_GET_TYPE (ConDes[I])] = CD_GET_PRIO (ConDes[I]);
        }
    }

    /* Read the name */
    E->Name = MakeGlobalStringId (O, ReadVar (F));

    /* Read the value */
    if (SYM_IS_EXPR (Type)) {
        E->Expr = ReadExpr (F, O);
    } else {
        E->Expr = LiteralExpr (Read32 (F), O);
    }

    /* Read the size */
    if (SYM_HAS_SIZE (Type)) {
        E->Size = ReadVar (F);
    }

    /* Last are the locations */
    ReadLineInfoList (F, O, &E->DefLines);
    ReadLineInfoList (F, O, &E->RefLines);

    /* If this symbol is exported as a condes, and the condes type declares a
    ** forced import, add this import to the object module.
    */
    for (I = 0; I < CD_TYPE_COUNT; ++I) {
        const ConDesImport* CDI;

        if (E->ConDes[I] != CD_PRIO_NONE && (CDI = ConDesGetImport (I)) != 0) {
            unsigned J;

            /* Generate a new import, and add it to the module's import list. */
            Import* Imp = GenImport (CDI->Name, CDI->AddrSize);

            Imp->Obj = O;
            CollAppend (&O->Imports, Imp);

            /* Add line info for the export that is actually the condes that
            ** forces the import.  Then, add line info for the config. file.
            ** The export's info is added first because the import pretends
            ** that it came from the object module instead of the config. file.
            */
            for (J = 0; J < CollCount (&E->DefLines); ++J) {
                CollAppend (&Imp->RefLines, DupLineInfo (CollAt (&E->DefLines, J)));
            }
            CollAppend (&Imp->RefLines, GenLineInfo (&CDI->Pos));
        }
    }

    /* Return the new export */
    return E;
}