Changeset 6c53a93 for driver/as.cc
- Timestamp:
- Jan 5, 2022, 10:39:39 AM (4 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum, stuck-waitfor-destruct
- Children:
- 0ac728b
- Parents:
- e2853eb (diff), 6111f1f (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - File:
-
- 1 edited
-
driver/as.cc (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
driver/as.cc
re2853eb r6c53a93 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // as.c -- map assembler file, scan for debug information . If found, expand file by one character and insert Cforall8 // language code on the N line from the start of the debug information.7 // as.c -- map assembler file, scan for debug information, then language code, and skip N lines forward to code. If 8 // code is C dialect, possibly expand file by one character, and replace with Cforall language code. 9 9 // 10 10 // Author : Peter A. Buhr 11 11 // Created On : Wed Aug 1 10:49:42 2018 12 12 // Last Modified By : Peter A. Buhr 13 // Last Modified On : Sat Sep 8 08:40:16 201814 // Update Count : 9713 // Last Modified On : Wed Dec 8 07:56:12 2021 14 // Update Count : 136 15 15 // 16 16 … … 18 18 #include <cstdlib> // exit 19 19 #include <fcntl.h> // open 20 #include <unistd.h> 21 #include <sys/stat.h> 20 #include <cstring> // strstr, memmove 21 #include <unistd.h> // ftruncate,execvp 22 #include <sys/stat.h> // fstat 22 23 #include <sys/mman.h> // mmap 23 #include <string.h>24 24 25 25 //#define __DEBUG_H__ 26 27 #ifdef __DEBUG_H__28 #include <iostream>29 using namespace std;30 #endif // __DEBUG_H__31 26 32 27 int main( const int argc, const char * argv[] ) { 33 28 #ifdef __DEBUG_H__ 34 29 for ( int i = 0; i < argc; i += 1 ) { 35 cerr << argv[i] << endl;30 fprintf( stderr, "%s\n", argv[i] ); 36 31 } // for 37 32 #endif // __DEBUG_H__ … … 48 43 if ( start == (void *)-1 ) { perror( "mmap" ); exit( EXIT_FAILURE ); }; 49 44 50 if ( char * cursor = strstr( start, ".Ldebug_info0:" ) ) { // debug information ? 51 // Expand file by one byte to hold 2 character Cforall language code. 52 if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); }; 45 char * dcursor; 46 if ( (dcursor = strstr( start, ".Ldebug_info0:" ) ) ) { // debug information ? 53 47 54 for ( int i = 0; i < 8; i += 1 ) { // move N (magic) lines forward 55 cursor = strstr( cursor, "\n" ) + 1; 56 } // for 48 if ( char * cursor = strstr( dcursor, ".long\t.LASF" ) ) { // language code ? 49 for ( int i = 0; i < 2; i += 1 ) { // move N (magic) lines forward 50 cursor = strstr( cursor, "\n" ) + 1; 51 } // for 52 cursor -= 2; // backup over "d\n", where d is a hex digit 53 // From elfcpp/dwarf.h in the binutils source tree. 54 // DW_LANG_C89 = 0x1, DW_LANG_C = 0x2, DW_LANG_C99 = 0xc, DW_LANG_C11 = 0x1d 55 if ( *(cursor - 2) == '0' && *(cursor - 1) == 'x' && 56 (*cursor == 'c' || *cursor == '1' || *cursor == '2') ) { // C99/C89/C 57 // Expand file by one byte to hold 2 character Cforall language code. 58 if ( ftruncate( fd, size + 1 ) ) { perror( "ftruncate" ); exit( EXIT_FAILURE ); }; 59 memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right 60 } else if ( *(cursor - 3) == '0' && *(cursor - 2) == 'x' && *(cursor - 1) == '1' && *cursor == 'd' ) { // C11 61 } else { 62 for ( int i = 0; i < 6; i += 1 ) { // move N (magic) lines forward 63 cursor = strstr( cursor, "\n" ) + 1; 64 } // for 65 fprintf( stderr, "*** ERROR *** Invalid C language code found in assembler file: %s\n" 66 "Assembler debug information:\n%.*s", 67 argv[argc - 1], (int)(cursor - dcursor), dcursor ); 68 exit( EXIT_FAILURE ); 69 } // if 57 70 58 cursor -= 2; // backup over "c\n" language value 59 if ( *(cursor - 1) != 'x' ) { fprintf( stderr, "invalid C language code\n" ); exit( EXIT_FAILURE ); }; 60 61 memmove( cursor + 2, cursor + 1, start + size - cursor - 1 ); // move remaining text 1 character right 62 63 *(cursor) = '2'; // replace C language value with CFA 64 *(cursor + 1) = '5'; 71 *(cursor - 1) = '2'; // replace C89/C/C99/C11 language code with CFA code 72 *cursor = '5'; 73 } // if 65 74 } // if 66 75
Note:
See TracChangeset
for help on using the changeset viewer.