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