Skip to content

Commit 9429c6b

Browse files
committed
Converted to sphinx/rst and improved some things along the way
1 parent f413bdc commit 9429c6b

File tree

92 files changed

+2601
-2127
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+2601
-2127
lines changed

Makefile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Minimal makefile for Sphinx documentation
2+
#
3+
4+
# You can set these variables from the command line.
5+
SPHINXOPTS =
6+
SPHINXBUILD = sphinx-build-3
7+
SPHINXPROJ = MappingHighLevelConstructstoLLVMIR
8+
SOURCEDIR = .
9+
BUILDDIR = _build
10+
11+
# Put it first so that "make" without argument is like "make help".
12+
help:
13+
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14+
15+
.PHONY: help Makefile
16+
17+
# Catch-all target: route all unknown targets to Sphinx using the new
18+
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19+
%: Makefile
20+
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

README.md

-37
This file was deleted.

README.rst

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
Mapping High Level Constructs to LLVM IR
2+
========================================
3+
4+
`Click here to read the book on
5+
gitbooks.io <https://f0rki.gitbooks.io/mapping-high-level-constructs-to-llvm-ir/content/>`__
6+
7+
About
8+
-----
9+
10+
This is a gitbook dedicated to providing a description on how LLVM based
11+
compilers map high-level language constructs into the LLVM intermediate
12+
representation (IR).
13+
14+
This document targets people interested in how modern compilers work and
15+
want to learn how high-level language constructs can be implemented.
16+
Currently the books focuses on C and C++, but contributions about other
17+
languages targeting LLVM are highly welcome. This document should help
18+
to make the learning curve less steep for aspiring LLVM users.
19+
20+
For the sake of simplicity, we'll be working with a 32-bit target
21+
machine so that pointers and word-sized operands are 32-bits. Also, for
22+
the sake of readability we do not mangle (encode) names. Rather, they
23+
are given simple, easy-to-read names that reflect their purpose. A
24+
production compiler for any language that supports overloading would
25+
generally need to mangle the names so as to avoid conflicts between
26+
symbols.
27+
28+
Contributing
29+
------------
30+
31+
The repository for this gitbook is hosted on
32+
`github <https://github.com/f0rki/mapping-high-level-constructs-to-llvm-ir>`__.
33+
All contributions are welcome. If you find an error file an
34+
`Issue <https://github.com/f0rki/mapping-high-level-constructs-to-llvm-ir/issues>`__
35+
or fork the repository `and create a
36+
pull-request <https://github.com/f0rki/mapping-high-level-constructs-to-llvm-ir/pulls>`__.
37+
38+
License
39+
-------
40+
41+
UNLESS OTHERWISE NOTED, THE CONTENTS OF THIS REPOSITORY ARE LICENSED
42+
UNDER THE CREATIVE COMMONS ATTRIBUTION - SHARE ALIKE 4.0 INTERNATIONAL
43+
LICENSE
44+
45+
.. figure:: https://i.creativecommons.org/l/by-sa/4.0/88x31.png
46+
:alt: https://creativecommons.org/licenses/by-sa/4.0/
47+
48+
https://creativecommons.org/licenses/by-sa/4.0/
49+
50+
51+
.. toctree::
52+
:maxdepth: 1
53+
:caption: Contents:
54+
55+
a-quick-primer/index
56+
basic-constructs/index
57+
control-structures/index
58+
object-oriented-constructs/index
59+
exception-handling/index
60+
advanced-constructs/index
61+
interoperating-with-a-runtime-library/index
62+
interfacing-to-the-operating-system/index
63+
epilogue/index
64+
appendix-a-how-to-implement-a-string-type-in-llvm/index
65+
66+
67+
Indices and tables
68+
------------------
69+
70+
* :ref:`genindex`
71+
* :ref:`modindex`
72+
* :ref:`search`

SUMMARY.md

-42
This file was deleted.

_build/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*
File renamed without changes.
File renamed without changes.

a-quick-primer/README.md

-47
This file was deleted.

a-quick-primer/index.rst

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
**************
2+
A Quick Primer
3+
**************
4+
5+
Here are a few things that you should know before reading this document:
6+
7+
- LLVM IR is not machine code, but sort of the step just above
8+
assembly. So some things look more like a high-level language (like
9+
functions and the strong typing). Other looks more like low-level
10+
assembly (e.g. branching, basic-blocks).
11+
- LLVM IR is strongly typed so expect to be told when you do something
12+
wrong.
13+
- LLVM IR does not differentiate between signed and unsigned integers.
14+
- LLVM IR assumes two's complement signed integers so that say
15+
``trunc`` works equally well on signed and unsigned integers.
16+
- Global symbols begin with an at sign (``@``).
17+
- Local symbols begin with a percent symbol (``%``).
18+
- All symbols must be declared or defined.
19+
- Don't worry that the LLVM IR at times can seem somewhat lengthy when
20+
it comes to expressing something; the optimizer will ensure the
21+
output is well optimized and you'll often see two or three LLVM IR
22+
instructions be coalesced into a single machine code instruction.
23+
- If in doubt, consult the Language Reference. If there is a conflict
24+
between the Language Reference and this document, this document is
25+
wrong!
26+
- All LLVM IR examples are presented without a data layout and without
27+
a target triple. You need to add those yourself, if you want to
28+
actually build and run the samples. Get them from ``clang`` for your
29+
platform.
30+
31+
Some Useful LLVM Tools
32+
----------------------
33+
34+
The most important LLVM tools for use with this article are as follows:
35+
36+
+----------------+----------------+---------------+-----------+---------------------+
37+
| Name | Function | Reads | Writes | Arguments |
38+
+================+================+===============+===========+=====================+
39+
| ``clang`` | C Compiler | ``.c`` | ``.ll`` | ``-emit-llvm -S`` |
40+
+----------------+----------------+---------------+-----------+---------------------+
41+
| ``clang++`` | C++ Compiler | ``.cpp`` | ``.ll`` | ``-emit-llvm -S`` |
42+
+----------------+----------------+---------------+-----------+---------------------+
43+
| ``llvm-dis`` | Disassembler | ``.bc`` | ``.ll`` | |
44+
+----------------+----------------+---------------+-----------+---------------------+
45+
| ``opt`` | Optimizer | ``.bc/.ll`` | same | |
46+
+----------------+----------------+---------------+-----------+---------------------+
47+
| ``llc`` | IR Compiler | ``.ll`` | ``.s`` | |
48+
+----------------+----------------+---------------+-----------+---------------------+
49+
50+
While you are playing around with generating or writing LLVM IR, you may
51+
want to add the option ``-fsanitize=undefined`` to Clang/Clang++ insofar
52+
you use either of those. This option makes Clang/Clang++ insert run-time
53+
checks in places where it would normally output an ``ud2`` instruction.
54+
This will likely save you some trouble if you happen to generate
55+
undefined LLVM IR. Please notice that this option only works for C and
56+
C++ compiles.
57+
58+
Note that you can use ``.ll`` or ``.bc`` files as input files for
59+
``clang(++)`` and compile full executables from bitcode files.

advanced-constructs/README.md

-5
This file was deleted.

advanced-constructs/closures.md

-5
This file was deleted.

advanced-constructs/closures.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Closures
2+
--------

0 commit comments

Comments
 (0)