cssymbol.hpp

来自「开放源码的编译器open watcom 1.6.0版的源代码」· HPP 代码 · 共 1,573 行 · 第 1/3 页

HPP
1,573
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
*               DESCRIBE IT HERE!
*
****************************************************************************/


#ifndef CSSYMBOL_H_INCLUDED
#define CSSYMBOL_H_INCLUDED

#include <stdlib.h>
#include <string.hpp>
#include "typemap.hpp"
#include "retrieve.hpp"
#include "makeexe.hpp"

extern TypeIndexMap TypeMap;

class SymbolStruct;

typedef unsigned_16 symbol_index;

static const NO_SEGMENT = 0xffff;
static const NO_OFFSET = 0xffff;

//
// basic size of a symbol record.
//
static const BASICSIZE = WORD;
static const REF_RECORD_LENGTH = 12;
static const NO_CHKSUM = 0;

class SymbolStruct {

    public :

        SymbolStruct() : _namePlusVar(NULL,0) { }

        SymbolStruct( const unsigned_16, const symbol_index );

        SymbolStruct( const s_common common );

        SymbolStruct( const s_common, const char*, const uint );

        virtual ~SymbolStruct() { }

        void Put( ExeMaker& ) const;

        virtual uint CodeSegment() const {
            return NO_SEGMENT;
        }

        virtual uint DataSegment() const {
            return NO_SEGMENT;
        }

        virtual uint MemOffset() const {
            return NO_OFFSET;
        }

        virtual void SetParent( const unsigned_32 ) { }
        virtual void SetNext( const unsigned_32 ) { }
        virtual void SetEnd( const unsigned_32 ) { }
        virtual void FixType() { }

        virtual bool IsStartSym() const {
            return FALSE;
        }

        virtual unsigned_32 cSum() const {
            if ( _namePlusVar._strLen > 0 ) {
                if ( *_namePlusVar._string > 0 ) {
                    return checkSum(_namePlusVar._string);
                }
            }
            return NO_CHKSUM;
        }

        // for the sake of link list.
        bool operator == ( const SymbolStruct& ) const;

        void SetOffset( const unsigned_32 offset ) {
            _offset = offset;
        }

        // length including length field.
        uint Length() const {
            return _length + WORD;
        }

        unsigned_32 Offset() const {
            return _offset;
        }

        bool IsGlobalProc() const {
            return ( _leaf == S_GPROC16 || _leaf == S_GPROC32 );
        }

        bool IsStaticData() const {
            return ( _leaf == S_LDATA16 ||
                     _leaf == S_LDATA32 ||
                     _leaf == S_LTHREAD32 );
        }

        bool IsStaticProc() const {
            return ( _leaf == S_LPROC16 || _leaf == S_LPROC32 );
        }

        bool IsEndSym() const {
            return ( _leaf == S_END );
        }

        bool IsModuleSpecific() const {
            return ( _leaf == S_OBJNAME || _leaf == S_COMPILE );
        }

/*        const unsigned_8 NameLen() const { // to be deleted.
            if ( _name != NULL ) {
                return *_name+1;
            }
            return 0;
        } */

        // Virtual func since ref syms define a different version.
        virtual const char* Name() const {
            return ( _namePlusVar._string );
        }

        static SymbolStruct* Error( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const { }

        static uint GetVarLength( const uint totalLen,
                                  const uint structLen ) {
            return ( totalLen - BASICSIZE - structLen );
        }

    private :

        unsigned_8 PadToAlign( const uint length ) {
            if ( length % LONG_WORD != 0 ) {
                return (unsigned_8) ( LONG_WORD - length % LONG_WORD );
            }
            return 0;
        }

        void Init() {
            _pad = PadToAlign(_length + WORD);
            _length += _pad;
        }
        static unsigned_8 byt_toupper( const unsigned_8 );
        static unsigned_32 dwrd_toupper( const unsigned_32 );
        static unsigned_32 checkSum( const char* );

        static char*    _padTable[];

        unsigned_16     _length;
        symbol_index    _leaf;
        unsigned_32     _offset;
        unsigned_8      _pad;
        VariantString   _namePlusVar;
};

class CSCompile : public SymbolStruct {

    public :

        CSCompile ( const s_common     common,
                    const cs_compile   compile,
                    const char*        lpVersion )
                : SymbolStruct( common ),
                  _compile( compile ) {
            _verlen = common.length - sizeof(cs_compile) - WORD;
            _version = new char [_verlen];
            memcpy( _version,lpVersion, _verlen );
        }

        ~CSCompile() {
            delete [] _version;
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_compile      _compile;
        char*           _version;
        unsigned        _verlen;
};

//
// Does not implement register tracking.  Should be added once its format
// is available.
//
class CSRegister : public SymbolStruct {

    public :

        CSRegister ( const s_common     common,
                     const cs_register  registerStruct,
                     const char*        var,
                     const uint         varLen )
                : SymbolStruct( common, var, varLen ),
                  _register( registerStruct ) { }

