blob: 40fe01f550885a532ed5f458cb3901263e18c1d1 [file] [log] [blame]
Daniel Dunbara5677512009-01-05 19:53:30 +00001class 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 Dunbard38c11e2009-01-10 01:50:42 +00006 onlyPrecompile=False, tempSuffix=None,
7 canBeUserSpecified=False):
Daniel Dunbara5677512009-01-05 19:53:30 +00008 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 Dunbard38c11e2009-01-10 01:50:42 +000014 self.canBeUserSpecified = canBeUserSpecified
Daniel Dunbara5677512009-01-05 19:53:30 +000015
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 Dunbard38c11e2009-01-10 01:50:42 +000022 self.tempSuffix,
23 self.canBeUserSpecified)
Daniel Dunbara5677512009-01-05 19:53:30 +000024
25# C family source language (with and without preprocessing).
Daniel Dunbard38c11e2009-01-10 01:50:42 +000026CTypeNoPP = InputType('cpp-output', tempSuffix='i',
27 canBeUserSpecified=True)
28CType = InputType('c', CTypeNoPP,
29 canBeUserSpecified=True)
30ObjCTypeNoPP = InputType('objective-c-cpp-output', tempSuffix='mi',
31 canBeUserSpecified=True)
32ObjCType = InputType('objective-c', ObjCTypeNoPP,
33 canBeUserSpecified=True)
34CXXTypeNoPP = InputType('c++-cpp-output', tempSuffix='ii',
35 canBeUserSpecified=True)
36CXXType = InputType('c++', CXXTypeNoPP,
37 canBeUserSpecified=True)
38ObjCXXTypeNoPP = InputType('objective-c++-cpp-output', tempSuffix='mii',
39 canBeUserSpecified=True)
40ObjCXXType = InputType('objective-c++', ObjCXXTypeNoPP,
41 canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000042
43# C family input files to precompile.
44CHeaderNoPPType = InputType('c-header-cpp-output', onlyPrecompile=True, tempSuffix='pch')
Daniel Dunbard38c11e2009-01-10 01:50:42 +000045CHeaderType = InputType('c-header', CHeaderNoPPType, onlyPrecompile=True,
46 canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000047ObjCHeaderNoPPType = InputType('objective-c-header-cpp-output', onlyPrecompile=True, tempSuffix='pch')
Daniel Dunbard38c11e2009-01-10 01:50:42 +000048ObjCHeaderType = InputType('objective-c-header', ObjCHeaderNoPPType, onlyPrecompile=True,
49 canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000050CXXHeaderNoPPType = InputType('c++-header-cpp-output', onlyPrecompile=True, tempSuffix='pch')
Daniel Dunbard38c11e2009-01-10 01:50:42 +000051CXXHeaderType = InputType('c++-header', CXXHeaderNoPPType, onlyPrecompile=True,
52 canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000053ObjCXXHeaderNoPPType = InputType('objective-c++-header-cpp-output', onlyPrecompile=True, tempSuffix='pch')
Daniel Dunbard38c11e2009-01-10 01:50:42 +000054ObjCXXHeaderType = InputType('objective-c++-header', ObjCXXHeaderNoPPType, onlyPrecompile=True,
55 canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000056
57# Other languages.
Daniel Dunbard38c11e2009-01-10 01:50:42 +000058AdaType = InputType('ada', canBeUserSpecified=True)
59AsmTypeNoPP = InputType('assembler', onlyAssemble=True, tempSuffix='s',
60 canBeUserSpecified=True)
61AsmType = InputType('assembler-with-cpp', AsmTypeNoPP, onlyAssemble=True,
62 canBeUserSpecified=True)
63FortranTypeNoPP = InputType('f95', canBeUserSpecified=True)
64FortranType = InputType('f95-cpp-input', FortranTypeNoPP, canBeUserSpecified=True)
65JavaType = InputType('java', canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000066
67# Misc.
68PCHType = InputType('precompiled-header')
69ObjectType = InputType('object', tempSuffix='o')
Daniel Dunbard38c11e2009-01-10 01:50:42 +000070TreelangType = InputType('treelang', canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000071ImageType = InputType('image', tempSuffix='out')
72NothingType = InputType('nothing')
73
74###
75
76kDefaultOutput = "a.out"
77kTypeSuffixMap = {
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}
116kTypeSpecifierMap = {
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 Dunbard38c11e2009-01-10 01:50:42 +0000136 'f95-cpp-input' : FortranType,
137 'f95' : FortranTypeNoPP,
Daniel Dunbara5677512009-01-05 19:53:30 +0000138 'java' : JavaType,
139 'treelang' : TreelangType,
140}
Daniel Dunbard38c11e2009-01-10 01:50:42 +0000141
142# Check that the type specifier map at least matches what the types
143# believe to be true.
144assert not [name for name,type in kTypeSpecifierMap.items()
145 if type and (type.name != name or not type.canBeUserSpecified)]