Add some hands-on documentation about which files to create and edit when
authorMatthijs Kooijman <matthijs@stdin.nl>
Mon, 29 Sep 2008 11:52:22 +0000 (11:52 +0000)
committerMatthijs Kooijman <matthijs@stdin.nl>
Mon, 29 Sep 2008 11:52:22 +0000 (11:52 +0000)
adding a backend.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@56783 91177308-0d34-0410-b5e6-96231b3b80d8

docs/WritingAnLLVMBackend.html

index 909432ef453d74f1276a930a963109a4fac90dd6..bddc021a323e7e6dcea835c2d30ee4ebc2e89d84 100644 (file)
@@ -217,6 +217,56 @@ e.g.:</p>
 <p>For now, just take a look at <tt>lib/Target/CBackend</tt> for an example of
 how the C backend is written.</p>
 
+</div>
+<!-- ======================================================================= -->
+<div class="doc_subsection">
+  <a name="files">Files to create/modify</a>
+</div>
+
+<div class="doc_text">
+
+<p>To actually create your backend, you need to create and modify a few files.
+Here, the absolute minimum will be discussed. To actually use LLVM's target
+independent codegenerator, you must <a href="CodeGenerator.html">implement extra
+things</a>.</p>
+
+<p>First of all, you should create a subdirectory under <tt>lib/Target</tt>,
+which will hold all the files related to your target. Let's assume that our
+target is called, "Dummy", we would create the directory
+<tt>lib/Target/Dummy</tt>.</p>
+
+<p>In this new directory, you should put a <tt>Makefile</tt>. You can probably
+copy one from another target and modify it. It should at least contain the
+<tt>LEVEL</tt>, <tt>LIBRARYNAME</tt> and <tt>TARGET</tt> variables, and then
+include <tt>$(LEVEL)/Makefile.common</tt>. Be careful to give the library the
+correct name, it must be named <tt>LLVMDummy</tt> (see the MIPS target, for
+example). Alternatively, you can split the library into
+<tt>LLVMDummyCodeGen</tt> and <tt>LLVMDummyAsmPrinter</tt>, the latter of which
+should be implemented in a subdirectory below <tt>lib/Target/Dummy</tt> (see the
+PowerPC target, for example).</p>
+
+<p>Note that these two naming schemes are hardcoded into llvm-config. Using any
+other naming scheme will confuse llvm-config and produce lots of (seemingly
+unrelated) linker errors when linking <tt>llc</tt>.</p>
+
+<p>To make your target actually do something, you need to implement a subclass
+of <tt>TargetMachine</tt>. This implementation should typically be in the file
+<tt>lib/Target/DummyTargetMachine.cpp</tt>, but any file in the
+<tt>lib/Target</tt> directory will be built and should work. To use LLVM's <a
+href="CodeGenerator.html">target independent code generator</a>, you should
+create a subclass of <tt>LLVMTargetMachine</tt>. This is what all current
+machine backends do. To create a target from scratch, create a subclass of
+<tt>TargetMachine</tt>. This is what the current language backends do.</p>
+
+<p>To get LLVM to actually build and link your target, you also need to add it
+to the <tt>TARGETS_TO_BUILD</tt> variable. To do this, you need to modify the
+<tt>configure</tt> script to know about your target when parsing the
+<tt>--enable-targets</tt> option. Search the <tt>configure</tt> script for
+<tt>TARGETS_TO_BUILD</tt>, add your target to the lists there (some creativity
+required) and then reconfigure. Alternatively, you can change
+<tt>autotools/configure.ac</tt> and regenerate <tt>configure</tt> by running
+<tt>./autoconf/AutoRegen.sh</tt>.
+
 </div>
 
 <!-- *********************************************************************** -->