Exemple #1
0
bool ObjInit( char *fname ) {
//***************************

    owl_client_funcs    funcs = {
        (int (*)( owl_client_file, const char *, uint ))write,
        (long (*)( owl_client_file ))tell,
        (long (*)( owl_client_file, long, int ))lseek,
        MemAlloc,
        MemFree
    };
    char                name[ _MAX_FNAME ];
    owl_format          obj_format;

    SectionInit();
    _splitpath( fname, NULL, NULL, name, NULL );
    if( !objectDefined ) {
        _makepath( objName, NULL, NULL, name, OBJ_EXT );
    } else {
        char    tmpName[ _MAX_PATH2 ];
        char    *tmpNode;
        char    *tmpDir;
        char    *tmpFname;
        char    *tmpExt;
        _splitpath2( objName, tmpName, &tmpNode, &tmpDir, &tmpFname, &tmpExt );
        if( *tmpExt == 0 )
            tmpExt = OBJ_EXT;
        if( *tmpFname == 0 )
            tmpFname = name;
        _makepath( objName, tmpNode, tmpDir, tmpFname, tmpExt );
    }
    objectDefined = FALSE;      // so that the /fo applies only to the 1st obj
    _makepath( errorFilename, NULL, NULL, name, ".err" );
    objFile = open( objName, O_CREAT | O_TRUNC | O_BINARY | O_WRONLY, PMODE_RW );
    if( objFile == -1 ) {
        AsOutMessage( stderr, UNABLE_TO_CREATE, objName );
        fputc( '\n', stderr );
        return( FALSE );
    }
    ErrorFile = fopen( errorFilename, "wt" );
    OwlHandle = OWLInit( &funcs, OBJ_OWL_CPU );
    obj_format = ( _IsOption( OBJ_COFF ) ? OWL_FORMAT_COFF : OWL_FORMAT_ELF );
    OwlFile = OWLFileInit( OwlHandle, fname, (owl_client_file)(pointer_int)objFile, obj_format, OWL_FILE_OBJECT );
    ObjSwitchSection( AS_SECTION_TEXT );
    CurrAlignment = 0;
    return( TRUE );
}
Exemple #2
0
extern bool OptionsInit( int argc, char **argv ) {
//************************************************

    char        *s;

#ifdef AS_ALPHA
    s = "__WASAXP__=" BANSTR( _BANVER ) ;
#elif defined( AS_PPC )
    s = "__WASPPC__=" BANSTR( _BANVER ) ;
#elif defined( AS_MIPS )
    s = "__WASMPS__=" BANSTR( _BANVER ) ;
#endif
    maxNumPredefines = argc + 2; // version macro and extra null at the end
    if( !optionsPredefine( s ) )
        goto errInvalid;

    while( *argv ) {
        if( argv[0][0] == '-' || argv[0][0] == '/' ) {
            s = &argv[0][2];
            switch( argv[0][1] ) {
            case 'b':
            case 'B':
                // ignore the -bt=NT crap
                break;
            case 'd':
            case 'D':
                if( isdigit( *s ) ) {
                    DebugLevel = strtoul( s, &s, 10 );
                } else if( !optionsPredefine( s ) ) {
                    goto errInvalid;
                }
                break;
            case 'e':
                if( *s == '\0' ) goto errInvalid;
                ErrorLimit = strtoul( s, &s, 10 );
                if( *s != '\0' ) goto errInvalid;
                break;
            case 'f':
            case 'F':
                switch( *s ) {
                case 'o':
                    ++s;
                    if( *s == '=' ) ++s;
                    if( *s == '\0' ) goto errInvalid;
                    ObjSetObjFile( s );
                    break;
                default:
                    goto errInvalid;
                }
                break;
            case 'h':
            case '?':
                _SetOption( PRINT_HELP );
                break;
            case 'i':
            case 'I':
                if( *s == '=' ) {
                    ++s;
                }
                if( *s == '\0' ) break;
                if( AsIncPath ) { // Additional /i switch
                    AsIncPath = MemRealloc( AsIncPath, strlen( AsIncPath ) +
                        strlen( s ) + 2 );      // for ';' and EOL
                    strcat( AsIncPath, ";" );
                    strcat( AsIncPath, s );
                } else { // First /i switch
                    AsIncPath = MemAlloc( strlen( s ) + 1 );
                    strcpy( AsIncPath, s );
                }
                break;
            case 'o':
                switch( *s ) {
                case 'c':
                    _SetOption( OBJ_COFF );
                    break;
                case 'e': // ELF
                    _UnsetOption( OBJ_COFF );
                    break;
                default:
                    goto errInvalid;
                }
                if( *++s != '\0' ) goto errInvalid;
                break;
            case 'q':
                _SetOption( BE_QUIET );
                break;
            case 'w':
                if( isdigit( *s ) ) {
                    WarningLevel = strtoul( s, &s, 10 );
                } else {
                    switch( *s ) {
                    case 'e':
                        _SetOption( WARNING_ERROR );
                        break;
                    default:
                        goto errInvalid;
                    }
                }
                break;
            case 'z':
                switch( *s ) {
                case 'q':
                    _SetOption( BE_QUIET );
                    break;
                default:
                    goto errInvalid;
                }
                break;
#ifndef NDEBUG
            case 'v':
                while( *s ) {
                    switch( *s ) {
                    case 'p':
                        _SetOption( DUMP_PARSE_TREE );
                        break;
                    case 't':
                        _SetOption( DUMP_INS_TABLE );
                        break;
                    case 'i':
                        _SetOption( DUMP_INSTRUCTIONS );
                        break;
                    case 's':
                        _SetOption( DUMP_SYMBOL_TABLE );
                        break;
                    case 'l':
                        _SetOption( DUMP_LEXER_BUFFER );
                        break;
                    case 'd':
                        _SetOption( DUMP_DEBUG_MSGS );
                        break;
                    default:
                        goto errInvalid;
                    }
                    s++;
                }
                break;
#endif
            default:
            errInvalid:
                Banner();
                AsOutMessage( stderr, AS_MSG_ERROR );
                AsOutMessage( stderr, INVALID_OPTION, *argv );
                fputc( '\n', stderr );
                return( FALSE );
                break;
            }
            memcpy( argv, argv+1, sizeof( *argv ) * argc );
        } else {
            argv++;
        }
        argc--;
        maxNumPredefines--;
    }
    return( TRUE );
}
Exemple #3
0
int main( int argc, char **argv )
//*******************************
{
    static char *fname;

#ifndef __WATCOMC__
    _argv = argv;
    _argc = argc;
#endif
    MemInit();
    if( !AsMsgInit() ) {
        return( EXIT_FAILURE );
    }
    if( argc == 1 ) {
        Banner();
        Usage();
    } else if( OptionsInit( --argc, ++argv ) ) {
        Banner();
        if( _IsOption( PRINT_HELP ) ) {
            Usage();
            *argv = NULL;
        } else if( !*argv ) {
            AsOutMessage( stderr, AS_MSG_ERROR );
            AsOutMessage( stderr, NO_FILENAME_SPECIFIED );
            fputc( '\n', stderr );
        }
        while( *argv ) {
            fname = MakeAsmFilename( *argv );
            if( PP_Init( fname, PPFLAG_ASM_COMMENT | PPFLAG_EMIT_LINE, NULL ) != 0 ) {
                AsOutMessage( stderr, UNABLE_TO_OPEN, fname );
                fputc( '\n', stderr );
            } else {
                OptionsPPDefine();
                SymInit();
                InsInit();
                DirInit();
                if( ObjInit( fname ) ) {
                    if( setjmp( AsmParse ) == 0 ) {
                        ErrorCountsReset();
                        DoReport = TRUE;
                        if( !yyparse() ) {
                            CurrLineno--;    // This is the total # of lines
                            ObjRelocsFini(); // Must be done before ErrorReport
                            // and other finis
                        } else {
                            DoReport = FALSE;
                        }
                    } else { // AbortParse() was invoked
                        DoReport = FALSE;
                    }
                    ErrorReport();
                    AsLexerFini();
                    ObjFini();
                }
                DirFini();
                InsFini();
                SymFini();
            }
            PP_Fini();
            ++argv;
        }
    }
    OptionsFini();
    AsMsgFini();
    MemFini();
    return( ExitStatus );
}