[llvm-commits] [llvm] r56783 - /llvm/trunk/docs/WritingAnLLVMBackend.html
Matthijs Kooijman
matthijs at stdin.nl
Mon Sep 29 04:52:23 PDT 2008
Author: matthijs
Date: Mon Sep 29 06:52:22 2008
New Revision: 56783
URL: http://llvm.org/viewvc/llvm-project?rev=56783&view=rev
Log:
Add some hands-on documentation about which files to create and edit when
adding a backend.
Modified:
llvm/trunk/docs/WritingAnLLVMBackend.html
Modified: llvm/trunk/docs/WritingAnLLVMBackend.html
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/WritingAnLLVMBackend.html?rev=56783&r1=56782&r2=56783&view=diff
==============================================================================
--- llvm/trunk/docs/WritingAnLLVMBackend.html (original)
+++ llvm/trunk/docs/WritingAnLLVMBackend.html Mon Sep 29 06:52:22 2008
@@ -218,6 +218,56 @@
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>
<!-- *********************************************************************** -->
<div class="doc_section">
More information about the llvm-commits
mailing list