cssymbol.cpp
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C++ 代码 · 共 682 行 · 第 1/2 页
CPP
682 行
/****************************************************************************
*
* 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!
*
****************************************************************************/
#include <string.hpp>
#include <stdlib.h>
#include "common.hpp"
#include "cverror.hpp"
#include "cssymbol.hpp"
#include "symdis.hpp"
extern uint NumLeafLength( const char* );
char* SymbolStruct::_padTable[] = {
NULL,"\0","\0\0","\0\0\0",
};
// unused function section :
bool SymbolStruct::operator == ( const SymbolStruct& ) const
{
throw InternalError("SymbolStruct == gets call");
}
// end section.
SymbolStruct::SymbolStruct( const unsigned_16 length,
const symbol_index leaf )
/****************************************************/
: _length( length ),
_leaf( leaf ),
_offset( 0 ),
_pad( 0 ),
_namePlusVar(NULL,0)
{
Init();
}
SymbolStruct::SymbolStruct( const s_common common )
: _length( common.length ),
_leaf( common.code ),
_offset( 0 ),
_pad( 0 ),
_namePlusVar(NULL,0)
/*************************************************/
{
Init();
}
SymbolStruct::SymbolStruct( const s_common common,
const char* namePVar,
const uint vLen )
: _length( common.length ),
_leaf( common.code ),
_offset( 0 ),
_pad( 0 ),
_namePlusVar(namePVar,vLen)
/*****************************************************/
{
Init();
}
unsigned_8 SymbolStruct::byt_toupper( const unsigned_8 b )
/********************************************************/
{
return ( b&0xdf );
}
unsigned_32 SymbolStruct::dwrd_toupper( const unsigned_32 dw )
/************************************************************/
{
return ( dw&0xdfdfdfdf );
}
// Assume length prefix name.
unsigned_32 SymbolStruct::checkSum( const char* name )
/****************************************************/
{
unsigned_32 cb = *name;
name += BYTE;
unsigned_32 ulEnd = 0;
while ( cb & 3 ) {
ulEnd |= byt_toupper( name[cb-1] );
ulEnd <<= 8;
cb -= 1;
}
unsigned_32 cul = cb/4;
unsigned_32 ulSum = 0;
unsigned_32* lpulName = (unsigned_32 *) name;
for ( unsigned_32 iul = 0; iul < cul; iul++ ) {
ulSum ^= dwrd_toupper(lpulName[iul]);
ulSum = _lrotl(ulSum,4);
}
ulSum ^= ulEnd;
return ulSum;
}
SymbolStruct* SymbolStruct::Error( const char* )
/**********************************************/
{
throw InternalError("encounter undefined symbol in sstSymbol.");
}
SymbolStruct* CSCompile::Construct( const char* ptr )
/***************************************************/
{
return new CSCompile ( * (s_common *) ptr,
* (cs_compile *) (ptr+sizeof(s_common)),
ptr + sizeof(s_compile) );
}
SymbolStruct* CSRegister::Construct( const char* ptr )
/****************************************************/
{
return new CSRegister ( * (s_common *) ptr,
* (cs_register *) (ptr+sizeof(s_common)),
ptr + sizeof(s_register),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_register)));
}
SymbolStruct* CSConstant::Construct( const char* ptr )
/****************************************************/
{
const char* valuePtr = ptr + sizeof(s_common) + sizeof(cs_constant);
unsigned_8 valueLen = NumLeafLength(valuePtr);
const char* varPtr = valuePtr + valueLen;
return new CSConstant ( * (s_common *) ptr,
* (cs_constant *) (ptr+sizeof(s_common)),
valuePtr, valueLen, varPtr,
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_constant)+valueLen));
}
SymbolStruct* CSUdt::Construct( const char* ptr )
/***********************************************/
{
return new CSUdt ( * (s_common *) ptr,
* (cs_udt *) (ptr+sizeof(s_common)),
ptr + sizeof(s_udt),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_udt)));
}
SymbolStruct* CSStartSearch::Construct( const char* ptr )
/*******************************************************/
{
::Warning("language processor emitted start search symbol.");
return new CSStartSearch ( * (s_common *) ptr,
* (cs_ssearch *) (ptr+sizeof(s_common)) );
}
SymbolStruct* CSEndBlock::Construct( const char* ptr )
/****************************************************/
{
return new CSEndBlock ( * (s_common *) ptr);
}
SymbolStruct* CSSkipRecord::Construct( const char* )
/**************************************************/
{
return NULL;
}
SymbolStruct* CSObjName::Construct( const char* ptr )
/***************************************************/
{
return new CSObjName ( * (s_common *) ptr,
* (cs_objname *) (ptr+sizeof(s_common)),
ptr + sizeof(s_objname),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_objname)));
}
SymbolStruct* CSEndOfArg::Construct( const char* ptr )
/****************************************************/
{
return new CSEndOfArg ( * (s_common *) ptr );
}
SymbolStruct* CSCobolUdt::Construct( const char* ptr )
/**************************************************/
{
return new CSCobolUdt ( * (s_common *) ptr,
* (cs_coboludt *) (ptr+sizeof(s_common)),
ptr + sizeof(s_coboludt),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_coboludt)));
}
SymbolStruct* CSManyReg::Construct( const char* ptr )
/***************************************************/
{
return new CSManyReg ( * (s_common *) ptr,
* (cs_manyreg *) (ptr + sizeof(s_common)),
ptr + sizeof(s_manyreg),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_manyreg)));
}
SymbolStruct* CSReturn::Construct( const char* ptr )
/**************************************************/
{
return new CSReturn ( * (s_common *) ptr,
* (cs_return *) (ptr+sizeof(s_common)),
ptr + sizeof(s_return),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_return)));
}
SymbolStruct* CSEntryThis::Construct( const char* ptr )
/*****************************************************/
{
return new CSEntryThis ( * (s_common *) ptr,
SymbolDistributor::CreateSym(ptr+sizeof(s_common)));
}
SymbolStruct* CSBPRel16::Construct( const char* ptr )
/***************************************************/
{
return new CSBPRel16 ( * (s_common *) ptr,
* (cs_bprel16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_bprel16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_bprel16)));
}
SymbolStruct* CSLData16::Construct( const char* ptr )
/***************************************************/
{
return new CSLData16 ( * (s_common *) ptr,
* (cs_ldata16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_ldata16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_ldata16)));
}
SymbolStruct* CSPub16::Construct( const char* ptr )
/**************************************************/
{
return new CSPub16 ( * (s_common *) ptr,
* (cs_pub16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_pub16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_pub16)));
}
SymbolStruct* CSLProc16::Construct( const char* ptr )
/**************************************************/
{
return new CSLProc16 ( * (s_common *) ptr,
* (cs_lproc16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_lproc16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_lproc16)));
}
SymbolStruct* CSThunk16::Construct( const char* ptr )
/**************************************************/
{
return new CSThunk16 ( * (s_common *) ptr,
* (cs_thunk16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_thunk16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_thunk16)));
}
SymbolStruct* CSBlock16::Construct( const char* ptr )
/**************************************************/
{
return new CSBlock16 ( * (s_common *) ptr,
* (cs_block16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_block16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_block16)));
}
SymbolStruct* CSWith16::Construct( const char* ptr )
/**************************************************/
{
return new CSWith16 ( * (s_common *) ptr,
* (cs_with16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_with16) );
}
SymbolStruct* CSLabel16::Construct( const char* ptr )
/**************************************************/
{
return new CSLabel16 ( * (s_common *) ptr,
* (cs_label16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_label16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_label16)));
}
SymbolStruct* CSCExModel16::Construct( const char* ptr )
/*****************************************************/
{
return new CSCExModel16 ( * (s_common *) ptr,
* (cs_cexmodel16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_cexmodel16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_cexmodel16)));
}
SymbolStruct* CSVftPath16::Construct( const char* ptr )
/**************************************************/
{
return new CSVftPath16 ( * (s_common *) ptr,
* (cs_vftpath16 *) (ptr+sizeof(s_common)) );
}
SymbolStruct* CSRegRel16::Construct( const char* ptr )
/**************************************************/
{
return new CSRegRel16 ( * (s_common *) ptr,
* (cs_regrel16 *) (ptr+sizeof(s_common)),
ptr + sizeof(s_regrel16),
GetVarLength(*(unsigned_8 *)ptr,sizeof(cs_regrel16)));
}
SymbolStruct* CSBPRel32::Construct( const char* ptr )
/***************************************************/
{
return new CSBPRel32 ( * (s_common *) ptr,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?