Changeset f7ac09d for src/driver/as.cc


Ignore:
Timestamp:
Aug 2, 2018, 5:51:59 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, no_list, persistent-indexer, pthread-emulation, qualifiedEnum
Children:
3537dd7
Parents:
0a76d84
Message:

third version of add CFA language

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/driver/as.cc

    r0a76d84 rf7ac09d  
    1010// Created On       : Wed Aug  1 10:49:42 2018
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Aug  2 16:18:14 2018
    13 // Update Count     : 84
     12// Last Modified On : Thu Aug  2 17:50:09 2018
     13// Update Count     : 90
    1414//
    1515
     
    3838        off_t size = mystat.st_size;
    3939
    40         if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); };
    41 
    4240        char * start = (char *)mmap( NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 );
    4341        if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); };
    4442
    45         char * cursor = strstr( start, ".Ldebug_info0:" );      // debug information ?
    46         for ( int i = 0; i < 8; i += 1 ) {                                      // move N (magic) lines forward
    47                 cursor = strstr( cursor, "\n" ) + 1;
    48         } // for
    49         cursor -= 2;                                                                            // backup over "c\n" language value
    50         if ( *(cursor - 1) != 'x' ) { fprintf( stderr, "invalid C language code\n" ); exit( EXIT_FAILURE ); };
    51         memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move text 1 character right
    52         *(cursor) = '2';                                                                        // replace with CFA language value
    53         *(cursor + 1) = '5';
     43        if ( char * cursor = strstr( start, ".Ldebug_info0:" ) ) { // debug information ?
     44                // Expand file by one byte to hold 2 character Cforall language code.
     45                if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); };
    5446
    55         if ( munmap( start, size ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); };
     47                for ( int i = 0; i < 8; i += 1 ) {                              // move N (magic) lines forward
     48                        cursor = strstr( cursor, "\n" ) + 1;
     49                } // for
     50
     51                cursor -= 2;                                                                    // backup over "c\n" language value
     52                if ( *(cursor - 1) != 'x' ) { fprintf( stderr, "invalid C language code\n" ); exit( EXIT_FAILURE ); };
     53
     54                memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right
     55
     56                *(cursor) = '2';                                                                // replace C language value with CFA
     57                *(cursor + 1) = '5';
     58        } // if
     59
     60        if ( munmap( start, size ) ) { perror( "munmap" ); exit( EXIT_FAILURE ); }; // update on disk
    5661
    5762        argv[0] = "as";
Note: See TracChangeset for help on using the changeset viewer.