blob: 19c1f5fffbdd830c5ed2d10ae5453e37a55432cf [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):
Daniel Dunbar9c199a02009-01-11 23:13:15 +000017 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 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.
Daniel Dunbar9c199a02009-01-11 23:13:15 +000044CHeaderNoPPType = InputType('c-header-cpp-output', tempSuffix='i',
45 onlyPrecompile=True)
46CHeaderType = InputType('c-header', CHeaderNoPPType,
47 onlyPrecompile=True, canBeUserSpecified=True)
48ObjCHeaderNoPPType = InputType('objective-c-header-cpp-output', tempSuffix='mi',
49 onlyPrecompile=True)
50ObjCHeaderType = InputType('objective-c-header', ObjCHeaderNoPPType,
51 onlyPrecompile=True, canBeUserSpecified=True)
52CXXHeaderNoPPType = InputType('c++-header-cpp-output', tempSuffix='ii',
53 onlyPrecompile=True)
54CXXHeaderType = InputType('c++-header', CXXHeaderNoPPType,
55 onlyPrecompile=True, canBeUserSpecified=True)
56ObjCXXHeaderNoPPType = InputType('objective-c++-header-cpp-output', tempSuffix='mii',
57 onlyPrecompile=True)
58ObjCXXHeaderType = InputType('objective-c++-header', ObjCXXHeaderNoPPType,
59 onlyPrecompile=True, canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000060
61# Other languages.
Daniel Dunbard38c11e2009-01-10 01:50:42 +000062AdaType = InputType('ada', canBeUserSpecified=True)
63AsmTypeNoPP = InputType('assembler', onlyAssemble=True, tempSuffix='s',
64 canBeUserSpecified=True)
65AsmType = InputType('assembler-with-cpp', AsmTypeNoPP, onlyAssemble=True,
66 canBeUserSpecified=True)
67FortranTypeNoPP = InputType('f95', canBeUserSpecified=True)
68FortranType = InputType('f95-cpp-input', FortranTypeNoPP, canBeUserSpecified=True)
69JavaType = InputType('java', canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000070
71# Misc.
Daniel Dunbar9c199a02009-01-11 23:13:15 +000072PCHType = InputType('precompiled-header', tempSuffix='gch')
Daniel Dunbara5677512009-01-05 19:53:30 +000073ObjectType = InputType('object', tempSuffix='o')
Daniel Dunbard38c11e2009-01-10 01:50:42 +000074TreelangType = InputType('treelang', canBeUserSpecified=True)
Daniel Dunbara5677512009-01-05 19:53:30 +000075ImageType = InputType('image', tempSuffix='out')
76NothingType = InputType('nothing')
77
78###
79
80kDefaultOutput = "a.out"
81kTypeSuffixMap = {
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}
120kTypeSpecifierMap = {
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 Dunbard38c11e2009-01-10 01:50:42 +0000140 'f95-cpp-input' : FortranType,
141 'f95' : FortranTypeNoPP,
Daniel Dunbara5677512009-01-05 19:53:30 +0000142 'java' : JavaType,
143 'treelang' : TreelangType,
144}
Daniel Dunbard38c11e2009-01-10 01:50:42 +0000145
146# Check that the type specifier map at least matches what the types
147# believe to be true.
148assert not [name for name,type in kTypeSpecifierMap.items()
149 if type and (type.name != name or not type.canBeUserSpecified)]