Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 1 | class InputType(object): |
| 2 | """InputType - Information about various classes of files which |
| 3 | the driver recognizes and control processing.""" |
| 4 | |
| 5 | def __init__(self, name, preprocess=None, onlyAssemble=False, |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 6 | onlyPrecompile=False, tempSuffix=None, |
| 7 | canBeUserSpecified=False): |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 8 | assert preprocess is None or isinstance(preprocess, InputType) |
| 9 | self.name = name |
| 10 | self.preprocess = preprocess |
| 11 | self.onlyAssemble = onlyAssemble |
| 12 | self.onlyPrecompile = onlyPrecompile |
| 13 | self.tempSuffix = tempSuffix |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 14 | self.canBeUserSpecified = canBeUserSpecified |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 15 | |
| 16 | def __repr__(self): |
| 17 | return '%s(%r, %r, %r, %r, %r)' % (self.__class__.__name__, |
| 18 | self.name, |
| 19 | self.preprocess, |
| 20 | self.onlyAssemble, |
| 21 | self.onlyPrecompile, |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 22 | self.tempSuffix, |
| 23 | self.canBeUserSpecified) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 24 | |
| 25 | # C family source language (with and without preprocessing). |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 26 | CTypeNoPP = InputType('cpp-output', tempSuffix='i', |
| 27 | canBeUserSpecified=True) |
| 28 | CType = InputType('c', CTypeNoPP, |
| 29 | canBeUserSpecified=True) |
| 30 | ObjCTypeNoPP = InputType('objective-c-cpp-output', tempSuffix='mi', |
| 31 | canBeUserSpecified=True) |
| 32 | ObjCType = InputType('objective-c', ObjCTypeNoPP, |
| 33 | canBeUserSpecified=True) |
| 34 | CXXTypeNoPP = InputType('c++-cpp-output', tempSuffix='ii', |
| 35 | canBeUserSpecified=True) |
| 36 | CXXType = InputType('c++', CXXTypeNoPP, |
| 37 | canBeUserSpecified=True) |
| 38 | ObjCXXTypeNoPP = InputType('objective-c++-cpp-output', tempSuffix='mii', |
| 39 | canBeUserSpecified=True) |
| 40 | ObjCXXType = InputType('objective-c++', ObjCXXTypeNoPP, |
| 41 | canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 42 | |
| 43 | # C family input files to precompile. |
| 44 | CHeaderNoPPType = InputType('c-header-cpp-output', onlyPrecompile=True, tempSuffix='pch') |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 45 | CHeaderType = InputType('c-header', CHeaderNoPPType, onlyPrecompile=True, |
| 46 | canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 47 | ObjCHeaderNoPPType = InputType('objective-c-header-cpp-output', onlyPrecompile=True, tempSuffix='pch') |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 48 | ObjCHeaderType = InputType('objective-c-header', ObjCHeaderNoPPType, onlyPrecompile=True, |
| 49 | canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 50 | CXXHeaderNoPPType = InputType('c++-header-cpp-output', onlyPrecompile=True, tempSuffix='pch') |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 51 | CXXHeaderType = InputType('c++-header', CXXHeaderNoPPType, onlyPrecompile=True, |
| 52 | canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 53 | ObjCXXHeaderNoPPType = InputType('objective-c++-header-cpp-output', onlyPrecompile=True, tempSuffix='pch') |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 54 | ObjCXXHeaderType = InputType('objective-c++-header', ObjCXXHeaderNoPPType, onlyPrecompile=True, |
| 55 | canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 56 | |
| 57 | # Other languages. |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 58 | AdaType = InputType('ada', canBeUserSpecified=True) |
| 59 | AsmTypeNoPP = InputType('assembler', onlyAssemble=True, tempSuffix='s', |
| 60 | canBeUserSpecified=True) |
| 61 | AsmType = InputType('assembler-with-cpp', AsmTypeNoPP, onlyAssemble=True, |
| 62 | canBeUserSpecified=True) |
| 63 | FortranTypeNoPP = InputType('f95', canBeUserSpecified=True) |
| 64 | FortranType = InputType('f95-cpp-input', FortranTypeNoPP, canBeUserSpecified=True) |
| 65 | JavaType = InputType('java', canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 66 | |
| 67 | # Misc. |
| 68 | PCHType = InputType('precompiled-header') |
| 69 | ObjectType = InputType('object', tempSuffix='o') |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 70 | TreelangType = InputType('treelang', canBeUserSpecified=True) |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 71 | ImageType = InputType('image', tempSuffix='out') |
| 72 | NothingType = InputType('nothing') |
| 73 | |
| 74 | ### |
| 75 | |
| 76 | kDefaultOutput = "a.out" |
| 77 | kTypeSuffixMap = { |
| 78 | '.c' : CType, |
| 79 | '.i' : CTypeNoPP, |
| 80 | '.ii' : CXXTypeNoPP, |
| 81 | '.m' : ObjCType, |
| 82 | '.mi' : ObjCTypeNoPP, |
| 83 | '.mm' : ObjCXXType, |
| 84 | '.M' : ObjCXXType, |
| 85 | '.mii' : ObjCXXTypeNoPP, |
| 86 | '.h' : CHeaderType, |
| 87 | '.cc' : CXXType, |
| 88 | '.cc' : CXXType, |
| 89 | '.cp' : CXXType, |
| 90 | '.cxx' : CXXType, |
| 91 | '.cpp' : CXXType, |
| 92 | '.CPP' : CXXType, |
| 93 | '.cXX' : CXXType, |
| 94 | '.C' : CXXType, |
| 95 | '.hh' : CXXHeaderType, |
| 96 | '.H' : CXXHeaderType, |
| 97 | '.f' : FortranTypeNoPP, |
| 98 | '.for' : FortranTypeNoPP, |
| 99 | '.FOR' : FortranTypeNoPP, |
| 100 | '.F' : FortranType, |
| 101 | '.fpp' : FortranType, |
| 102 | '.FPP' : FortranType, |
| 103 | '.f90' : FortranTypeNoPP, |
| 104 | '.f95' : FortranTypeNoPP, |
| 105 | '.F90' : FortranType, |
| 106 | '.F95' : FortranType, |
| 107 | # Apparently the Ada F-E hardcodes these suffixes in many |
| 108 | # places. This explains why there is only one -x option for ada. |
| 109 | '.ads' : AdaType, |
| 110 | '.adb' : AdaType, |
| 111 | # FIXME: Darwin always uses a preprocessor for asm input. Where |
| 112 | # does this fit? |
| 113 | '.s' : AsmTypeNoPP, |
| 114 | '.S' : AsmType, |
| 115 | } |
| 116 | kTypeSpecifierMap = { |
| 117 | 'none' : None, |
| 118 | |
| 119 | 'c' : CType, |
| 120 | 'c-header' : CHeaderType, |
| 121 | # NOTE: gcc.info claims c-cpp-output works but the actual spelling |
| 122 | # is cpp-output. Nice. |
| 123 | 'cpp-output' : CTypeNoPP, |
| 124 | 'c++' : CXXType, |
| 125 | 'c++-header' : CXXHeaderType, |
| 126 | 'c++-cpp-output' : CXXTypeNoPP, |
| 127 | 'objective-c' : ObjCType, |
| 128 | 'objective-c-header' : ObjCHeaderType, |
| 129 | 'objective-c-cpp-output' : ObjCTypeNoPP, |
| 130 | 'objective-c++' : ObjCXXType, |
| 131 | 'objective-c++-header' : ObjCXXHeaderType, |
| 132 | 'objective-c++-cpp-output' : ObjCXXTypeNoPP, |
| 133 | 'assembler' : AsmTypeNoPP, |
| 134 | 'assembler-with-cpp' : AsmType, |
| 135 | 'ada' : AdaType, |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 136 | 'f95-cpp-input' : FortranType, |
| 137 | 'f95' : FortranTypeNoPP, |
Daniel Dunbar | a567751 | 2009-01-05 19:53:30 +0000 | [diff] [blame] | 138 | 'java' : JavaType, |
| 139 | 'treelang' : TreelangType, |
| 140 | } |
Daniel Dunbar | d38c11e | 2009-01-10 01:50:42 +0000 | [diff] [blame^] | 141 | |
| 142 | # Check that the type specifier map at least matches what the types |
| 143 | # believe to be true. |
| 144 | assert not [name for name,type in kTypeSpecifierMap.items() |
| 145 | if type and (type.name != name or not type.canBeUserSpecified)] |