blob: 24335cfae039fb362b9664f610dcc4055d2dca2f [file] [log] [blame]
Chris Lattner97e8b6f2007-10-07 06:04:32 +00001//===--- ASTConsumers.cpp - ASTConsumer implementations -------------------===//
Reid Spencer5f016e22007-07-11 17:01:13 +00002//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
8//===----------------------------------------------------------------------===//
9//
Chris Lattner97e8b6f2007-10-07 06:04:32 +000010// AST Consumer Implementations.
Reid Spencer5f016e22007-07-11 17:01:13 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner97e8b6f2007-10-07 06:04:32 +000014#include "ASTConsumers.h"
Zhongxing Xu81488392008-08-24 02:33:36 +000015#include "clang/Driver/HTMLDiagnostics.h"
Ted Kremenek77cda502007-12-18 21:34:28 +000016#include "clang/AST/TranslationUnit.h"
Nico Weberdae86962008-08-09 18:32:11 +000017#include "clang/Basic/Diagnostic.h"
Ted Kremenek54117722007-12-20 00:34:58 +000018#include "clang/Basic/SourceManager.h"
19#include "clang/Basic/FileManager.h"
Reid Spencer5f016e22007-07-11 17:01:13 +000020#include "clang/AST/AST.h"
Chris Lattner3d4997d2007-09-15 23:02:28 +000021#include "clang/AST/ASTConsumer.h"
Ted Kremenek815c78f2008-08-05 18:50:11 +000022#include "clang/CodeGen/ModuleBuilder.h"
23#include "llvm/Module.h"
24#include "llvm/Bitcode/ReaderWriter.h"
Ted Kremenekea75c552007-11-28 21:32:21 +000025#include "llvm/Support/Streams.h"
Ted Kremenekcb330932008-02-18 21:21:23 +000026#include "llvm/Support/Timer.h"
Ted Kremeneka95d3752008-09-13 05:16:45 +000027#include "llvm/Support/raw_ostream.h"
Ted Kremenek4dc41cc2008-03-31 18:26:32 +000028#include "llvm/ADT/OwningPtr.h"
Ted Kremenek815c78f2008-08-05 18:50:11 +000029#include <fstream>
Ted Kremenek4dc41cc2008-03-31 18:26:32 +000030
Chris Lattner6000dac2007-08-08 22:51:59 +000031using namespace clang;
Reid Spencer5f016e22007-07-11 17:01:13 +000032
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000033//===----------------------------------------------------------------------===//
34/// DeclPrinter - Utility class for printing top-level decls.
Chris Lattner6000dac2007-08-08 22:51:59 +000035
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000036namespace {
37 class DeclPrinter {
38 public:
Ted Kremeneka95d3752008-09-13 05:16:45 +000039 llvm::raw_ostream& Out;
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000040
Ted Kremeneka95d3752008-09-13 05:16:45 +000041 DeclPrinter(llvm::raw_ostream* out) : Out(out ? *out : llvm::errs()) {}
42 DeclPrinter() : Out(llvm::errs()) {}
43 virtual ~DeclPrinter();
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000044
Chris Lattneref5a85d2008-01-02 21:04:16 +000045 void PrintDecl(Decl *D);
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000046 void PrintFunctionDeclStart(FunctionDecl *FD);
47 void PrintTypeDefDecl(TypedefDecl *TD);
Chris Lattnerc6fdc342008-01-12 07:05:38 +000048 void PrintLinkageSpec(LinkageSpecDecl *LS);
Ted Kremeneka526c5c2008-01-07 19:49:32 +000049 void PrintObjCMethodDecl(ObjCMethodDecl *OMD);
50 void PrintObjCImplementationDecl(ObjCImplementationDecl *OID);
51 void PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID);
52 void PrintObjCProtocolDecl(ObjCProtocolDecl *PID);
53 void PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID);
54 void PrintObjCCategoryDecl(ObjCCategoryDecl *PID);
55 void PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID);
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +000056 void PrintObjCPropertyDecl(ObjCPropertyDecl *PD);
Fariborz Jahanian628b96f2008-04-23 00:06:01 +000057 void PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID);
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000058 };
59} // end anonymous namespace
60
Ted Kremeneka95d3752008-09-13 05:16:45 +000061DeclPrinter::~DeclPrinter() {
62 Out.flush();
63}
64
Chris Lattneref5a85d2008-01-02 21:04:16 +000065void DeclPrinter:: PrintDecl(Decl *D) {
66 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
67 PrintFunctionDeclStart(FD);
68
69 if (FD->getBody()) {
70 Out << ' ';
71 FD->getBody()->printPretty(Out);
72 Out << '\n';
73 }
Ted Kremeneka526c5c2008-01-07 19:49:32 +000074 } else if (isa<ObjCMethodDecl>(D)) {
Chris Lattneref5a85d2008-01-02 21:04:16 +000075 // Do nothing, methods definitions are printed in
Ted Kremeneka526c5c2008-01-07 19:49:32 +000076 // PrintObjCImplementationDecl.
Chris Lattneref5a85d2008-01-02 21:04:16 +000077 } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
78 PrintTypeDefDecl(TD);
Ted Kremeneka526c5c2008-01-07 19:49:32 +000079 } else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) {
80 PrintObjCInterfaceDecl(OID);
81 } else if (ObjCProtocolDecl *PID = dyn_cast<ObjCProtocolDecl>(D)) {
82 PrintObjCProtocolDecl(PID);
83 } else if (ObjCForwardProtocolDecl *OFPD =
Chris Lattnerc81c8142008-02-25 21:04:36 +000084 dyn_cast<ObjCForwardProtocolDecl>(D)) {
Chris Lattneref5a85d2008-01-02 21:04:16 +000085 Out << "@protocol ";
86 for (unsigned i = 0, e = OFPD->getNumForwardDecls(); i != e; ++i) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +000087 const ObjCProtocolDecl *D = OFPD->getForwardProtocolDecl(i);
Chris Lattneref5a85d2008-01-02 21:04:16 +000088 if (i) Out << ", ";
89 Out << D->getName();
90 }
91 Out << ";\n";
Ted Kremeneka526c5c2008-01-07 19:49:32 +000092 } else if (ObjCImplementationDecl *OID =
Chris Lattnerc81c8142008-02-25 21:04:36 +000093 dyn_cast<ObjCImplementationDecl>(D)) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +000094 PrintObjCImplementationDecl(OID);
95 } else if (ObjCCategoryImplDecl *OID =
Chris Lattnerc81c8142008-02-25 21:04:36 +000096 dyn_cast<ObjCCategoryImplDecl>(D)) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +000097 PrintObjCCategoryImplDecl(OID);
98 } else if (ObjCCategoryDecl *OID =
Chris Lattnerc81c8142008-02-25 21:04:36 +000099 dyn_cast<ObjCCategoryDecl>(D)) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000100 PrintObjCCategoryDecl(OID);
101 } else if (ObjCCompatibleAliasDecl *OID =
Chris Lattnerc81c8142008-02-25 21:04:36 +0000102 dyn_cast<ObjCCompatibleAliasDecl>(D)) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000103 PrintObjCCompatibleAliasDecl(OID);
Chris Lattner23a0e452008-06-21 21:40:20 +0000104 } else if (ObjCClassDecl *OFCD = dyn_cast<ObjCClassDecl>(D)) {
105 Out << "@class ";
106 ObjCInterfaceDecl **ForwardDecls = OFCD->getForwardDecls();
107 for (unsigned i = 0, e = OFCD->getNumForwardDecls(); i != e; ++i) {
108 const ObjCInterfaceDecl *D = ForwardDecls[i];
109 if (i) Out << ", ";
110 Out << D->getName();
111 }
112 Out << ";\n";
Chris Lattneref5a85d2008-01-02 21:04:16 +0000113 } else if (TagDecl *TD = dyn_cast<TagDecl>(D)) {
114 Out << "Read top-level tag decl: '" << TD->getName() << "'\n";
115 } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
116 Out << "Read top-level variable decl: '" << SD->getName() << "'\n";
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000117 } else if (LinkageSpecDecl *LSD = dyn_cast<LinkageSpecDecl>(D)) {
118 PrintLinkageSpec(LSD);
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000119 } else if (FileScopeAsmDecl *AD = dyn_cast<FileScopeAsmDecl>(D)) {
120 Out << "asm(";
121 AD->getAsmString()->printPretty(Out);
122 Out << ")\n";
Chris Lattneref5a85d2008-01-02 21:04:16 +0000123 } else {
124 assert(0 && "Unknown decl type!");
125 }
126}
127
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000128void DeclPrinter::PrintFunctionDeclStart(FunctionDecl *FD) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000129 bool HasBody = FD->getBody();
130
Ted Kremenekea75c552007-11-28 21:32:21 +0000131 Out << '\n';
Chris Lattner70c8b2e2007-08-26 04:02:13 +0000132
133 switch (FD->getStorageClass()) {
134 default: assert(0 && "Unknown storage class");
135 case FunctionDecl::None: break;
Ted Kremenekea75c552007-11-28 21:32:21 +0000136 case FunctionDecl::Extern: Out << "extern "; break;
137 case FunctionDecl::Static: Out << "static "; break;
Ted Kremenek24bd3c42008-04-15 03:57:09 +0000138 case FunctionDecl::PrivateExtern: Out << "__private_extern__ "; break;
Chris Lattner70c8b2e2007-08-26 04:02:13 +0000139 }
140
141 if (FD->isInline())
Ted Kremenekea75c552007-11-28 21:32:21 +0000142 Out << "inline ";
Chris Lattner70c8b2e2007-08-26 04:02:13 +0000143
Reid Spencer5f016e22007-07-11 17:01:13 +0000144 std::string Proto = FD->getName();
Chris Lattner0d6ca112007-12-03 21:43:25 +0000145 const FunctionType *AFT = FD->getType()->getAsFunctionType();
Reid Spencer5f016e22007-07-11 17:01:13 +0000146
Chris Lattner0d6ca112007-12-03 21:43:25 +0000147 if (const FunctionTypeProto *FT = dyn_cast<FunctionTypeProto>(AFT)) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000148 Proto += "(";
149 for (unsigned i = 0, e = FD->getNumParams(); i != e; ++i) {
150 if (i) Proto += ", ";
151 std::string ParamStr;
152 if (HasBody) ParamStr = FD->getParamDecl(i)->getName();
153
154 FT->getArgType(i).getAsStringInternal(ParamStr);
155 Proto += ParamStr;
156 }
157
158 if (FT->isVariadic()) {
159 if (FD->getNumParams()) Proto += ", ";
160 Proto += "...";
161 }
162 Proto += ")";
163 } else {
164 assert(isa<FunctionTypeNoProto>(AFT));
165 Proto += "()";
166 }
167
168 AFT->getResultType().getAsStringInternal(Proto);
Ted Kremenekea75c552007-11-28 21:32:21 +0000169 Out << Proto;
Reid Spencer5f016e22007-07-11 17:01:13 +0000170
Chris Lattner6000dac2007-08-08 22:51:59 +0000171 if (!FD->getBody())
Ted Kremenekea75c552007-11-28 21:32:21 +0000172 Out << ";\n";
Chris Lattner6000dac2007-08-08 22:51:59 +0000173 // Doesn't print the body.
Reid Spencer5f016e22007-07-11 17:01:13 +0000174}
175
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000176void DeclPrinter::PrintTypeDefDecl(TypedefDecl *TD) {
Reid Spencer5f016e22007-07-11 17:01:13 +0000177 std::string S = TD->getName();
178 TD->getUnderlyingType().getAsStringInternal(S);
Ted Kremenekea75c552007-11-28 21:32:21 +0000179 Out << "typedef " << S << ";\n";
Reid Spencer5f016e22007-07-11 17:01:13 +0000180}
181
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000182void DeclPrinter::PrintLinkageSpec(LinkageSpecDecl *LS) {
183 const char *l;
184 if (LS->getLanguage() == LinkageSpecDecl::lang_c)
185 l = "C";
Chris Lattner06767512008-04-08 05:52:18 +0000186 else {
187 assert(LS->getLanguage() == LinkageSpecDecl::lang_cxx &&
188 "unknown language in linkage specification");
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000189 l = "C++";
Chris Lattner06767512008-04-08 05:52:18 +0000190 }
Chris Lattnerc6fdc342008-01-12 07:05:38 +0000191 Out << "extern \"" << l << "\" { ";
192 PrintDecl(LS->getDecl());
193 Out << "}\n";
194}
195
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000196void DeclPrinter::PrintObjCMethodDecl(ObjCMethodDecl *OMD) {
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000197 if (OMD->isInstance())
Ted Kremenekea75c552007-11-28 21:32:21 +0000198 Out << "\n- ";
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000199 else
Ted Kremenekea75c552007-11-28 21:32:21 +0000200 Out << "\n+ ";
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000201 if (!OMD->getResultType().isNull())
Chris Lattnerefe8a962008-08-22 06:59:15 +0000202 Out << '(' << OMD->getResultType().getAsString() << ")";
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000203
Chris Lattnerefe8a962008-08-22 06:59:15 +0000204 std::string name = OMD->getSelector().getName();
205 std::string::size_type pos, lastPos = 0;
Chris Lattner58cce3b2008-03-16 01:07:14 +0000206 for (unsigned i = 0, e = OMD->getNumParams(); i != e; ++i) {
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000207 ParmVarDecl *PDecl = OMD->getParamDecl(i);
Ted Kremenekea75c552007-11-28 21:32:21 +0000208 // FIXME: selector is missing here!
Chris Lattnerefe8a962008-08-22 06:59:15 +0000209 pos = name.find_first_of(":", lastPos);
210 Out << " " << name.substr(lastPos, pos - lastPos);
211 Out << ":(" << PDecl->getType().getAsString() << ")" << PDecl->getName();
212 lastPos = pos + 1;
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000213 }
Chris Lattnerefe8a962008-08-22 06:59:15 +0000214
215 if (OMD->getNumParams() == 0)
216 Out << " " << name;
217
218 if (OMD->isVariadic())
219 Out << ", ...";
220
221 Out << ";";
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000222}
223
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000224void DeclPrinter::PrintObjCImplementationDecl(ObjCImplementationDecl *OID) {
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000225 std::string I = OID->getName();
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000226 ObjCInterfaceDecl *SID = OID->getSuperClass();
Ted Kremenekea75c552007-11-28 21:32:21 +0000227
228 if (SID)
229 Out << "@implementation " << I << " : " << SID->getName();
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000230 else
Ted Kremenekea75c552007-11-28 21:32:21 +0000231 Out << "@implementation " << I;
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000232
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000233 for (ObjCImplementationDecl::instmeth_iterator I = OID->instmeth_begin(),
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000234 E = OID->instmeth_end(); I != E; ++I) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000235 ObjCMethodDecl *OMD = *I;
236 PrintObjCMethodDecl(OMD);
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000237 if (OMD->getBody()) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000238 Out << ' ';
239 OMD->getBody()->printPretty(Out);
240 Out << '\n';
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000241 }
242 }
243
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000244 for (ObjCImplementationDecl::classmeth_iterator I = OID->classmeth_begin(),
Chris Lattnerab4c4d52007-12-12 07:46:12 +0000245 E = OID->classmeth_end(); I != E; ++I) {
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000246 ObjCMethodDecl *OMD = *I;
247 PrintObjCMethodDecl(OMD);
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000248 if (OMD->getBody()) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000249 Out << ' ';
250 OMD->getBody()->printPretty(Out);
251 Out << '\n';
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000252 }
253 }
254
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000255 for (ObjCImplementationDecl::propimpl_iterator I = OID->propimpl_begin(),
256 E = OID->propimpl_end(); I != E; ++I)
257 PrintObjCPropertyImplDecl(*I);
258
Ted Kremenekea75c552007-11-28 21:32:21 +0000259 Out << "@end\n";
Fariborz Jahaniandb8f3d32007-11-10 20:59:13 +0000260}
261
262
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000263void DeclPrinter::PrintObjCInterfaceDecl(ObjCInterfaceDecl *OID) {
Fariborz Jahaniane37882a2007-10-08 23:06:41 +0000264 std::string I = OID->getName();
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000265 ObjCInterfaceDecl *SID = OID->getSuperClass();
Ted Kremenekea75c552007-11-28 21:32:21 +0000266
267 if (SID)
268 Out << "@interface " << I << " : " << SID->getName();
Fariborz Jahaniane37882a2007-10-08 23:06:41 +0000269 else
Ted Kremenekea75c552007-11-28 21:32:21 +0000270 Out << "@interface " << I;
271
Fariborz Jahaniane37882a2007-10-08 23:06:41 +0000272 // Protocols?
Chris Lattner3db6cae2008-07-21 18:19:38 +0000273 const ObjCList<ObjCProtocolDecl> &Protocols = OID->getReferencedProtocols();
274 if (!Protocols.empty()) {
275 for (ObjCList<ObjCProtocolDecl>::iterator I = Protocols.begin(),
276 E = Protocols.end(); I != E; ++I)
277 Out << (I == Protocols.begin() ? '<' : ',') << (*I)->getName();
Fariborz Jahaniane37882a2007-10-08 23:06:41 +0000278 }
Ted Kremenekea75c552007-11-28 21:32:21 +0000279
Chris Lattner3db6cae2008-07-21 18:19:38 +0000280 if (!Protocols.empty())
281 Out << ">";
282 Out << '\n';
Fariborz Jahanianedcfb422007-10-26 16:29:12 +0000283
Chris Lattnerf3a7af92008-03-16 21:08:55 +0000284 if (OID->ivar_size() > 0) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000285 Out << '{';
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000286 for (ObjCInterfaceDecl::ivar_iterator I = OID->ivar_begin(),
Chris Lattnerbe6df082007-12-12 07:56:42 +0000287 E = OID->ivar_end(); I != E; ++I) {
288 Out << '\t' << (*I)->getType().getAsString()
289 << ' ' << (*I)->getName() << ";\n";
Fariborz Jahanianedcfb422007-10-26 16:29:12 +0000290 }
Ted Kremenekea75c552007-11-28 21:32:21 +0000291 Out << "}\n";
Fariborz Jahanianedcfb422007-10-26 16:29:12 +0000292 }
Fariborz Jahanian82a5fe32007-11-06 22:01:00 +0000293
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000294 for (ObjCInterfaceDecl::classprop_iterator I = OID->classprop_begin(),
295 E = OID->classprop_end(); I != E; ++I)
296 PrintObjCPropertyDecl(*I);
Fariborz Jahanian33de3f02008-05-07 17:43:59 +0000297 bool eol_needed = false;
Fariborz Jahanianb89ca232008-05-06 23:14:25 +0000298 for (ObjCInterfaceDecl::classmeth_iterator I = OID->classmeth_begin(),
299 E = OID->classmeth_end(); I != E; ++I)
Fariborz Jahanian33de3f02008-05-07 17:43:59 +0000300 eol_needed = true, PrintObjCMethodDecl(*I);
Fariborz Jahanianb89ca232008-05-06 23:14:25 +0000301
302 for (ObjCInterfaceDecl::instmeth_iterator I = OID->instmeth_begin(),
303 E = OID->instmeth_end(); I != E; ++I)
Fariborz Jahanian33de3f02008-05-07 17:43:59 +0000304 eol_needed = true, PrintObjCMethodDecl(*I);
Fariborz Jahanianb89ca232008-05-06 23:14:25 +0000305
Fariborz Jahanian33de3f02008-05-07 17:43:59 +0000306 Out << (eol_needed ? "\n@end\n" : "@end\n");
Steve Naroff2bd42fa2007-09-10 20:51:04 +0000307 // FIXME: implement the rest...
308}
309
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000310void DeclPrinter::PrintObjCProtocolDecl(ObjCProtocolDecl *PID) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000311 Out << "@protocol " << PID->getName() << '\n';
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000312
313 for (ObjCProtocolDecl::classprop_iterator I = PID->classprop_begin(),
314 E = PID->classprop_end(); I != E; ++I)
315 PrintObjCPropertyDecl(*I);
316 Out << "@end\n";
Fariborz Jahanianab0aeb02007-10-08 18:53:38 +0000317 // FIXME: implement the rest...
318}
319
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000320void DeclPrinter::PrintObjCCategoryImplDecl(ObjCCategoryImplDecl *PID) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000321 Out << "@implementation "
322 << PID->getClassInterface()->getName()
323 << '(' << PID->getName() << ");\n";
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000324 for (ObjCCategoryImplDecl::propimpl_iterator I = PID->propimpl_begin(),
325 E = PID->propimpl_end(); I != E; ++I)
326 PrintObjCPropertyImplDecl(*I);
327 Out << "@end\n";
Fariborz Jahanianab0aeb02007-10-08 18:53:38 +0000328 // FIXME: implement the rest...
329}
330
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000331void DeclPrinter::PrintObjCCategoryDecl(ObjCCategoryDecl *PID) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000332 Out << "@interface "
333 << PID->getClassInterface()->getName()
334 << '(' << PID->getName() << ");\n";
Fariborz Jahanian7e7e3872008-04-16 21:08:45 +0000335 // Output property declarations.
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000336 for (ObjCCategoryDecl::classprop_iterator I = PID->classprop_begin(),
337 E = PID->classprop_end(); I != E; ++I)
338 PrintObjCPropertyDecl(*I);
Fariborz Jahanian7e7e3872008-04-16 21:08:45 +0000339 Out << "@end\n";
340
Fariborz Jahanianab0aeb02007-10-08 18:53:38 +0000341 // FIXME: implement the rest...
342}
343
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000344void DeclPrinter::PrintObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *AID) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000345 Out << "@compatibility_alias " << AID->getName()
346 << ' ' << AID->getClassInterface()->getName() << ";\n";
Fariborz Jahanian243b64b2007-10-11 23:42:27 +0000347}
348
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000349/// PrintObjCPropertyDecl - print a property declaration.
350///
351void DeclPrinter::PrintObjCPropertyDecl(ObjCPropertyDecl *PDecl) {
Fariborz Jahanian46b55e52008-05-05 18:51:55 +0000352 if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Required)
353 Out << "@required\n";
354 else if (PDecl->getPropertyImplementation() == ObjCPropertyDecl::Optional)
355 Out << "@optional\n";
356
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000357 Out << "@property";
358 if (PDecl->getPropertyAttributes() != ObjCPropertyDecl::OBJC_PR_noattr) {
359 bool first = true;
360 Out << " (";
361 if (PDecl->getPropertyAttributes() &
362 ObjCPropertyDecl::OBJC_PR_readonly) {
363 Out << (first ? ' ' : ',') << "readonly";
364 first = false;
365 }
366
367 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_getter) {
368 Out << (first ? ' ' : ',') << "getter = "
Fariborz Jahanian5251e132008-05-06 18:09:04 +0000369 << PDecl->getGetterName().getName();
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000370 first = false;
371 }
372 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_setter) {
373 Out << (first ? ' ' : ',') << "setter = "
Fariborz Jahanian5251e132008-05-06 18:09:04 +0000374 << PDecl->getSetterName().getName();
Fariborz Jahanian3dd4ba42008-04-17 18:25:18 +0000375 first = false;
376 }
377
378 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_assign) {
379 Out << (first ? ' ' : ',') << "assign";
380 first = false;
381 }
382
383 if (PDecl->getPropertyAttributes() &
384 ObjCPropertyDecl::OBJC_PR_readwrite) {
385 Out << (first ? ' ' : ',') << "readwrite";
386 first = false;
387 }
388
389 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_retain) {
390 Out << (first ? ' ' : ',') << "retain";
391 first = false;
392 }
393
394 if (PDecl->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_copy) {
395 Out << (first ? ' ' : ',') << "copy";
396 first = false;
397 }
398
399 if (PDecl->getPropertyAttributes() &
400 ObjCPropertyDecl::OBJC_PR_nonatomic) {
401 Out << (first ? ' ' : ',') << "nonatomic";
402 first = false;
403 }
404 Out << " )";
405 }
406 Out << ' ' << PDecl->getType().getAsString()
407 << ' ' << PDecl->getName();
408
409 Out << ";\n";
410}
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000411
412/// PrintObjCPropertyImplDecl - Print an objective-c property implementation
413/// declaration syntax.
414///
415void DeclPrinter::PrintObjCPropertyImplDecl(ObjCPropertyImplDecl *PID) {
Daniel Dunbar9f0afd42008-08-26 04:47:31 +0000416 if (PID->getPropertyImplementation() == ObjCPropertyImplDecl::Synthesize)
Fariborz Jahanian628b96f2008-04-23 00:06:01 +0000417 Out << "\n@synthesize ";
418 else
419 Out << "\n@dynamic ";
420 Out << PID->getPropertyDecl()->getName();
421 if (PID->getPropertyIvarDecl())
422 Out << "=" << PID->getPropertyIvarDecl()->getName();
423 Out << ";\n";
424}
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000425//===----------------------------------------------------------------------===//
426/// ASTPrinter - Pretty-printer of ASTs
427
Chris Lattner3d4997d2007-09-15 23:02:28 +0000428namespace {
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000429 class ASTPrinter : public ASTConsumer, public DeclPrinter {
430 public:
Ted Kremeneka95d3752008-09-13 05:16:45 +0000431 ASTPrinter(llvm::raw_ostream* o = NULL) : DeclPrinter(o) {}
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000432
Chris Lattner3d4997d2007-09-15 23:02:28 +0000433 virtual void HandleTopLevelDecl(Decl *D) {
Chris Lattneref5a85d2008-01-02 21:04:16 +0000434 PrintDecl(D);
Reid Spencer5f016e22007-07-11 17:01:13 +0000435 }
Chris Lattner3d4997d2007-09-15 23:02:28 +0000436 };
Reid Spencer5f016e22007-07-11 17:01:13 +0000437}
Chris Lattner6000dac2007-08-08 22:51:59 +0000438
Ted Kremeneka95d3752008-09-13 05:16:45 +0000439ASTConsumer *clang::CreateASTPrinter(llvm::raw_ostream* out) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000440 return new ASTPrinter(out);
441}
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000442
443//===----------------------------------------------------------------------===//
444/// ASTDumper - Low-level dumper of ASTs
Chris Lattner3d4997d2007-09-15 23:02:28 +0000445
446namespace {
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000447 class ASTDumper : public ASTConsumer, public DeclPrinter {
Chris Lattner3d4997d2007-09-15 23:02:28 +0000448 SourceManager *SM;
449 public:
Ted Kremenekea75c552007-11-28 21:32:21 +0000450 ASTDumper() : DeclPrinter() {}
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000451
Ted Kremenek95041a22007-12-19 22:51:13 +0000452 void Initialize(ASTContext &Context) {
Ted Kremenek7a9d49f2007-12-11 21:27:55 +0000453 SM = &Context.getSourceManager();
Chris Lattner6000dac2007-08-08 22:51:59 +0000454 }
Chris Lattner3d4997d2007-09-15 23:02:28 +0000455
456 virtual void HandleTopLevelDecl(Decl *D) {
457 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
458 PrintFunctionDeclStart(FD);
459
460 if (FD->getBody()) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000461 Out << '\n';
462 // FIXME: convert dumper to use std::ostream?
Chris Lattner3d4997d2007-09-15 23:02:28 +0000463 FD->getBody()->dumpAll(*SM);
Ted Kremenekea75c552007-11-28 21:32:21 +0000464 Out << '\n';
Chris Lattner3d4997d2007-09-15 23:02:28 +0000465 }
466 } else if (TypedefDecl *TD = dyn_cast<TypedefDecl>(D)) {
467 PrintTypeDefDecl(TD);
468 } else if (ScopedDecl *SD = dyn_cast<ScopedDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000469 Out << "Read top-level variable decl: '" << SD->getName() << "'\n";
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000470 } else if (ObjCInterfaceDecl *OID = dyn_cast<ObjCInterfaceDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000471 Out << "Read objc interface '" << OID->getName() << "'\n";
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000472 } else if (ObjCProtocolDecl *OPD = dyn_cast<ObjCProtocolDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000473 Out << "Read objc protocol '" << OPD->getName() << "'\n";
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000474 } else if (ObjCCategoryDecl *OCD = dyn_cast<ObjCCategoryDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000475 Out << "Read objc category '" << OCD->getName() << "'\n";
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000476 } else if (isa<ObjCForwardProtocolDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000477 Out << "Read objc fwd protocol decl\n";
Ted Kremeneka526c5c2008-01-07 19:49:32 +0000478 } else if (isa<ObjCClassDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000479 Out << "Read objc fwd class decl\n";
Anders Carlssondfab6cb2008-02-08 00:33:21 +0000480 } else if (isa<FileScopeAsmDecl>(D)) {
481 Out << "Read file scope asm decl\n";
Ted Kremenek63bbe532008-03-14 17:31:00 +0000482 } else if (ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(D)) {
483 Out << "Read objc method decl: '" << MD->getSelector().getName()
484 << "'\n";
Steve Naroff1a2b90d2008-05-23 18:50:58 +0000485 if (MD->getBody()) {
486 // FIXME: convert dumper to use std::ostream?
487 MD->getBody()->dumpAll(*SM);
488 Out << '\n';
489 }
Ted Kremenek63bbe532008-03-14 17:31:00 +0000490 } else if (isa<ObjCImplementationDecl>(D)) {
491 Out << "Read objc implementation decl\n";
Daniel Dunbar539ced12008-10-05 00:31:15 +0000492 } else if (isa<ObjCCategoryImplDecl>(D)) {
493 Out << "Read objc category implementation decl\n";
Ted Kremenek63bbe532008-03-14 17:31:00 +0000494 }
495 else {
Chris Lattner9fa5e652007-10-06 18:52:10 +0000496 assert(0 && "Unknown decl type!");
Chris Lattner3d4997d2007-09-15 23:02:28 +0000497 }
498 }
499 };
Chris Lattner6000dac2007-08-08 22:51:59 +0000500}
501
Chris Lattner3d4997d2007-09-15 23:02:28 +0000502ASTConsumer *clang::CreateASTDumper() { return new ASTDumper(); }
503
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +0000504//===----------------------------------------------------------------------===//
505/// ASTViewer - AST Visualization
506
Ted Kremenek80de08f2007-09-19 21:29:43 +0000507namespace {
508 class ASTViewer : public ASTConsumer {
509 SourceManager *SM;
510 public:
Ted Kremenek95041a22007-12-19 22:51:13 +0000511 void Initialize(ASTContext &Context) {
Ted Kremenek7a9d49f2007-12-11 21:27:55 +0000512 SM = &Context.getSourceManager();
Ted Kremenek80de08f2007-09-19 21:29:43 +0000513 }
514
515 virtual void HandleTopLevelDecl(Decl *D) {
516 if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000517 DeclPrinter().PrintFunctionDeclStart(FD);
Ted Kremenek80de08f2007-09-19 21:29:43 +0000518
519 if (FD->getBody()) {
Ted Kremenekea75c552007-11-28 21:32:21 +0000520 llvm::cerr << '\n';
Ted Kremenek80de08f2007-09-19 21:29:43 +0000521 FD->getBody()->viewAST();
Ted Kremenekea75c552007-11-28 21:32:21 +0000522 llvm::cerr << '\n';
Ted Kremenek80de08f2007-09-19 21:29:43 +0000523 }
524 }
Ted Kremenek63bbe532008-03-14 17:31:00 +0000525 else if (ObjCMethodDecl *MD = dyn_cast<ObjCMethodDecl>(D)) {
526 DeclPrinter().PrintObjCMethodDecl(MD);
527
528 if (MD->getBody()) {
529 llvm::cerr << '\n';
530 MD->getBody()->viewAST();
531 llvm::cerr << '\n';
532 }
533 }
Ted Kremenek80de08f2007-09-19 21:29:43 +0000534 }
535 };
536}
537
538ASTConsumer *clang::CreateASTViewer() { return new ASTViewer(); }
539
Ted Kremenek74bf2c92007-09-07 23:47:56 +0000540//===----------------------------------------------------------------------===//
Ted Kremeneka1fa3a12007-12-13 00:37:31 +0000541// AST Serializer
542
543namespace {
Ted Kremenekf06c9282007-12-19 23:49:37 +0000544
545class ASTSerializer : public ASTConsumer {
546protected:
Nico Weberdae86962008-08-09 18:32:11 +0000547 Diagnostic& Diags;
Ted Kremenekc1e9dea2008-04-23 16:25:39 +0000548
Ted Kremenekf06c9282007-12-19 23:49:37 +0000549public:
Nico Weberbe1eb5c2008-08-10 19:20:05 +0000550 ASTSerializer(Diagnostic& diags) : Diags(diags) {}
Ted Kremenekf06c9282007-12-19 23:49:37 +0000551};
Eli Friedmand8a65c12008-06-09 20:02:51 +0000552
Ted Kremenekf06c9282007-12-19 23:49:37 +0000553class SingleFileSerializer : public ASTSerializer {
554 const llvm::sys::Path FName;
555public:
Nico Weberdae86962008-08-09 18:32:11 +0000556 SingleFileSerializer(const llvm::sys::Path& F, Diagnostic& diags)
557 : ASTSerializer(diags), FName(F) {}
Ted Kremenekf06c9282007-12-19 23:49:37 +0000558
Nico Weberbe1eb5c2008-08-10 19:20:05 +0000559 virtual void HandleTranslationUnit(TranslationUnit& TU) {
Nico Weberdae86962008-08-09 18:32:11 +0000560 if (Diags.hasErrorOccurred())
561 return;
Nico Weberbe1eb5c2008-08-10 19:20:05 +0000562 EmitASTBitcodeFile(&TU, FName);
Ted Kremenekf06c9282007-12-19 23:49:37 +0000563 }
564};
565
566class BuildSerializer : public ASTSerializer {
567 llvm::sys::Path EmitDir;
568public:
Nico Weberdae86962008-08-09 18:32:11 +0000569 BuildSerializer(const llvm::sys::Path& dir, Diagnostic& diags)
570 : ASTSerializer(diags), EmitDir(dir) {}
Ted Kremenekf06c9282007-12-19 23:49:37 +0000571
Nico Weberbe1eb5c2008-08-10 19:20:05 +0000572 virtual void HandleTranslationUnit(TranslationUnit& TU) {
573 if (Diags.hasErrorOccurred())
Ted Kremenekc1e9dea2008-04-23 16:25:39 +0000574 return;
575
Nico Weberbe1eb5c2008-08-10 19:20:05 +0000576 SourceManager& SourceMgr = TU.getContext().getSourceManager();
Ted Kremenek54117722007-12-20 00:34:58 +0000577 unsigned ID = SourceMgr.getMainFileID();
578 assert (ID && "MainFileID not set!");
579 const FileEntry* FE = SourceMgr.getFileEntryForID(ID);
580 assert (FE && "No FileEntry for main file.");
581
582 // FIXME: This is not portable to Windows.
583 // FIXME: This logic should probably be moved elsewhere later.
584
Ted Kremenekee533642007-12-20 19:47:16 +0000585 llvm::sys::Path FName(EmitDir);
Ted Kremenek54117722007-12-20 00:34:58 +0000586
587 std::vector<char> buf;
588 buf.reserve(strlen(FE->getName())+100);
589
590 sprintf(&buf[0], "dev_%llx", (uint64_t) FE->getDevice());
Ted Kremenekee533642007-12-20 19:47:16 +0000591 FName.appendComponent(&buf[0]);
592 FName.createDirectoryOnDisk(true);
593 if (!FName.canWrite() || !FName.isDirectory()) {
Ted Kremenek54117722007-12-20 00:34:58 +0000594 assert (false && "Could not create 'device' serialization directory.");
595 return;
596 }
Ted Kremenekee533642007-12-20 19:47:16 +0000597
Ted Kremenek54117722007-12-20 00:34:58 +0000598 sprintf(&buf[0], "%s-%llX.ast", FE->getName(), (uint64_t) FE->getInode());
Ted Kremenekee533642007-12-20 19:47:16 +0000599 FName.appendComponent(&buf[0]);
Nico Weberbe1eb5c2008-08-10 19:20:05 +0000600 EmitASTBitcodeFile(&TU, FName);
Ted Kremenek54117722007-12-20 00:34:58 +0000601
Ted Kremenekee533642007-12-20 19:47:16 +0000602 // Now emit the sources.
603
Ted Kremenek54117722007-12-20 00:34:58 +0000604 }
Ted Kremenekf06c9282007-12-19 23:49:37 +0000605};
606
607
Ted Kremeneka1fa3a12007-12-13 00:37:31 +0000608} // end anonymous namespace
609
610
Ted Kremenekfdfc1982007-12-19 22:24:34 +0000611ASTConsumer* clang::CreateASTSerializer(const std::string& InFile,
Ted Kremenekf06c9282007-12-19 23:49:37 +0000612 const std::string& OutputFile,
Ted Kremeneke7d07d12008-06-04 15:55:15 +0000613 Diagnostic &Diags) {
Ted Kremenek3910c7c2007-12-19 17:25:59 +0000614
Ted Kremenekf06c9282007-12-19 23:49:37 +0000615 if (OutputFile.size()) {
Ted Kremenek54117722007-12-20 00:34:58 +0000616 if (InFile == "-") {
617 llvm::cerr <<
618 "error: Cannot use --serialize with -o for source read from STDIN.\n";
619 return NULL;
620 }
621
Ted Kremenekf06c9282007-12-19 23:49:37 +0000622 // The user specified an AST-emission directory. Determine if the path
623 // is absolute.
624 llvm::sys::Path EmitDir(OutputFile);
625
626 if (!EmitDir.isAbsolute()) {
627 llvm::cerr <<
628 "error: Output directory for --serialize must be an absolute path.\n";
629
630 return NULL;
631 }
632
633 // Create the directory if it does not exist.
634 EmitDir.createDirectoryOnDisk(true);
635 if (!EmitDir.canWrite() || !EmitDir.isDirectory()) {
636 llvm::cerr <<
637 "error: Could not create output directory for --serialize.\n";
638
639 return NULL;
640 }
641
Ted Kremenek54117722007-12-20 00:34:58 +0000642 // FIXME: We should probably only allow using BuildSerializer when
643 // the ASTs come from parsed source files, and not from .ast files.
Nico Weberdae86962008-08-09 18:32:11 +0000644 return new BuildSerializer(EmitDir, Diags);
Ted Kremenekf06c9282007-12-19 23:49:37 +0000645 }
646
647 // The user did not specify an output directory for serialized ASTs.
648 // Serialize the translation to a single file whose name is the same
649 // as the input file with the ".ast" extension appended.
Ted Kremenek63ea8632007-12-19 19:27:38 +0000650
Ted Kremenekf06c9282007-12-19 23:49:37 +0000651 llvm::sys::Path FName(InFile.c_str());
Ted Kremenek54117722007-12-20 00:34:58 +0000652 FName.appendSuffix("ast");
Nico Weberdae86962008-08-09 18:32:11 +0000653 return new SingleFileSerializer(FName, Diags);
Ted Kremeneka1fa3a12007-12-13 00:37:31 +0000654}
Ted Kremenek815c78f2008-08-05 18:50:11 +0000655
656class LLVMCodeGenWriter : public ASTConsumer {
657 llvm::OwningPtr<CodeGenerator> Gen;
658 const std::string &InFile;
659 const std::string &OutputFile;
660 bool EmitBitcode;
661public:
662
663 LLVMCodeGenWriter(bool EmitBC, Diagnostic &Diags, const LangOptions &Features,
664 const std::string& infile, const std::string& outfile,
665 bool GenerateDebugInfo)
666 : Gen(CreateLLVMCodeGen(Diags, Features, infile, GenerateDebugInfo)),
667 InFile(infile), OutputFile(outfile), EmitBitcode(EmitBC) {}
668
669 virtual void Initialize(ASTContext &Context) {
670 Gen->Initialize(Context);
671 }
Matthijs Kooijman992a8782008-08-07 16:04:15 +0000672
673 virtual void InitializeTU(TranslationUnit& TU) {
674 Gen->InitializeTU(TU);
675 }
Ted Kremenek815c78f2008-08-05 18:50:11 +0000676
677 virtual void HandleTopLevelDecl(Decl *D) {
678 Gen->HandleTopLevelDecl(D);
679 }
680
Matthijs Kooijman992a8782008-08-07 16:04:15 +0000681 virtual void HandleTranslationUnit(TranslationUnit& TU) {
682 Gen->HandleTranslationUnit(TU);
683 }
684
Ted Kremenek815c78f2008-08-05 18:50:11 +0000685 virtual void HandleTagDeclDefinition(TagDecl *D) {
686 Gen->HandleTagDeclDefinition(D);
687 }
Matthijs Kooijman992a8782008-08-07 16:04:15 +0000688
Ted Kremenek815c78f2008-08-05 18:50:11 +0000689 virtual ~LLVMCodeGenWriter() {
690 llvm::OwningPtr<llvm::Module> CodeGenModule(Gen->ReleaseModule());
691
692 if (!CodeGenModule)
693 return;
694
695 std::ostream *Out;
696
697 if (OutputFile == "-") {
698 Out = llvm::cout.stream();
699 } else if (!OutputFile.empty()) {
700 Out = new std::ofstream(OutputFile.c_str(),
701 std::ios_base::binary|std::ios_base::out);
702 } else if (InFile == "-") {
703 Out = llvm::cout.stream();
704 } else {
705 llvm::sys::Path Path(InFile);
706 Path.eraseSuffix();
707 if (!EmitBitcode)
708 Path.appendSuffix("ll");
709 else
710 Path.appendSuffix("bc");
711
712 Out = new std::ofstream(Path.toString().c_str(),
713 std::ios_base::binary|std::ios_base::out);
714 }
715
716 if (!EmitBitcode)
Chris Lattner405674c2008-08-23 22:23:37 +0000717 *Out << *CodeGenModule.get();
Ted Kremenek815c78f2008-08-05 18:50:11 +0000718 else
719 llvm::WriteBitcodeToFile(CodeGenModule.get(), *Out);
720
721 if (Out != llvm::cout.stream())
722 delete Out;
723 }
724};
725
726ASTConsumer *clang::CreateLLVMCodeGenWriter(bool EmitBC, Diagnostic &Diags,
727 const LangOptions &Features,
728 const std::string& InFile,
729 const std::string& OutFile,
730 bool GenerateDebugInfo) {
731
732 return new LLVMCodeGenWriter(EmitBC, Diags, Features, InFile, OutFile,
733 GenerateDebugInfo);
734}