| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 # Copyright (c) 2013 The Native Client Authors. All rights reserved. | 2 # Copyright (c) 2013 The Native Client Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Utilities for determining (and overriding) the types of files | 6 """Utilities for determining (and overriding) the types of files |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 | 10 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 @SimpleCache | 61 @SimpleCache |
| 62 def IsNativeObject(filename): | 62 def IsNativeObject(filename): |
| 63 return FileType(filename) == 'o' | 63 return FileType(filename) == 'o' |
| 64 | 64 |
| 65 @SimpleCache | 65 @SimpleCache |
| 66 def IsNativeDSO(filename): | 66 def IsNativeDSO(filename): |
| 67 return FileType(filename) == 'so' | 67 return FileType(filename) == 'so' |
| 68 | 68 |
| 69 @SimpleCache | 69 @SimpleCache |
| 70 def IsPll(filename): |
| 71 return FileType(filename) == 'pll' |
| 72 |
| 73 @SimpleCache |
| 70 def GetBitcodeMagic(filename): | 74 def GetBitcodeMagic(filename): |
| 71 fp = driver_log.DriverOpen(filename, 'rb') | 75 fp = driver_log.DriverOpen(filename, 'rb') |
| 72 header = fp.read(4) | 76 header = fp.read(4) |
| 73 driver_log.DriverClose(fp) | 77 driver_log.DriverClose(fp) |
| 74 return header | 78 return header |
| 75 | 79 |
| 76 def IsLLVMBitcodeWrapperHeader(data): | 80 def IsLLVMBitcodeWrapperHeader(data): |
| 77 return data[:4] == LLVM_WRAPPER_MAGIC | 81 return data[:4] == LLVM_WRAPPER_MAGIC |
| 78 | 82 |
| 79 @SimpleCache | 83 @SimpleCache |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 346 |
| 343 if elftools.IsELF(filename): | 347 if elftools.IsELF(filename): |
| 344 return GetELFType(filename) | 348 return GetELFType(filename) |
| 345 | 349 |
| 346 # If this is LLVM bitcode, we don't have a good way of determining if it | 350 # If this is LLVM bitcode, we don't have a good way of determining if it |
| 347 # is an object file or a non-finalized program, so just say 'po' for now. | 351 # is an object file or a non-finalized program, so just say 'po' for now. |
| 348 if IsLLVMBitcode(filename): | 352 if IsLLVMBitcode(filename): |
| 349 return 'po' | 353 return 'po' |
| 350 | 354 |
| 351 if IsPNaClBitcode(filename): | 355 if IsPNaClBitcode(filename): |
| 356 # Although this file has the same extension as a native ".so", it actually |
| 357 # is in a portable format and should be handled slightly differently. |
| 358 if ext == 'so': |
| 359 return 'pll' |
| 352 return 'pexe' | 360 return 'pexe' |
| 353 | 361 |
| 354 if IsLinkerScript(filename): | 362 if IsLinkerScript(filename): |
| 355 return 'ldscript' | 363 return 'ldscript' |
| 356 | 364 |
| 357 # Use the file extension if it is recognized | 365 # Use the file extension if it is recognized |
| 358 if ext in ExtensionMap: | 366 if ext in ExtensionMap: |
| 359 return ExtensionMap[ext] | 367 return ExtensionMap[ext] |
| 360 | 368 |
| 361 driver_log.Log.Fatal('%s: Unrecognized file type', filename) | 369 driver_log.Log.Fatal('%s: Unrecognized file type', filename) |
| 362 | 370 |
| 363 # Map from GCC's -x file types and this driver's file types. | 371 # Map from GCC's -x file types and this driver's file types. |
| 364 FILE_TYPE_MAP = { | 372 FILE_TYPE_MAP = { |
| 365 'c' : 'c', | 373 'c' : 'c', |
| 366 'c++' : 'c++', | 374 'c++' : 'c++', |
| 367 'assembler' : 's', | 375 'assembler' : 's', |
| 368 'assembler-with-cpp': 'S', | 376 'assembler-with-cpp': 'S', |
| 369 'c-header' : 'c-header', | 377 'c-header' : 'c-header', |
| 370 'c++-header' : 'c++-header', | 378 'c++-header' : 'c++-header', |
| 371 } | 379 } |
| 372 FILE_TYPE_MAP_REVERSE = dict([reversed(_tmp) for _tmp in FILE_TYPE_MAP.items()]) | 380 FILE_TYPE_MAP_REVERSE = dict([reversed(_tmp) for _tmp in FILE_TYPE_MAP.items()]) |
| 373 | 381 |
| 374 def FileTypeToGCCType(filetype): | 382 def FileTypeToGCCType(filetype): |
| 375 return FILE_TYPE_MAP_REVERSE[filetype] | 383 return FILE_TYPE_MAP_REVERSE[filetype] |
| 376 | 384 |
| 377 def GCCTypeToFileType(gcctype): | 385 def GCCTypeToFileType(gcctype): |
| 378 if gcctype not in FILE_TYPE_MAP: | 386 if gcctype not in FILE_TYPE_MAP: |
| 379 driver_log.Log.Fatal('language "%s" not recognized' % gcctype) | 387 driver_log.Log.Fatal('language "%s" not recognized' % gcctype) |
| 380 return FILE_TYPE_MAP[gcctype] | 388 return FILE_TYPE_MAP[gcctype] |
| OLD | NEW |