blob: b855a93acb2bd5ebd6ed0ec80c72bac5327dbb6b [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>
24 <li><a href="#irgen">LLVM IR Generation</a></li>
25 </ul>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000026
27 <!--=====================================================================-->
Daniel Dunbar2f064172008-11-13 23:01:34 +000028 <h2 id="docs">Developer Documentation</h2>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000029 <!--=====================================================================-->
30
31 <p>Both Clang and LLVM use doxygen to provide API documentation. Their
Daniel Dunbar2f064172008-11-13 23:01:34 +000032 respective web pages (generated nightly) are here:</p>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000033 <ul>
34 <li><a href="http://clang.llvm.org/doxygen">Clang</a></li>
35 <li><a href="http://llvm.org/doxygen">LLVM</a></li>
36 </ul>
Daniel Dunbar2f064172008-11-13 23:01:34 +000037
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000038 <p>For work on the LLVM IR generation, the LLVM assembly language
39 <a href="http://llvm.org/docs/LangRef.html">reference manual</a> is
40 also useful.</p>
41
42 <!--=====================================================================-->
43 <h2 id="debugging">Debugging</h2>
44 <!--=====================================================================-->
45
Daniel Dunbar2f064172008-11-13 23:01:34 +000046 <p>Inspecting data structures in a debugger:</p>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000047 <ul>
48 <li>Many LLVM and Clang data structures provide
49 a <tt>dump()</tt> method which will print a description of the
50 data structure to <tt>stderr</tt>.</li>
51 <li>The <a href="docs/InternalsManual.html#QualType"><tt>QualType</tt></a>
52 structure is used pervasively. This is a simple value class for
53 wrapping types with qualifiers; you can use
54 the <tt>isConstQualified()</tt>, for example, to get one of the
55 qualifiers, and the <tt>getTypePtr()</tt> method to get the
56 wrapped <tt>Type*</tt> which you can then dump.</li>
57 </ul>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000058
59 <!--=====================================================================-->
60 <h2 id="irgen">LLVM IR Generation</h2>
61 <!--=====================================================================-->
62
63 <p>The LLVM IR generation part of clang handles conversion of the
64 AST nodes output by the Sema module to the LLVM Intermediate
65 Representation (IR). Historically, this was referred to as
66 "codegen", and the Clang code for this lives
67 in <tt>lib/CodeGen</tt>.</p>
68
69 <p>The output is most easily inspected using the <tt>-emit-llvm</tt>
70 option to clang (possibly in conjunction with <tt>-o -</tt>). You
71 can also use <tt>-emit-llvm-bc</tt> to write an LLVM bitcode file
72 which can be processed by the suite of LLVM tools
73 like <tt>llvm-dis</tt>, <tt>llvm-nm</tt>, etc. See the LLVM
Daniel Dunbar2f064172008-11-13 23:01:34 +000074 <a href="http://llvm.org/docs/CommandGuide/">Command Guide</a>
Daniel Dunbar0d7c3f92008-11-13 22:49:41 +000075 for more information.</p>
76
77</div>
78</body>
79</html>