process.c
来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 1,633 行 · 第 1/4 页
C
1,633 行
static void doDLLExport( void )
{
byte exp_flag;
unsigned_16 ordinal;
exp_flag = GetByte();
if( exp_flag & 0x80 ) {
Output( INDENT "DLL Export by Ordinal" CRLF );
} else {
Output( INDENT "DLL Export by Name" CRLF );
}
GetName();
Output( INDENT "Exported Name: %N " );
if( GetName() > 0 )
Output( "Internal Name: %N" );
if( exp_flag & 0x80 ) {
ordinal = GetUInt();
Output( "@%u", ordinal );
}
Output( CRLF );
}
static int doOMFExt( void )
{
byte subtype;
subtype = GetByte();
switch( subtype ) {
case DLL_IMPDEF:
doDLLImport();
return( 1 );
case DLL_EXPDEF:
doDLLExport();
return( 1 );
default:
Output( INDENT "Unknown OMF extension (subtype %x)" CRLF, subtype );
}
return( 0 );
}
void ProcComent( void )
/*********************/
{
byte c_bits;
byte c_class;
int dont_print;
c_bits = GetByte();
c_class = GetByte();
Output( INDENT "bits %b, class %b" CRLF, c_bits, c_class );
dont_print = 0;
if( InterpretComent ) {
switch( c_class ) {
case CMT_LZEXT:
Output( INDENT "Lazy extern (will search libs):" CRLF );
doWeakLazyExtern();
dont_print = 1;
break;
case CMT_WKEXT:
Output( INDENT "Weak extern (won't search libs):" CRLF );
doWeakLazyExtern();
dont_print = 1;
break;
case CMT_DEPENDENCY:
Output( INDENT "Borland Dependency:" CRLF );
doDependency();
dont_print = 1;
break;
case CMT_LANGUAGE_TRANS:
Output( INDENT "Language Translator:" CRLF );
break;
case CMT_WAT_PROC_MODEL:
Output( INDENT "WATCOM Compile parameters:" CRLF );
doProcModel();
dont_print = 1;
break;
case CMT_MS_PROC_MODEL:
Output( INDENT "Microsoft Compile parameters:" CRLF );
doProcModel();
dont_print = 1;
break;
case CMT_DOSSEG:
Output( INDENT "DOSSEG Segment Ordering" CRLF );
break;
case CMT_DEFAULT_LIBRARY:
Output( INDENT "Default Library: \"%R\"" CRLF );
dont_print = 1;
break;
case CMT_DLL_ENTRY:
Output( INDENT "OMF Extension" CRLF );
dont_print = doOMFExt();
break;
case CMT_MS_OMF:
dont_print = doMSOmf();
break;
case CMT_MS_END_PASS_1:
Output( INDENT "End of Linker Pass 1" CRLF );
break;
case CMT_EASY_OMF:
dont_print = doEasyOmf( c_bits );
break;
case CMT_DISASM_DIRECTIVE:
dont_print = doDisasmDirective();
break;
case CMT_LINKER_DIRECTIVE:
dont_print = doLinkerDirective();
break;
}
} else {
/* we have to interpret these in order to handle the object file
properly */
switch( c_class ) {
case CMT_EASY_OMF:
dont_print = doEasyOmf( c_bits );
break;
case CMT_MS_OMF:
dont_print = doMSOmf();
break;
}
}
if( ! ( dont_print || EndRec() ) ) {
OutputData( 0L, 0L );
}
}
void ProcLNames( unsigned_16 *index )
/***********************************/
{
while( ! EndRec() ) {
GetName();
AddLname();
Output( INDENT "%u - %N" CRLF, ++(*index) );
}
}
void ProcNames( unsigned_16 *index )
/**********************************/
{
while( ! EndRec() ) {
GetName();
Output( INDENT "%u - %N" CRLF, ++(*index) );
}
}
void ProcExtNames( void )
/***********************/
{
while( ! EndRec() ) {
GetName();
if( TranslateIndex ) {
AddXname();
}
Output( INDENT "%u - %N Type:%u" CRLF, ++Importindex, GetIndex() );
}
}
void ProcComExtDef( void )
/************************/
{
unsigned name;
unsigned typ;
while( ! EndRec() ) {
name = GetIndex();
typ = GetIndex();
Output(INDENT "%u - LNAME:%u Type:%u" CRLF, ++Importindex, name, typ);
if( TranslateIndex ) {
Output( INDENT " - '%s'\n", GetXname( name ) );
}
}
}
static const char *oldAlign[] = {
/*ALIGN_ABS */ "ABS",
/*ALIGN_BYTE */ "BYTE",
/*ALIGN_WORD */ "WORD",
/*ALIGN_PARA */ "PARA",
/*ALIGN_PAGE */ "PAGE",
/*ALIGN_UNABS */ "UNABS",
/*ALIGN_LTRELOC */ "LTL"
};
static const char *newAlign[] = {
/*ALIGN_ABS */ "ABS",
/*ALIGN_BYTE */ "BYTE",
/*ALIGN_WORD */ "WORD",
/*ALIGN_PARA */ "PARA",
/*ALIGN_PAGE */ "PAGE",
/*ALIGN_DWORD */ "DWORD",
/*ALIGN_4KPAGE */ "PAGE4K"
};
static const char *segComb[] = {
/*COMB_INVALID */ "PRIVATE",
/*COMB_ABOVEALL */ "ABOVEALL",
/*COMB_ADDOFF */ "PUBLIC",
/*COMB_BAD */ "***bad***",
/*COMB_FOUR */ "TYPE 4",
/*COMB_STACK */ "STACK",
/*COMB_COMMON */ "COMMON",
/*COMB_ALIGNTOP */ "ALIGNTOP"
};
void ProcSegDefs( void )
/**********************/
{
byte acbp;
byte align;
unsigned_32 length;
byte comb;
byte phar_attr;
const char *phar_access;
unsigned_16 abs_frame;
unsigned_32 abs_offset;
byte ltl_dat;
unsigned_16 ltl_len;
unsigned_16 ltl_offset;
unsigned_16 seg;
unsigned_16 class;
unsigned_16 ovl;
int use32;
++Segindex;
acbp = GetByte();
align = acbp >> 5;
if( align >= ALIGN_4KPAGE ) {
Output( BAILOUT "Unknown align, acbp=%b" CRLF, acbp );
longjmp( BailOutJmp, 1 );
}
comb = ( acbp >> 2 ) & 7;
switch( align ) {
case ALIGN_UNABS:
if( !IsIntel ) break;
/* FALL THROUGH */
case ALIGN_ABS:
abs_frame = GetUInt();
/* note MS386 has a 16bit quantity here */ // !!! offset should be only 8-bit
abs_offset = ( IsPharLap ) ? GetLInt() : GetByte();
break;
case ALIGN_LTRELOC:
if( IsIntel ) {
ltl_dat = GetByte();
ltl_len = GetUInt();
ltl_offset = GetUInt();
}
break;
}
length = GetEither();
if( acbp & 2 ) {
length = 0x10000; /* FIXME - should handle 4G segments */
}
if( !IsIntel || align != ALIGN_UNABS ) {
seg = GetIndex();
class = GetIndex();
ovl = GetIndex();
}
phar_access = NULL;
if( IsPharLap && EndRec() == FALSE ) {
phar_attr = GetByte();
use32 = phar_attr & EASY_USE32_FIELD;
phar_attr &= EASY_PROTECT_FIELD;
switch( phar_attr ) {
case EASY_READ_ONLY: phar_access = " RO"; break;
case EASY_EXEC_ONLY: phar_access = " EO"; break;
case EASY_EXEC_READ: phar_access = " ER"; break;
case EASY_READ_WRITE: phar_access = " RW"; break;
}
} else if( IsPharLap || ( !IsIntel && ( acbp & 1 ) ) ) {
use32 = 1;
} else {
use32 = 0;
}
if( !IsIntel || align != ALIGN_UNABS ) {
Output( INDENT "%u: Seg:%u Class:%u Ovl:%u %s %s %s%s Length %X" CRLF,
Segindex, seg, class, ovl,
( IsIntel ) ? oldAlign[align] : newAlign[align],
segComb[ comb ],
( use32 ) ? "USE32" : "USE16",
( phar_access != NULL ) ? phar_access : "",
length
);
if( TranslateIndex ) {
Output( INDENT " Seg: '%s' Class: '%s'" CRLF,
GetLname( seg ), GetLname( class ) );
AddSegdef( seg );
}
} else {
Output( INDENT "%u: Unnamed Absolute %s %s USE16 Length %X" CRLF,
Segindex, oldAlign[ ALIGN_UNABS ], segComb[ comb ], length );
}
if( align == ALIGN_ABS || ( IsIntel && align == ALIGN_UNABS ) ) {
Output( INDENT "Frame: %x Offset: %X" CRLF, abs_frame, abs_offset );
}
if( IsIntel && align == ALIGN_LTRELOC ) {
Output( INDENT "LTL Data:%b Len:%x Offset:%x" CRLF,
ltl_dat, ltl_len, ltl_offset );
}
}
static void getBase( int indent )
{
unsigned_16 group;
unsigned_16 seg;
Grpdeflist *gd;
Segdeflist *sd;
char *grpname;
char *segname;
group = GetIndex();
seg = GetIndex();
if( indent ) Output( INDENT );
if( group == 0 && seg == 0 ) {
Output( "Frame: %x", GetUInt() );
} else {
if( TranslateIndex ) {
gd = GetGrpdef( group );
if( gd != NULL ) {
grpname = GetLname( gd->grpind );
} else {
grpname = "";
}
sd = GetSegdef( seg );
if( sd != NULL ) {
segname = GetLname( sd->segind );
} else {
segname = "";
}
Output( "Group: %u - '%s', Seg: %u - '%s'",
group, grpname, seg, segname );
} else {
Output( "Group: %u, Seg: %u", group, seg );
}
}
if( indent ) Output( CRLF );
}
void ProcLocSyms( void )
/**********************/
{
ProcPubDefs();
}
void ProcPubDefs( void )
/**********************/
{
unsigned_32 puboff;
getBase( TRUE );
while( ! EndRec() ) {
GetName();
puboff = GetEither();
Output( INDENT "%X - %N Type:%u" CRLF, puboff, GetIndex() );
}
}
void ProcComDef( void )
/*********************/
{
unsigned_16 type;
byte seg;
unsigned_32 num;
unsigned_32 size;
while( ! EndRec() ) {
GetName();
type = GetIndex(); /* type index */
seg = GetByte(); /* data seg type */
if( seg == COMDEF_FAR ) {
num = GetVariable();
size = GetVariable();
Output( INDENT "%u - %N Type %u, FAR, Num:%X, Size:%X" CRLF,
++Importindex, type, num, size );
} else if( seg == COMDEF_NEAR ) {
size = GetVariable();
Output( INDENT "%u - %N Type %u, NEAR, Size:%X" CRLF,
++Importindex, type, size );
} else if( seg < 0x60 ) { // Borland style COMDEF
size = GetVariable();
Output( INDENT "%u - %N Type %u, Seg: %u, Size:%X" CRLF,
++Importindex, type, seg, size );
} else {
Output( INDENT "%u - %N Type %u" BAILOUT "Unknown seg(%b)" CRLF,
++Importindex, type, seg );
longjmp( BailOutJmp, 1 );
}
}
}
static void DoLinNumsMS( void )
/*****************************/
{
unsigned_16 line_num;
unsigned_32 offset;
unsigned count;
if( Descriptions ) {
Output( INDENT "Number pairs are \"line#:offset\"" CRLF );
}
if( ! EndRec() ) {
count = 0;
do {
line_num = GetUInt();
offset = GetEither();
switch( count % 4 ) {
case 0:
Output( INDENT "%5:%X", line_num, offset );
break;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?