        ~CSRegister() { }

        void FixType() {
            _register.type = TypeMap.Lookup(_register.type);
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_register      _register;
};

class CSConstant : public SymbolStruct {

    public :

        CSConstant ( const s_common     common,
                     const cs_constant  constant,
                     const char*        valuePtr,
                     const uint         valueLen ,
                     const char*        var,
                     const uint         varLen )
                : SymbolStruct( common, var, varLen),
                  _constant( constant ),
                  _value( valuePtr, valueLen ) { }

        ~CSConstant() { }

        void FixType() {
            _constant.type = TypeMap.Lookup(_constant.type);
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_constant      _constant;
        VariantString    _value;
};

class CSUdt : public SymbolStruct {

    public :

        CSUdt ( const s_common     common,
                const cs_udt       udt,
                const char*        var,
                const uint         varLen )
            : SymbolStruct( common, var, varLen ),
              _udt( udt ) { }

        ~CSUdt() { }

        void FixType() {
            _udt.type = TypeMap.Lookup(_udt.type);
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_udt      _udt;
};

class CSStartSearch : public SymbolStruct {

    public :

        CSStartSearch ( const s_common     common,
                        const cs_ssearch&  ssearch )
                : SymbolStruct( common ),
                  _ssearch( ssearch ) { }

        CSStartSearch( const unsigned_32 seg )
                : SymbolStruct( 8, S_SSEARCH ) {
            _ssearch.segment = seg;
        }

        void SetNext( const unsigned_32 offset ) {
            _ssearch.sym_off = offset;
        }

        ~CSStartSearch() { }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_ssearch      _ssearch;
};

class CSEndBlock : public SymbolStruct {

    public :

        CSEndBlock ( const s_common common )
                : SymbolStruct( common ) { }

        ~CSEndBlock() { }

        static SymbolStruct* Construct( const char* );
};

class CSSkipRecord {

    public :

        static SymbolStruct* Construct( const char* );
};

class CSObjName : public SymbolStruct {

    public :

        CSObjName ( const s_common     common,
                    const cs_objname   objName,
                    const char*        var,
                    const uint         varLen )
                : SymbolStruct( common, var, varLen ),
                  _objName( objName ) { }

        ~CSObjName() { }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_objname      _objName;
};

class CSEndOfArg : public SymbolStruct {

    public :

        CSEndOfArg ( const s_common common )
                : SymbolStruct( common ) { }

        ~CSEndOfArg() { }

        static SymbolStruct* Construct( const char* );
};

class CSCobolUdt : public SymbolStruct {

    public :

        CSCobolUdt ( const s_common     common,
                     const cs_coboludt  cobolUdt,
                     const char*        var,
                     const uint         varLen )
                : SymbolStruct( common, var, varLen ),
                  _cobolUdt( cobolUdt ) { }

        ~CSCobolUdt() { }

        void FixType() {
            _cobolUdt.type = TypeMap.Lookup(_cobolUdt.type);
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_coboludt      _cobolUdt;
};

class CSManyReg : public SymbolStruct {

    public :

        CSManyReg ( const s_common     common,
                    const cs_manyreg   manyReg,
                    const char*        buffer,
                    const uint         len )
                : SymbolStruct( common,buffer+manyReg.count,len-manyReg.count),
                  _manyReg( manyReg ),
                  _regList( buffer, manyReg.count ) { }

        ~CSManyReg() { }

        void FixType() {
            _manyReg.type = TypeMap.Lookup(_manyReg.type);
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_manyreg      _manyReg;
        VariantString   _regList;
};

class CSReturn : public SymbolStruct {

    public :

        CSReturn ( const s_common     common,
                   const cs_return    returnStruct,
                   const char*        data,
                   const uint         dataLen )
                : SymbolStruct( common ),
                  _return( returnStruct ),
                  _data( data, dataLen ) { }

        ~CSReturn() { }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        cs_return      _return;
        VariantString  _data;
};

class CSEntryThis : public SymbolStruct {

    public :

        CSEntryThis ( const s_common common,
                      SymbolStruct*  symPtr )
                : SymbolStruct( common ),
                  _symPtr( symPtr ) { }

        ~CSEntryThis() {
            delete _symPtr;
        }

        static SymbolStruct* Construct( const char* );

    protected:

        virtual void DerivedPut( ExeMaker& ) const;

    private :

        SymbolStruct*   _symPtr;
};

class CSBPRel16 : public SymbolStruct {

    public :

        CSBPRel16 ( const s_common     common,
                    const cs_bprel16   bpRel16,
                    const char*        var,
                    const uint         varLen )
                : SymbolStruct( common, var, varLen ),
                  _bpRel16( bpRel16 ) { }

        ~CSBPRel16() { }

        void FixType() {
            _bpRel16.type = TypeMap.Lookup(_bpRel16.type);
        }

        static SymbolStruct* Construct( const char* );

⌨️ 快捷键说明

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