Пример #1
0
void EmitVarName(Var * var)
/*
Purpose:
	Emit name of variable.
	Variable name may contain non-alphanumeric characters, so we must translate them to support ordinary assemblers.
	Identifiers starting with digit are prefixed by _N.
	Non-alphanumeric characters are replaced by xNN, when NN are two hexadecimal digits representing ascii code of the character.
*/
{
	char * s, c;

	s = var->name;
	if (s != NULL) {
		// If identifier starts with number, we prefix _N
		c = *s;
		if (c >='0' && c <= '9') {
			EmitChar('_');
			EmitChar('N');
		}

		while(c = *s++) {
			if (c == '\'') {
				EmitChar('_');
				c = '_';
			} if (c == '_' || (c >= 'a' && c <= 'z') || (c>='A' && c<='Z') || (c>='0' && c<='9')) {
				EmitChar(c);
			} else {
				EmitChar('x');
				EmitHex(c);
			}
		}
	}

	// If variable has index, append the index
	if (var->idx != 0) EmitInt(var->idx-1);
}
Пример #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;
        }