Exemple #1
0
void WriteImports (void)
/* Write the imports list to the object file */
{
    SymEntry* S;

    /* Tell the object file module that we're about to start the imports */
    ObjStartImports ();

    /* Write the import count to the list */
    ObjWriteVar (ImportCount);

    /* Walk throught list and write all valid imports to the file. An import
    ** is considered valid, if it is either referenced, or the forced bit is
    ** set. Otherwise, the import is ignored (no need to link in something
    ** that isn't used).
    */
    S = SymList;
    while (S) {
        if ((S->Flags & (SF_UNUSED | SF_IMPORT)) == SF_IMPORT &&
            (S->Flags & (SF_REFERENCED | SF_FORCED)) != 0) {

            ObjWrite8 (S->AddrSize);
            ObjWriteVar (S->Name);
            WriteLineInfo (&S->DefLines);
            WriteLineInfo (&S->RefLines);
        }
        S = S->List;
    }

    /* Done writing imports */
    ObjEndImports ();
}
Exemple #2
0
void WriteOptions (void)
/* Write the options to the object file */
{
    Option* O;

    /* Tell the object file module that we're about to start the options */
    ObjStartOptions ();

    /* Write the option count */
    ObjWriteVar (OptCount);

    /* Walk through the list and write the options */
    O = OptRoot;
    while (O) {

	/* Write the type of the option, then the value */
	ObjWrite8 (O->Type);
        ObjWriteVar (O->Val);

	/* Next option */
	O = O->Next;

    }

    /* Done writing options */
    ObjEndOptions ();
}
Exemple #3
0
void WriteAssertions (void)
/* Write the assertion table to the object file */
{
    unsigned I;

    /* Get the number of assertions */
    unsigned Count = CollCount (&Assertions);

    /* Tell the object file module that we're about to start the assertions */
    ObjStartAssertions ();

    /* Write the string count to the list */
    ObjWriteVar (Count);

    /* Write the assertions */
    for (I = 0; I < Count; ++I) {

        /* Get the next assertion */
        Assertion* A = CollAtUnchecked (&Assertions, I);

        /* Write it to the file */
        WriteExpr (A->Expr);
        ObjWriteVar ((unsigned) A->Action);
        ObjWriteVar (A->Msg);
        WriteLineInfo (&A->LI);
    }

    /* Done writing the assertions */
    ObjEndAssertions ();
}
Exemple #4
0
void WriteHLLDbgSyms (void)
/* Write a list of all high level language symbols to the object file. */
{
    unsigned I;

    /* Only if debug info is enabled */
    if (DbgSyms) {

        /* Write the symbol count to the list */
        ObjWriteVar (CollCount (&HLLDbgSyms));

        /* Walk through list and write all symbols to the file. */
        for (I = 0; I < CollCount (&HLLDbgSyms); ++I) {

            /* Get the next symbol */
            HLLDbgSym* S = CollAtUnchecked (&HLLDbgSyms, I);

            /* Get the type of the symbol */
            unsigned SC = HLL_GET_SC (S->Flags);

            /* Remember if the symbol has debug info attached
            ** ### This should go into DbgInfoCheck
            */
            if (S->Sym && S->Sym->DebugSymId != ~0U) {
                S->Flags |= HLL_DATA_SYM;
            }

            /* Write the symbol data */
            ObjWriteVar (S->Flags);
            ObjWriteVar (S->Name);
            if (HLL_HAS_SYM (S->Flags)) {
                ObjWriteVar (S->Sym->DebugSymId);
            }
            if (SC == HLL_SC_AUTO || SC == HLL_SC_REG) {
                ObjWriteVar (S->Offs);
            }
            ObjWriteVar (S->Type);
            ObjWriteVar (S->Scope->Id);
        }

    } else {

        /* Write a count of zero */
        ObjWriteVar (0);

    }
}
Exemple #5
0
void WriteFiles (void)
/* Write the list of input files to the object file */
{
    unsigned I;

    /* Tell the obj file module that we're about to start the file list */
    ObjStartFiles ();

    /* Write the file count */
    ObjWriteVar (CollCount (&FileTab));

    /* Write the file data */
    for (I = 0; I < CollCount (&FileTab); ++I) {
        /* Get a pointer to the entry */
        const FileEntry* F = CollConstAt (&FileTab, I);
        /* Write the fields */
        ObjWriteVar (F->Name);
        ObjWrite32 (F->MTime);
        ObjWriteVar (F->Size);
    }

    /* Done writing files */
    ObjEndFiles ();
}
Exemple #6
0
void WriteScopes (void)
/* Write the scope table to the object file */
{
    /* Tell the object file module that we're about to start the scopes */
    ObjStartScopes ();

    /* We will write scopes only if debug symbols are requested */
    if (DbgSyms) {

        /* Get head of list */
        SymTable* S = RootScope;

        /* Write the scope count to the file */
        ObjWriteVar (ScopeCount);

        /* Walk through all scopes and write them to the file */
        while (S) {

            /* Flags for this scope */
            unsigned Flags = 0;

            /* Check if this scope has a size. If so, remember it in the
            ** flags.
            */
            long Size;
            SymEntry* SizeSym = FindSizeOfScope (S);
            if (SizeSym != 0 && SymIsConst (SizeSym, &Size)) {
                Flags |= SCOPE_SIZE;
            }

            /* Check if the scope has a label */
            if (S->Label) {
                Flags |= SCOPE_LABELED;
            }

            /* Scope must be defined */
            CHECK (S->Type != SCOPE_UNDEF);

            /* Id of parent scope */
            if (S->Parent) {
                ObjWriteVar (S->Parent->Id);
            } else {
                ObjWriteVar (0);
            }

            /* Lexical level */
            ObjWriteVar (S->Level);

            /* Scope flags */
            ObjWriteVar (Flags);

            /* Type of scope */
            ObjWriteVar (S->Type);

            /* Name of the scope */
            ObjWriteVar (S->Name);

            /* If the scope has a size, write it to the file */
            if (SCOPE_HAS_SIZE (Flags)) {
                ObjWriteVar (Size);
            }

            /* If the scope has a label, write its id to the file */
            if (SCOPE_HAS_LABEL (Flags)) {
                ObjWriteVar (S->Label->DebugSymId);
            }

            /* Spans for this scope */
            WriteSpanList (&S->Spans);

            /* Next scope */
            S = S->Next;
        }

    } else {

        /* No debug info requested */
        ObjWriteVar (0);

    }

    /* Done writing the scopes */
    ObjEndScopes ();
}
Exemple #7
0
void WriteDbgSyms (void)
/* Write a list of all symbols to the object file */
{
    unsigned Count;
    SymEntry* S;

    /* Tell the object file module that we're about to start the debug info */
    ObjStartDbgSyms ();

    /* Check if debug info is requested */
    if (DbgSyms) {

        /* Walk through the list, give each symbol an id and count them */
        Count = 0;
        S = SymList;
        while (S) {
            if (IsDbgSym (S)) {
                S->DebugSymId = Count++;
            }
            S = S->List;
        }

        /* Write the symbol count to the list */
        ObjWriteVar (Count);

        /* Walk through list and write all symbols to the file. Ignore size
        ** symbols.
        */
        S = SymList;
        while (S) {
            if (IsDbgSym (S)) {

                /* Get the expression bits and the value */
                long ConstVal;
                unsigned SymFlags = GetSymInfoFlags (S, &ConstVal);

                /* Check if this symbol has a size. If so, remember it in the
                ** flags.
                */
                long Size;
                SymEntry* SizeSym = FindSizeOfSymbol (S);
                if (SizeSym != 0 && SymIsConst (SizeSym, &Size)) {
                    SymFlags |= SYM_SIZE;
                }

                /* Write the type */
                ObjWriteVar (SymFlags);

                /* Write the address size */
                ObjWrite8 (S->AddrSize);

                /* Write the id of the parent. For normal symbols, this is a
                ** scope (symbol table), for cheap locals, it's a symbol.
                */
                if (SYM_IS_STD (SymFlags)) {
                    ObjWriteVar (S->Sym.Tab->Id);
                } else {
                    ObjWriteVar (S->Sym.Entry->DebugSymId);
                }

                /* Write the name */
                ObjWriteVar (S->Name);

                /* Write the value */
                if (SYM_IS_CONST (SymFlags)) {
                    /* Constant value */
                    ObjWrite32 (ConstVal);
                } else {
                    /* Expression involved */
                    WriteExpr (S->Expr);
                }

                /* If the symbol has a size, write it to the file */
                if (SYM_HAS_SIZE (SymFlags)) {
                    ObjWriteVar (Size);
                }

                /* If the symbol is an im- or export, write out the ids */
                if (SYM_IS_IMPORT (SymFlags)) {
                    ObjWriteVar (GetSymImportId (S));
                }
                if (SYM_IS_EXPORT (SymFlags)) {
                    ObjWriteVar (GetSymExportId (S));
                }

                /* Write the line infos */
                WriteLineInfo (&S->DefLines);
                WriteLineInfo (&S->RefLines);
            }
            S = S->List;
        }

    } else {

        /* No debug symbols */
        ObjWriteVar (0);

    }

    /* Write the high level symbols */
    WriteHLLDbgSyms ();

    /* Done writing debug symbols */
    ObjEndDbgSyms ();
}
Exemple #8
0
void WriteExports (void)
/* Write the exports list to the object file */
{
    SymEntry* S;
    unsigned Type;

    /* Tell the object file module that we're about to start the exports */
    ObjStartExports ();

    /* Write the export count to the list */
    ObjWriteVar (ExportCount);

    /* Walk throught list and write all exports to the file */
    S = SymList;
    while (S) {
        if ((S->Flags & (SF_UNUSED | SF_EXPORT)) == SF_EXPORT) {

            /* Get the expression bits and the value */
            long ConstVal;
            unsigned SymFlags = GetSymInfoFlags (S, &ConstVal);

            /* Check if this symbol has a size. If so, remember it in the
            ** flags.
            */
            long Size;
            SymEntry* SizeSym = FindSizeOfSymbol (S);
            if (SizeSym != 0 && SymIsConst (SizeSym, &Size)) {
                SymFlags |= SYM_SIZE;
            }

            /* Count the number of ConDes types */
            for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
                if (S->ConDesPrio[Type] != CD_PRIO_NONE) {
                    SYM_INC_CONDES_COUNT (SymFlags);
                }
            }

            /* Write the type and the export size */
            ObjWriteVar (SymFlags);
            ObjWrite8 (S->ExportSize);

            /* Write any ConDes declarations */
            if (SYM_GET_CONDES_COUNT (SymFlags) > 0) {
                for (Type = 0; Type < CD_TYPE_COUNT; ++Type) {
                    unsigned char Prio = S->ConDesPrio[Type];
                    if (Prio != CD_PRIO_NONE) {
                        ObjWrite8 (CD_BUILD (Type, Prio));
                    }
                }
            }

            /* Write the name */
            ObjWriteVar (S->Name);

            /* Write the value */
            if (SYM_IS_CONST (SymFlags)) {
                /* Constant value */
                ObjWrite32 (ConstVal);
            } else {
                /* Expression involved */
                WriteExpr (S->Expr);
            }

            /* If the symbol has a size, write it to the file */
            if (SYM_HAS_SIZE (SymFlags)) {
                ObjWriteVar (Size);
            }

            /* Write the line infos */
            WriteLineInfo (&S->DefLines);
            WriteLineInfo (&S->RefLines);
        }
        S = S->List;
    }

    /* Done writing exports */
    ObjEndExports ();
}