blob: d3d43c25881535470b71dfff10e6fdadc3958f21 [file] [log] [blame]
Chris Lattner97e8b6f2007-10-07 06:04:32 +00001//===--- ASTConsumers.h - ASTConsumer implementations -----------*- C++ -*-===//
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 Consumers.
Reid Spencer5f016e22007-07-11 17:01:13 +000011//
12//===----------------------------------------------------------------------===//
13
Chris Lattner97e8b6f2007-10-07 06:04:32 +000014#ifndef DRIVER_ASTCONSUMERS_H
15#define DRIVER_ASTCONSUMERS_H
Reid Spencer5f016e22007-07-11 17:01:13 +000016
Eli Friedman7df3d712008-02-16 23:17:23 +000017#include <string>
Ted Kremenek1b5a4bd2007-11-27 21:46:50 +000018
Chris Lattnere66b65c2008-02-06 01:42:25 +000019namespace llvm {
Chris Lattner0fa0daa2009-08-24 04:11:30 +000020 class raw_ostream;
Chris Lattnere66b65c2008-02-06 01:42:25 +000021 class Module;
Benjamin Kramerf21efe92009-08-11 17:46:57 +000022 class LLVMContext;
Chris Lattnere66b65c2008-02-06 01:42:25 +000023 namespace sys { class Path; }
24}
Reid Spencer5f016e22007-07-11 17:01:13 +000025namespace clang {
26
Chris Lattner556beb72007-09-15 22:56:56 +000027class ASTConsumer;
Chris Lattnerc0508f92007-09-15 23:21:08 +000028class Diagnostic;
Ted Kremenekdca24662007-12-05 00:26:13 +000029class FileManager;
Chris Lattner3245a0a2008-04-16 06:11:58 +000030class Preprocessor;
Ted Kremenek339b9c22008-04-17 22:31:54 +000031class PreprocessorFactory;
Daniel Dunbareb194852009-07-12 23:52:11 +000032class CompileOptions;
Cedric Venetea684e62009-02-14 16:15:20 +000033class LangOptions;
Ted Kremenek339b9c22008-04-17 22:31:54 +000034
Eli Friedman18d868f2009-05-18 01:16:21 +000035// AST pretty-printer: prints out the AST in a format that is close to the
36// original C code. The output is intended to be in a format such that
37// clang could re-parse the output back into the same AST, but the
38// implementation is still incomplete.
Chris Lattner0fa0daa2009-08-24 04:11:30 +000039ASTConsumer *CreateASTPrinter(llvm::raw_ostream *OS);
Ted Kremenekfdfc1982007-12-19 22:24:34 +000040
Douglas Gregoree75c052009-05-21 20:55:50 +000041// AST XML-printer: prints out the AST in a XML format
42// The output is intended to be in a format such that
43// clang or any other tool could re-parse the output back into the same AST,
44// but the implementation is still incomplete.
Chris Lattner0fa0daa2009-08-24 04:11:30 +000045ASTConsumer *CreateASTPrinterXML(llvm::raw_ostream *OS);
Douglas Gregoree75c052009-05-21 20:55:50 +000046
Eli Friedman18d868f2009-05-18 01:16:21 +000047// AST dumper: dumps the raw AST in human-readable form to stderr; this is
Douglas Gregor4fe0c8e2009-05-30 00:08:05 +000048// intended for debugging.
49ASTConsumer *CreateASTDumper();
Ted Kremenekfdfc1982007-12-19 22:24:34 +000050
Eli Friedman18d868f2009-05-18 01:16:21 +000051// Graphical AST viewer: for each function definition, creates a graph of
52// the AST and displays it with the graph viewer "dotty". Also outputs
53// function declarations to stderr.
Ted Kremenek80de08f2007-09-19 21:29:43 +000054ASTConsumer *CreateASTViewer();
Ted Kremenekfdfc1982007-12-19 22:24:34 +000055
Eli Friedman18d868f2009-05-18 01:16:21 +000056// DeclContext printer: prints out the DeclContext tree in human-readable form
57// to stderr; this is intended for debugging.
Zhongxing Xu2d75d6f2009-01-13 01:29:24 +000058ASTConsumer *CreateDeclContextPrinter();
59
Eli Friedman18d868f2009-05-18 01:16:21 +000060// ObjC rewriter: attempts tp rewrite ObjC constructs into pure C code.
61// This is considered experimental, and only works with Apple's ObjC runtime.
Chris Lattner0fa0daa2009-08-24 04:11:30 +000062ASTConsumer *CreateObjCRewriter(const std::string &InFile,
63 llvm::raw_ostream *OS,
Eli Friedmanbce831b2009-05-18 22:29:17 +000064 Diagnostic &Diags,
Eli Friedmanc6d656e2009-05-18 22:39:16 +000065 const LangOptions &LOpts,
66 bool SilenceRewriteMacroWarning);
Eli Friedman18d868f2009-05-18 01:16:21 +000067
68// LLVM code generator: uses the code generation backend to generate LLVM
69// assembly. This runs optimizations depending on the CompileOptions
70// parameter. The output depends on the Action parameter.
Daniel Dunbard69bacc2008-10-21 23:49:24 +000071enum BackendAction {
Eli Friedman18d868f2009-05-18 01:16:21 +000072 Backend_EmitAssembly, // Emit native assembly
73 Backend_EmitBC, // Emit LLVM bitcode file
74 Backend_EmitLL, // Emit human-readable LLVM assembly
75 Backend_EmitNothing // Don't emit anything (benchmarking mode)
Daniel Dunbard69bacc2008-10-21 23:49:24 +000076};
77ASTConsumer *CreateBackendConsumer(BackendAction Action,
78 Diagnostic &Diags,
79 const LangOptions &Features,
Daniel Dunbar70f92432008-10-23 05:50:47 +000080 const CompileOptions &CompileOpts,
Eli Friedman66d6f042009-05-18 22:20:00 +000081 const std::string &ModuleID,
Owen Anderson42253cc2009-07-01 17:00:06 +000082 llvm::raw_ostream *OS,
Owen Anderson8f1ca782009-07-01 23:14:14 +000083 llvm::LLVMContext& C);
Ted Kremenekfdfc1982007-12-19 22:24:34 +000084
Eli Friedman18d868f2009-05-18 01:16:21 +000085// HTML printer: uses the rewriter to convert source code to HTML with
86// syntax highlighting suitable for viewing in a web-browser.
Eli Friedman66d6f042009-05-18 22:20:00 +000087ASTConsumer* CreateHTMLPrinter(llvm::raw_ostream *OS, Diagnostic &D,
Chris Lattner0b1fb982009-04-10 17:15:23 +000088 Preprocessor *PP, PreprocessorFactory *PPF);
Ted Kremenek6a340832008-03-18 21:19:49 +000089
Eli Friedman18d868f2009-05-18 01:16:21 +000090// PCH generator: generates a precompiled header file; this file can be
91// used later with the PCHReader (clang-cc option -include-pch)
92// to speed up compile times.
Chris Lattnerdf961c22009-04-10 18:08:30 +000093ASTConsumer *CreatePCHGenerator(const Preprocessor &PP,
Douglas Gregore650c8c2009-07-07 00:12:59 +000094 llvm::raw_ostream *OS,
95 const char *isysroot = 0);
Douglas Gregor2cf26342009-04-09 22:27:44 +000096
Eli Friedman18d868f2009-05-18 01:16:21 +000097// Block rewriter: rewrites code using the Apple blocks extension to pure
Eli Friedman66d6f042009-05-18 22:20:00 +000098// C code. Output is always sent to stdout.
Chris Lattner0b1fb982009-04-10 17:15:23 +000099ASTConsumer *CreateBlockRewriter(const std::string &InFile,
Steve Naroff1c9f81b2008-09-17 00:13:27 +0000100 Diagnostic &Diags,
101 const LangOptions &LangOpts);
Eli Friedman18d868f2009-05-18 01:16:21 +0000102
103// Inheritance viewer: for C++ code, creates a graph of the inheritance
104// tree for the given class and displays it with "dotty".
Ted Kremenek7cae2f62008-10-23 23:36:29 +0000105ASTConsumer *CreateInheritanceViewer(const std::string& clsname);
106
Ted Kremenekbe1fe1e2009-02-17 04:27:41 +0000107} // end clang namespace
Ted Kremenekf4381fd2008-07-02 00:03:09 +0000108
Reid Spencer5f016e22007-07-11 17:01:13 +0000109#endif