llvm-project/clang/README.txt

181 lines
8.0 KiB
Plaintext
Raw Normal View History

//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//
2006-10-06 13:20:10 +08:00
Chris Lattner
I. Introduction:
clang: noun
1. A loud, resonant, metallic sound.
2. The strident call of a crane or goose.
2007-02-11 16:19:36 +08:00
3. C-language family front-end toolkit.
The world needs better compiler tools, tools which are built as libraries. This
design point allows reuse of the tools in new and novel ways. However, building
the tools as libraries isn't enough: they must have clean APIs, be as
decoupled from each other as possible, and be easy to modify/extend. This
requires clean layering, decent design, and avoiding tying the libraries to a
specific use. Oh yeah, did I mention that we want the resultant libraries to
be as fast as possible? :)
2007-05-31 01:01:31 +08:00
This front-end is built as a component of the LLVM toolkit that can be used
with the LLVM backend or independently of it. In this spirit, the API has been
carefully designed as the following components:
libsupport - Basic support library, reused from LLVM.
libsystem - System abstraction library, reused from LLVM.
2006-10-06 13:20:10 +08:00
libbasic - Diagnostics, SourceLocations, SourceBuffer abstraction,
file system caching for input source files. This depends on
libsupport and libsystem.
libast - Provides classes to represent the C AST, the C type system,
builtin functions, and various helpers for analyzing and
manipulating the AST (visitors, pretty printers, etc). This
library depends on libbasic.
2006-10-06 13:20:10 +08:00
liblex - C/C++/ObjC lexing and preprocessing, identifier hash table,
pragma handling, tokens, and macros. This depends on libbasic.
2007-05-31 01:01:31 +08:00
libparse - C (for now) parsing and local semantic analysis. This library
2006-10-06 13:20:10 +08:00
invokes coarse-grained 'Actions' provided by the client to do
2007-05-31 01:01:31 +08:00
stuff (e.g. libsema builds ASTs). This depends on liblex.
libsema - Provides a set of parser actions to build a standardized AST
for programs. AST's are 'streamed' out a top-level declaration
at a time, allowing clients to use decl-at-a-time processing,
build up entire translation units, or even build 'whole
program' ASTs depending on how they use the APIs. This depends
on libast and libparse.
2007-05-31 01:01:31 +08:00
libcodegen - Lower the AST to LLVM IR for optimization & codegen. Depends
on libast.
2007-02-11 16:19:36 +08:00
clang - An example driver, client of the libraries at various levels.
2007-05-31 01:01:31 +08:00
This depends on all these libraries, and on LLVM VMCore.
2007-07-12 02:58:19 +08:00
This front-end has been intentionally built as a DAG of libraries, making it
easy to reuse individual parts or replace pieces if desired. For example, to
build a preprocessor, you take the Basic and Lexer libraries. If you want an
indexer, you take those plus the Parser library and provide some actions for
indexing. If you want a refactoring, static analysis, or source-to-source
compiler tool, it makes sense to take those plus the AST building and semantic
analyzer library. Finally, if you want to use this with the LLVM backend,
you'd take these components plus the AST to LLVM lowering code.
In the future I hope this toolkit will grow to include new and interesting
2007-02-11 16:19:36 +08:00
components, including a C++ front-end, ObjC support, and a whole lot of other
things.
Finally, it should be pointed out that the goal here is to build something that
is high-quality and industrial-strength: all the obnoxious features of the C
family must be correctly supported (trigraphs, preprocessor arcana, K&R-style
2006-11-06 02:05:21 +08:00
prototypes, GCC/MS extensions, etc). It cannot be used if it is not 'real'.
2006-10-06 13:56:14 +08:00
II. Usage of clang driver:
* Basic Command-Line Options:
- Help: clang --help
2006-10-17 13:20:30 +08:00
- Standard GCC options accepted: -E, -I*, -i*, -pedantic, -std=c90, etc.
2006-11-06 02:05:21 +08:00
- To make diagnostics more gcc-like: -fno-caret-diagnostics -fno-show-column
2006-10-14 13:19:00 +08:00
- Enable metric printing: -stats
2006-10-06 13:56:14 +08:00
2007-07-12 02:58:19 +08:00
* -fsyntax-only is currently the default mode.
2006-10-06 13:56:14 +08:00
2007-07-12 02:58:19 +08:00
* -E mode works the same way as GCC.
2007-05-31 01:01:31 +08:00
* -Eonly mode does all preprocessing, but does not print the output,
useful for timing the preprocessor.
2006-10-06 13:56:14 +08:00
* -fsyntax-only is currently partially implemented, lacking some
semantic analysis (some errors and warnings are not produced).
2007-07-12 02:58:19 +08:00
* -parse-noop parses code without building an AST. This is useful
for timing the cost of the parser without including AST building
time.
* -parse-ast builds ASTs, but doesn't print them. This is most
useful for timing AST building vs -parse-noop.
2006-11-06 02:00:10 +08:00
2007-07-12 02:58:19 +08:00
* -parse-ast-print pretty prints most expression and statements nodes.
2006-10-06 13:56:14 +08:00
* -parse-ast-check checks that diagnostic messages that are expected
are reported and that those which are reported are expected.
* -dump-cfg builds ASTs and then CFGs. CFGs are then pretty-printed.
* -view-cfg builds ASTs and then CFGs. CFGs are then visualized by
invoking Graphviz.
For more information on getting Graphviz to work with clang/LLVM,
see: http://llvm.org/docs/ProgrammersManual.html#ViewGraph
2006-11-06 02:05:21 +08:00
2007-07-12 02:58:19 +08:00
2006-10-06 13:56:14 +08:00
III. Current advantages over GCC:
2006-08-13 02:43:54 +08:00
* Column numbers are fully tracked (no 256 col limit, no GCC-style pruning).
2007-05-31 01:01:31 +08:00
* All diagnostics have column numbers, includes 'caret diagnostics', and they
highlight regions of interesting code (e.g. the LHS and RHS of a binop).
* Full diagnostic customization by client (can format diagnostics however they
2006-10-06 13:56:14 +08:00
like, e.g. in an IDE or refactoring tool) through DiagnosticClient interface.
* Built as a framework, can be reused by multiple tools.
* All languages supported linked into same library (no cc1,cc1obj, ...).
* mmap's code in read-only, does not dirty the pages like GCC (mem footprint).
2007-05-31 01:01:31 +08:00
* LLVM License, can be linked into non-GPL projects.
* Full diagnostic control, per diagnostic. Diagnostics are identified by ID.
* Significantly faster than GCC at semantic analysis, parsing, preprocessing
and lexing.
2006-10-31 08:54:25 +08:00
* Defers exposing platform-specific stuff to as late as possible, tracks use of
platform-specific features (e.g. #ifdef PPC) to allow 'portable bytecodes'.
2006-11-19 09:17:45 +08:00
* The lexer doesn't rely on the "lexer hack": it has no notion of scope and
2007-02-11 16:19:36 +08:00
does not categorize identifiers as types or variables -- this is up to the
2006-11-19 09:17:45 +08:00
parser to decide.
2006-10-31 08:54:25 +08:00
2007-05-31 01:01:31 +08:00
Potential Future Features:
2006-08-14 08:13:31 +08:00
* Fine grained diag control within the source (#pragma enable/disable warning).
* Better token tracking within macros? (Token came from this line, which is
a macro argument instantiated here, recursively instantiated here).
2007-05-31 01:01:31 +08:00
* Fast #import with a module system.
2006-08-11 02:48:21 +08:00
* Dependency tracking: change to header file doesn't recompile every function
that texually depends on it: recompile only those functions that need it.
2007-07-12 02:58:19 +08:00
This is aka 'incremental parsing'.
2006-10-06 13:56:14 +08:00
IV. Missing Functionality / Improvements
clang driver:
2007-07-12 02:58:19 +08:00
* Include search paths are hard-coded into the driver. Doh.
2006-07-19 11:39:58 +08:00
File Manager:
2007-07-12 02:58:19 +08:00
* Reduce syscalls for reduced compile time, see NOTES.txt.
2006-07-19 11:39:58 +08:00
Lexer:
* Source character mapping. GCC supports ASCII and UTF-8.
See GCC options: -ftarget-charset and -ftarget-wide-charset.
* Universal character support. Experimental in GCC, enabled with
-fextended-identifiers.
* -fpreprocessed mode.
Preprocessor:
2006-10-18 12:02:41 +08:00
* Know about apple header maps.
* #assert/#unassert
2006-10-31 08:54:25 +08:00
* #line / #file directives (currently accepted and ignored).
* MSExtension: "L#param" stringizes to a wide string literal.
* Charize extension: "#define F(o) #@o F(a)" -> 'a'.
2006-10-16 06:34:29 +08:00
* Consider merging the parser's expression parser into the preprocessor to
eliminate duplicate code.
* Add support for -M*
Traditional Preprocessor:
2007-07-12 02:58:19 +08:00
* Currently, we have none. :)
2006-08-11 04:00:01 +08:00
Parser:
2007-05-31 01:01:31 +08:00
* C90/K&R modes are only partially implemented.
2007-07-12 02:58:19 +08:00
* __extension__ is currently just skipped and ignored.
2006-10-31 08:54:25 +08:00
* "initializers", GCC inline asm.
2006-10-06 13:40:42 +08:00
2007-02-11 16:19:36 +08:00
Semantic Analysis:
2007-05-31 01:01:31 +08:00
* Perhaps 75% done.
2007-07-12 02:58:19 +08:00
LLVM Code Gen:
* Still very early.
2007-05-31 01:01:31 +08:00