blob: 020d3cbfb2a8b0938356e5adc1b4c1ddf2498551 [file] [log] [blame]
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +00001<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3<!-- Material used from: HTML 4.01 specs: http://www.w3.org/TR/html401/ -->
4<html>
5<head>
6 <META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
7 <title>Hacking on clang</title>
8 <link type="text/css" rel="stylesheet" href="menu.css" />
9 <link type="text/css" rel="stylesheet" href="content.css" />
10</head>
11<body>
12<!--#include virtual="menu.html.incl"-->
13<div id="content">
14 <!--*********************************************************************-->
15 <h1>Hacking on Clang</h1>
16 <!--*********************************************************************-->
17
18 <p>This document provides some hints for how to get started hacking
19 on Clang for developers who are new to the Clang and/or LLVM
Daniel Dunbar2f064172008-11-13 23:01:34 +000020 codebases.</p>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000021 <ul>
22 <li><a href="#docs">Developer Documentation</a></li>
23 <li><a href="#debugging">Debugging</a></li>
Daniel Dunbar1f6572c2008-11-18 17:56:21 +000024 <li><a href="#testing">Testing</a></li>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000025 <li><a href="#irgen">LLVM IR Generation</a></li>
26 </ul>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000027
28 <!--=====================================================================-->
Daniel Dunbar2f064172008-11-13 23:01:34 +000029 <h2 id="docs">Developer Documentation</h2>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000030 <!--=====================================================================-->
31
32 <p>Both Clang and LLVM use doxygen to provide API documentation. Their
Daniel Dunbar2f064172008-11-13 23:01:34 +000033 respective web pages (generated nightly) are here:</p>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000034 <ul>
35 <li><a href="http://clang.llvm.org/doxygen">Clang</a></li>
36 <li><a href="http://llvm.org/doxygen">LLVM</a></li>
37 </ul>
Daniel Dunbar2f064172008-11-13 23:01:34 +000038
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000039 <p>For work on the LLVM IR generation, the LLVM assembly language
40 <a href="http://llvm.org/docs/LangRef.html">reference manual</a> is
41 also useful.</p>
42
43 <!--=====================================================================-->
44 <h2 id="debugging">Debugging</h2>
45 <!--=====================================================================-->
46
Daniel Dunbar2f064172008-11-13 23:01:34 +000047 <p>Inspecting data structures in a debugger:</p>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000048 <ul>
49 <li>Many LLVM and Clang data structures provide
50 a <tt>dump()</tt> method which will print a description of the
51 data structure to <tt>stderr</tt>.</li>
52 <li>The <a href="docs/InternalsManual.html#QualType"><tt>QualType</tt></a>
53 structure is used pervasively. This is a simple value class for
54 wrapping types with qualifiers; you can use
55 the <tt>isConstQualified()</tt>, for example, to get one of the
56 qualifiers, and the <tt>getTypePtr()</tt> method to get the
57 wrapped <tt>Type*</tt> which you can then dump.</li>
58 </ul>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000059
60 <!--=====================================================================-->
Daniel Dunbar1f6572c2008-11-18 17:56:21 +000061 <h2 id="testing">Testing</h2>
62 <!--=====================================================================-->
63
64 <p>Clang includes a basic regression suite in the tree which can be
65 run with <tt>make test</tt> from the top-level clang directory, or
66 just <tt>make</tt> in the <em>test</em> sub-directory. <tt>make
67 report</tt> can be used after running the tests to summarize the
68 results, and <tt>make VERBOSE=1</tt> can be used to show more detail
69 about what is being run.</p>
70
Nuno Lopesab4b2ef2008-11-25 15:46:06 +000071 <p>The regression suite can also be run with Valgrind by running
72 <tt>make test VG=1</tt> in the top-level clang directory.</p>
73
Daniel Dunbar1f6572c2008-11-18 17:56:21 +000074 <p>For more intensive changes, running
75 the <a href="http://llvm.org/docs/TestingGuide.html#testsuiterun">LLVM
76 Test Suite</a> with clang is recommended. Currently the best way to
77 override LLVMGCC, as in: <tt>make LLVMGCC="ccc -std=gnu89"
78 TEST=nightly report</tt> (make sure ccc is in your PATH or use the
79 full path).</p>
80
81 <!--=====================================================================-->
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000082 <h2 id="irgen">LLVM IR Generation</h2>
83 <!--=====================================================================-->
84
85 <p>The LLVM IR generation part of clang handles conversion of the
86 AST nodes output by the Sema module to the LLVM Intermediate
87 Representation (IR). Historically, this was referred to as
88 "codegen", and the Clang code for this lives
89 in <tt>lib/CodeGen</tt>.</p>
90
91 <p>The output is most easily inspected using the <tt>-emit-llvm</tt>
92 option to clang (possibly in conjunction with <tt>-o -</tt>). You
93 can also use <tt>-emit-llvm-bc</tt> to write an LLVM bitcode file
94 which can be processed by the suite of LLVM tools
95 like <tt>llvm-dis</tt>, <tt>llvm-nm</tt>, etc. See the LLVM
Daniel Dunbar2f064172008-11-13 23:01:34 +000096 <a href="http://llvm.org/docs/CommandGuide/">Command Guide</a>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000097 for more information.</p>
98
99</div>
100</body>
101</html>