Пример #1
0
void  FindSrcLine( uint_32 addr )
/*******************************/
{
    line_num            *line;
    line_num            *check;
    unsigned            next;
    int                 len;
    char                txt_line[ MAX_LINE_LEN + 1 ];

    line = Mod->src_rover;
    if( line == NULL ) return;
    if( line->seg != Segment ) {
        if( Segment->src_done )
            return;
        check = line;
        for( ;; ) {
           check = check->next_num;
           if( check == NULL ) {
               Segment->src_done = true;
               return;
           }
           if( check->seg == Segment ) break;
        }
        FlipToSeg( line->seg );
        return;
    }
    if( line->address > addr ) return;

    if( addr == Segment->start && LastNum <= 1 ) {
        if( line->next_num == NULL ) {
            next = UINT_MAX;
        } else {
            next = line->next_num->num;
        }
    } else if( addr == Segment->size ) {
        for( ;; ) {
            if( line == NULL ) break;
            if( line->seg != Segment ) break;
            line = line->next_num;
        }
    } else {
        next = LastNum;
        for( ;; ) {
            if( line == NULL ) return;
            if( line->seg != Segment ) return;
            if( line->address == addr ) break;
            line = line->next_num;
        }
        for( ;; ) {
            line = line->next_num;
            if( line == NULL ) {
                next = UINT_MAX;
                break;
            }
            if( line->num < next ) continue;
            next = line->num;
            if( line->seg != Segment ) break;
            if( line->address > addr ) break;
        }
    }
    Mod->src_rover = line;
    EmitNL();
    for( ;; ) {
        if( LastNum + 1 >= next ) return;
        len = FGetTxtRec( Source, txt_line, MAX_LINE_LEN );
        txt_line[ len ] = NULLCHAR;
        if( feof( Source ) ) break;
        if( Options & FORM_ASSEMBLER ) {
            if( DO_UNIX ) {
                Emit( "/ " );
            } else {
                Emit( "; " );
            }
        }
        EmitLine( txt_line );
        ++LastNum;
    }
    if( next != UINT_MAX ) {
        DoEmitError( ERR_EOF_ENCOUNTERED );
    }
}
Пример #2
0
void  EmitModule()
/****************/

{
    char                *name;
    import_sym          *imp;
    char                sp_buf[ _MAX_PATH2 ];
    char                *root_name;

    if( ( Options & FORM_ASSEMBLER ) == 0 ) {
        EmitNL();
        DoEmit( MSG_MODULE );
        EmitLine( Mod->name );
        if( Mod->main ) {
            EmitLine( "MAIN MODULE " );
        }
        if( Mod->start != NULL ) {
            DoEmit( MSG_START_ADDR );
            name = GetFixName( Mod->start );
            if( name == NULL ) {
                name = NewName( Mod->start );
            }
            Emit( name );
            EmitNL();
        }
    } else {
        _splitpath2( Mod->name, sp_buf, NULL, NULL, &root_name, NULL );
        if( DO_UNIX ) {
            EmitBlanks( LABEL_LEN );
            EmitSpaced( ".file", OPCODE_LEN );
            Emit( "\"" );
            Emit( root_name );
            Emit( "\"" );
            EmitNL();
        } else {
            if( RetFarUsed ) {
                EmitRetFMacro();
            }
            if( Is32BitObj ) EmitLine( ".386p" );
            EmitBlanks( LABEL_LEN );
            EmitSpaced( "NAME", OPCODE_LEN );
            EmitLine( root_name );
        }
        if( ( Options & FORM_DO_WTK )  &&  HaveWtk() ) {
            Emit( "INCLUDE" );
            EmitBlanks( LABEL_LEN - 7 );
            EmitLine( "67MACROS.EQU" );
        }
    }
    for( imp = Mod->imports; imp != NULL; imp = imp->next_imp ) {
        switch( imp->class ) {
        case TYPE_IMPORT:
            if( !DO_UNIX
                && ( Options & FORM_ASSEMBLER )
                && imp->public
                && !imp->exported
                && strcmp( imp->name, WTLBASEStr ) != 0 ) {
                EmitBlanks( LABEL_LEN );
                EmitSpaced( "EXTRN", OPCODE_LEN );
                EmitSym( imp->name, 0 );
                Emit( ":BYTE" );        // so that output would assemble
                EmitNL();
            }
            break;
        case TYPE_COMDEF:
            if( DO_UNIX ) {
                if( imp->public ) {
                    EmitBlanks( LABEL_LEN );
                    EmitSpaced( ".globl", OPCODE_LEN );
                    EmitLine( imp->name );
                }
                EmitBlanks( LABEL_LEN );
                EmitSpaced( ".lcomm", OPCODE_LEN );
                EmitSym( imp->name, 0 );
                Emit( ", " );
            } else {
                if( imp->public ) {
                    EmitBlanks( LABEL_LEN );
                    EmitSpaced( "COMM", OPCODE_LEN );
                } else {
                    if( Options & FORM_ASSEMBLER ) {
                        DoEmitError( MSG_LCL_COMM_WONT_ASM );
                    }
                    EmitBlanks( LABEL_LEN );
                    EmitSpaced( "LCOMM", OPCODE_LEN );
                }
                if( imp->far_common ) {
                    Emit( "FAR  " );
                } else {
                    Emit( "NEAR " );
                }
                EmitSym( imp->name, 0 );
                Emit( ":BYTE:" );
            }
            EmitHex( imp->u.size );
            EmitNL();
            break;
        }