├── .gitattributes ├── .gitignore ├── BUILD.md ├── README.md ├── RESOURCES.md ├── bin ├── llvm │ └── build.bat ├── pelook.exe ├── updatemds.bat └── vswhere.exe ├── docs ├── 2002-08-09-LLVMCompilationStrategy.pdf ├── 2002-08-09-LLVMCompilationStrategy.txt ├── 2002-12-LattnerMSThesis.pdf ├── 2002-12-LattnerMSThesis.txt ├── 2015_1405.4565.pdf ├── 2015_1405.4565.txt ├── 2016_VMIL_Efficient_Execution_of_LLVM_IR_on_Truffle.pdf ├── 2016_VMIL_Efficient_Execution_of_LLVM_IR_on_Truffle.txt ├── 2018_LLVM_Documentation_Release_8.pdf ├── 2018_LLVM_Documentation_Release_8.txt ├── 2018_Rigger_Safe_and_Efficient_Execution_of LLVM_based_Languages.pdf ├── 2018_Rigger_Safe_and_Efficient_Execution_of LLVM_based_Languages.txt ├── 2021_PLDI_Alive2.pdf ├── 2021_PLDI_Alive2.txt ├── 2024_First_Steps_towards_Deductive_Verification_of_LLVM_IR.pdf ├── 2024_First_Steps_towards_Deductive_Verification_of_LLVM_IR.txt ├── TutorialLLVMBackendCpu0.pdf ├── TutorialLLVMBackendCpu0.txt └── images │ └── llvm.png ├── examples ├── JITTutorial1 │ ├── 00download.txt │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── Makefile │ ├── build.bat │ ├── build.sh │ └── src │ │ └── tut1.cpp ├── JITTutorial1_main │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── Makefile │ ├── build.bat │ └── src │ │ ├── main.cpp │ │ ├── tut1.cpp │ │ └── tut1.h ├── JITTutorial2 │ ├── 00download.txt │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── Makefile │ ├── build.bat │ └── src │ │ └── tut2.cpp ├── JITTutorial2_main │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── Makefile │ ├── build.bat │ └── src │ │ ├── main.cpp │ │ ├── tut2.cpp │ │ ├── tut2.h │ │ ├── utils.cpp │ │ └── utils.h ├── Makefile.inc ├── README.md ├── hello │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── Makefile │ ├── build.bat │ └── src │ │ └── main │ │ ├── c │ │ └── hello.c │ │ └── cpp │ │ └── hello.cpp └── llvm-hello │ ├── .gitignore │ ├── 00download.txt │ ├── CMakeLists.txt │ ├── Doxyfile │ ├── Makefile │ ├── build.bat │ └── src │ └── main │ └── cpp │ └── main.cpp ├── llvm-essentials ├── 1_2_Getting_familiar_with_LLVM_IR │ ├── Makefile │ ├── build.bat │ └── src │ │ └── add.c ├── 3_2_Getting_address_of_element │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── toy.cpp ├── 3_3_Reading_from_memory │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── toy.cpp ├── 3_4_Writing_to_memory │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── toy.cpp ├── 3_5_Inserting_a_scalar_into_a_vector │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── toy.cpp ├── 3_6_Extracting_a_scalar_from_a_vector │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── toy.cpp ├── 5_1_Loop_processing │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── toy.cpp ├── 5_2_Scalar_evolution │ ├── CMakeLists.txt │ ├── build.bat │ └── src │ │ └── scalevl.cpp ├── Makefile.inc └── README.md ├── setenv.bat └── setenv.sh /.gitattributes: -------------------------------------------------------------------------------- 1 | # Set the default behavior, in case people don't have core.autocrlf set. 2 | * text=auto 3 | 4 | # Explicitly declare text files you want to always be normalized and converted 5 | # to native line endings on checkout. 6 | # (see https://github.com/github-linguist/linguist/blob/master/lib/linguist/languages.yml) 7 | *.ada text linguist-language=Ada 8 | *.adb text linguist-language=Ada 9 | *.adc text linguist-language=Ada 10 | *.ads text linguist-language=Ada 11 | *.awk text linguist-language=Awk 12 | *.c text linguist-language=C 13 | *.cabal text linguist-language=Cabal Config 14 | *.cbl text linguist-language=COBOL 15 | *.cob text linguist-language=COBOL 16 | *.cpp text linguist-language=C++ 17 | *.cpy text linguist-language=COBOL 18 | *.cs text linguist-language=CSharp 19 | *.daml text linguist-language=Haskell 20 | *.dart text linguist-language=Dart 21 | *.erl text linguist-language=Erlang 22 | *.es text linguist-language=JavaScript 23 | *.flix text linguist-language=Flix 24 | *.go text linguist-language=Go 25 | *.h text linguist-language=C 26 | *.hpp text linguist-language=C++ 27 | *.hs text linguist-language=Haskell 28 | *.hsc text linguist-language=Haskell 29 | *.inc text linguist-language=Makefile 30 | *.ini text linguist-language=INI 31 | *.java text linguist-language=Java 32 | *.js text linguist-language=JavaScript 33 | *.json text linguist-language=JSON 34 | *.jsx text linguist-language=JavaScript 35 | *.kt text linguist-language=Kotlin 36 | *.kts text linguist-language=Kotlin 37 | *.md text linguist-documentation=true 38 | *.mod test linguist-language=Modula-2 39 | *.properties text linguist-language=INI 40 | *.py text linguist-language=Python 41 | *.rs text linguist-language=Rust 42 | *.sbt text linguist-language=Scala 43 | *.sc text linguist-language=Scala 44 | *.scala text linguist-language=Scala 45 | *.txt text linguist-language=Text 46 | *.xml text linguist-language=XML 47 | *.xslt text linguist-language=XSLT 48 | *.wxi text linguist-language=XML 49 | *.wxl text linguist-language=XML 50 | *.wxs text linguist-language=XML 51 | *.yaml text linguist-language=MiniYAML 52 | *.zig text linguist-language=Zig 53 | 54 | # Declare files that will always have CRLF line endings on checkout. 55 | *.bat eol=crlf linguist-detectable=false 56 | *.cmd eol=crlf linguist-detectable=false 57 | *.ps1 eol=crlf linguist-detectable=false 58 | *.sln text eol=crlf linguist-detectable=false 59 | 60 | # https://github.com/github/linguist/blob/master/lib/linguist/languages.yml 61 | Makefile text eol=crlf linguist-detectable=false 62 | Makefile.inc text eol=crlf linguist-detectable=false 63 | 64 | # Declare files that will always have LF line endings on checkout. 65 | *.sh eol=lf linguist-detectable=false 66 | 67 | # Denote all files that are truly binary and should not be modified. 68 | *.bmp binary 69 | *.class binary 70 | *.dat binary 71 | *.dll binary 72 | *.gif binary 73 | *.ico binary 74 | *.jar binary 75 | *.jpg binary 76 | *.m4a binary 77 | *.pdf binary 78 | *.png binary 79 | *.rtf binary 80 | *.zip binary 81 | 82 | # Project specific attributes 83 | # https://aldomann.com/post/override-github-linguist-with-gitattributes-files/ 84 | bin/* linguist-vendored 85 | docs/* linguist-documentation 86 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.aux 3 | *.bak 4 | *.cfg 5 | *.config 6 | *.csv 7 | *.dot 8 | *.exe 9 | *.hprof 10 | *.iml 11 | *.log 12 | *.o 13 | *.obj 14 | *.orig 15 | *.pyc 16 | *.rej 17 | *.swn 18 | *.swo 19 | *.swp 20 | *.zip 21 | .DS_Store 22 | .checkstyle 23 | .classpath 24 | .externalToolBuilders 25 | .factorypath 26 | .idea 27 | .metadata/ 28 | .project 29 | .settings/ 30 | build/ 31 | clibraries/ 32 | llvm-*.src/ 33 | svmbuild/ 34 | test-suite-*.src/ 35 | core.* 36 | env 37 | bench-results.json 38 | hs_err_pid*.log 39 | jmh_result.json 40 | *.src.tar.xz 41 | workingsets.xml 42 | 43 | # llvm-examples project 44 | *_LOCAL/ 45 | .settings/ 46 | -------------------------------------------------------------------------------- /BUILD.md: -------------------------------------------------------------------------------- 1 | # Building LLVM on Windows [↩](README.md#top) 2 | 3 | 4 | 5 | 6 | 8 | 9 |
LLVM projectThis document presents our build from the LLVM source distribution on a Windows machine. 7 |
10 | 11 | ## `build.bat` 12 | 13 | Command [**`build.bat`**](bin/llvm/build.bat) consists of ~350 lines of batch/PowerShell code we wrote to generate additional Windows binaries not available in the LLVM binary distribution. 14 | 15 | > **:mag_right:** For instance, [LLVM tools][llvm_tools] such as [**`llvm-as.exe`**][llvm_as] (assembler), [**`llvm-dis.exe`**][llvm_dis] (disassembler), [**`opt.exe`**][llvm_opt] (optimizer), [**`llc.exe`**][llvm_llc] (static compiler) and [**`lli.exe`**][llvm_lli] (bitcode interpreter) are not part of the [LLVM] binary distribution (e.g. [`LLVM-15.0.7-win64.exe`][llvm_downloads]). 16 | 17 | 18 | ## Usage examples 19 | 20 | Directory **`llvm-15.0.7.src\`** [1](#footnote_01) is setup as follows: 21 |
 22 | > curl -sL -o llvm-15.0.7.src.tar.xz https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7/llvm-15.0.7.src.tar.xz
 23 | > tar xzvf llvm-15.0.7.src.tar.xz
 24 | > cp bin\llvm\build.bat llvm-15.0.7.src
 25 | > cd llvm-15.0.7.src
 26 | 
27 | 28 | > **:mag_right:** In our case we successively worked with versions `8.0.1`, `9.0.1`, `10.0.1`, `11.0.1`, `11.1.0`, `12.0.1`, `13.0.1`, `14.0.6`, `15.0.6` of the [LLVM] source distribution and today we build our binaries from directory `L:\llvm-15.0.7.src\`. 29 | 30 | Command [**`build.bat -verbose compile`**](bin/llvm/build.bat) [2](#footnote_02) generates the additional binaries (both **`.exe`** and **`.lib`** files) into directory **`build\Release\`** (resp. **`build\Debug\`**). Be patient, build time is about 55 minutes on an Intel i7-4th with 16 GB of memory. 31 | 32 |
 33 | > cd
 34 | L:\llvm-15.0.7.src
 35 |  
 36 | > build -verbose compile
 37 | Toolset: MSVC/MSBuild, Project: LLVM
 38 | **********************************************************************
 39 | ** Visual Studio 2019 Developer Command Prompt v16.11.11
 40 | ** Copyright (c) 2019 Microsoft Corporation
 41 | **********************************************************************
 42 | [vcvarsall.bat] Environment initialized for: 'x64'
 43 | INCLUDE="..."
 44 | LIB="..."
 45 | Configuration: Debug, Platform: x64
 46 | [build] Current directory is: L:\llvm-15.0.7.src\build
 47 | [...]
 48 |  
 49 | > dir build\Release\bin\ll?.exe | findstr /b [0-9]
 50 | 07.12.2022  08:07        72 299 520 llc.exe
 51 | 07.12.2022  08:08        23 104 512 lli.exe
 52 | 
53 | 54 | > **:mag_right:** Command [**`build -verbose run`**](bin/llvm/build.bat) also execute **`lli.exe -version`** at the end of the build process : 55 | >
 56 | > [...]
 57 | > Generate LLVM executables (LLVM.sln)
 58 | > Execute build\Release\bin\lli.exe --version
 59 | > LLVM (http://llvm.org/):
 60 | >   LLVM version 15.0.7
 61 | >   Optimized build.
 62 | >   Default target: x86_64-pc-windows-msvc
 63 | >   Host CPU: haswell
 64 | 
65 | 66 | Command [**`build.bat -verbose install`**](bin/llvm/build.bat) copies the generated binaries to the [LLVM] installation directory (in our case **`C:\opt\LLVM-15.0.7\`**). 67 | 68 |
 69 | > build -verbose install
 70 | Do really want to copy files from 'build\' to 'c:\opt\LLVM-15.0.7\' (Y/N)? y
 71 | Copy files from directory build\Release\bin to C:\opt\LLVM-15.0.7\bin\
 72 | Copy files from directory build\Release\lib to C:\opt\LLVM-15.0.7\lib\
 73 | Copy files from directory build\lib\cmake to C:\opt\LLVM-15.0.7\lib\cmake\
 74 | Copy files from directory include to C:\opt\LLVM-15.0.7\include\
 75 | 
76 | 77 | > **:mag_right:** Before installation our [LLVM] installation directory contains 18 `llvm-*.exe` executables: 78 | >
 79 | > > where /r c:\opt\LLVM-15.0.7 llvm*.exe | wc -l
 80 | > 18
 81 | > 
82 | > and after installation it contains 78 `llvm-*.exe` executables: 83 | >
 84 | > > where /r c:\opt\LLVM-15.0.7 llvm*.exe | wc -l
 85 | > 78
 86 | > 
87 | 88 | We list below several executables in the [LLVM] installation directory; e.g. commands like [**`clang.exe`**][llvm_clang], [**`lld.exe`**][llvm_lld] and [**`lldb.exe`**][llvm_lldb] belong to the orginal distribution while commands like [**`llc.exe`**][llvm_llc], [**`lli.exe`**][llvm_lli] and [**`opt.exe`**][llvm_opt] were build/added from the [LLVM] source distribution. 89 | 90 |
 91 | > where /t clang llc lld lldb lli opt
 92 |  111801856   30.11.2022      10:46:14  C:\opt\LLVM-15.0.7\bin\clang.exe
 93 |   72299520   07.12.2022      01:34:48  C:\opt\LLVM-15.0.7\bin\llc.exe
 94 |   82472960   30.11.2022      10:48:04  C:\opt\LLVM-15.0.7\bin\lld.exe
 95 |     215552   30.11.2022      10:50:04  C:\opt\LLVM-15.0.7\bin\lldb.exe
 96 |   23104512   07.12.2022      01:35:01  C:\opt\LLVM-15.0.7\bin\lli.exe
 97 |   77778432   07.12.2022      01:43:52  C:\opt\LLVM-15.0.7\bin\opt.exe
 98 | 
99 | 100 | ## Footnotes [**▴**](#top) 101 | 102 | [1] ***Cmake modules*** [↩](#anchor_01) 103 | 104 |

105 | In order to successfully generate the LLVM distribution from the sources we need to copy some missing CMake files to directory L:\llvm-X.Y.Z.src\cmake\modules\: 106 | 107 | 108 | 109 | 110 |
LLVM versionCMake files
15ExtendPath.cmake
FindPrefixFromConfig.cmake
16CMakePolicy.cmake
ExtendPath.cmake
FindPrefixFromConfig.cmake
GNUInstallPackageDir.cmake
111 |

112 | 113 | [2] ***CmakeLists.txt*** [↩](#anchor_02) 114 | 115 |

116 | We need to comment out the lines marked with #ME# in file CMakeLists.txt in order to build a LLVM distribution in our Windows environment : 117 |

118 | if (LLVM_INCLUDE_BENCHMARKS)
119 |   ...
120 |   # Since LLVM requires C++11 it is safe to assume that std::regex is available.
121 |   set(HAVE_STD_REGEX ON CACHE BOOL "OK" FORCE)
122 |   #ME# add_subdirectory(${LLVM_THIRD_PARTY_DIR}/benchmark 
123 |   #ME#   ${CMAKE_CURRENT_BINARY_DIR}/third-party/benchmark)
124 |   #ME# add_subdirectory(benchmarks)
125 | endif()
126 | 
127 |

128 | 129 | *** 130 | 131 | *[mics](https://lampwww.epfl.ch/~michelou/)/August 2024* [**▲**](#top) 132 |   133 | 134 | 135 | 136 | [batch_file]: https://en.wikibooks.org/wiki/Windows_Batch_Scripting 137 | [llvm]: https://llvm.org/ 138 | [llvm_as]: https://llvm.org/docs/CommandGuide/llvm-as.html 139 | [llvm_clang]: https://releases.llvm.org/14.0.0/tools/clang/docs/ClangCommandLineReference.html 140 | [llvm_dis]: https://llvm.org/docs/CommandGuide/llvm-dis.html 141 | [llvm_downloads]: https://github.com/llvm/llvm-project/releases/tag/llvmorg-15.0.7 142 | [llvm_llc]: https://llvm.org/docs/CommandGuide/llc.html 143 | [llvm_lld]: https://lld.llvm.org/ 144 | [llvm_lldb]: https://lldb.llvm.org/ 145 | [llvm_lli]: https://llvm.org/docs/CommandGuide/lli.html 146 | [llvm_opt]: https://llvm.org/docs/CommandGuide/opt.html 147 | [llvm_tools]: https://llvm.org/docs/CommandGuide/ 148 | [mx_cli]: https://github.com/graalvm/mx 149 | [oracle_graal]: https://github.com/oracle/graal 150 | [travis_yml]: https://github.com/oracle/graal/blob/master/.travis.yml 151 | -------------------------------------------------------------------------------- /RESOURCES.md: -------------------------------------------------------------------------------- 1 | # LLVM Resources [↩](README.md#top) 2 | 3 | 4 | 5 | 6 | 8 | 9 |
LLVM projectThis document gathers LLVM related resources that caught our attention. 7 |
10 | 11 | 12 | ## Articles 13 | 14 | - [What is LLVM? The power behind Swift, Rust, Clang, and more][article_yegulalp] by Serdar Yeulalp, August 2023. 15 | - [Remote LLVM development with Visual Studio Code][article_kleine] by Konrad Kleine, April 2021. 16 | - [A Brief Introduction to Clang-Tidy][article_clang_tidy], by Bartlomeij Filipek, January 2021. 17 | - [MIR: A lightweight JIT compiler project][article_mir], by Vladimir Makarov, January 2020. 18 | - [A look at LLVM Advanced Data Types][article_data_types] by Serge Guelton, April 2019. 19 | - [Compiler Performance and LLVM][article_compiler_perf] by Jonathan Goodwin, March 2019. 20 | - [LLVM IR and Go][article_ir_go] by Robin Eklind, December 2018. 21 | - [How LLVM optimizes a function](https://blog.regehr.org/archives/1603) by John Regehr, September 2018. 22 | - [How LLVM optimizes power sums][article_power_sums] by Krister Walfridsson, April 2018. 23 | - [Adventures in JIT compilation: Part 3 - LLVM](https://eli.thegreenplace.net/2017/adventures-in-jit-compilation-part-3-llvm/) by Eli Bendersky, May 2017. 24 | - [Adventures in JIT compilation: Part 2 - an x64 JIT](https://eli.thegreenplace.net/2017/adventures-in-jit-compilation-part-2-an-x64-jit/) by Eli Bendersky, March 2017. 25 | - [Adventures in JIT compilation: Part 1 - an interpreter](https://eli.thegreenplace.net/2017/adventures-in-jit-compilation-part-1-an-interpreter/) by Eli Bendersky, March 2017. 26 | - [A Tourist’s Guide to the LLVM Source Code](https://blog.regehr.org/archives/1453) by John Regehr, January 2017. 27 | - [LLVM for Grad Students](http://www.cs.cornell.edu/~asampson/blog/llvm.html) by Adrian Sampson, August 2015. 28 | - [A deeper look into the LLVM code generator, Part 1](https://eli.thegreenplace.net/2013/02/25/a-deeper-look-into-the-llvm-code-generator-part-1) by Eli Bendersky, February 2013. 29 | - [Life of an instruction in LLVM](https://eli.thegreenplace.net/2012/11/24/life-of-an-instruction-in-llvm) by Eli Bendersky, November 2012. 30 | - [Create a working compiler with the LLVM framework, Part 2][article_sen_2] by Arpan Sen, June 2012. 31 | - [Create a working compiler with the LLVM framework, Part 1][article_sen_1] by Arpan Sen, June 2012. 32 | - [Writing Your Own Toy Compiler Using Flex, Bison and LLVM][article_toy_compiler], by Loren Segal, September 2009. 33 | 34 | 37 | 38 | ## Blogs 39 | 40 | - [nikic's Blog](https://www.npopov.com/) : 41 | - [How to reduce LLVM crashes](https://www.npopov.com/2023/10/22/How-to-reduce-LLVM-crashes.html), October 2023. 42 | - [LLVM: The middle-end optimization pipeline](https://www.npopov.com/2023/04/07/LLVM-middle-end-pipeline.html), April 2023. 43 | - [This year in LLVM (2022)](https://www.npopov.com/2022/12/20/This-year-in-LLVM-2022.html), December 2022. 44 | - [Design issues in LLVM IR](https://www.npopov.com/2021/06/02/Design-issues-in-LLVM-IR.html), June 2021. 45 | - [Make LLVM fast again](https://www.npopov.com/2020/05/10/Make-LLVM-fast-again.html), May 2020. 46 | - [LLVM Project Blog](https://blog.llvm.org/) : 47 | - [Improving LLVM Infrastructure - Part 1: Mailing lists][blog_llvm2022], January 2022. 48 | - [LLVM’s New Pass Manager][blog_llvm2021], March 2021. 49 | - [LLVM Infrastructure and Rust][blog_modebadze] by Beka Modebadze, December 2021. 50 | - [Compiling With Clang Optimization Flags][blog_exterman] by Dori Exterman, August 2021. 51 | - [Building llvm-project with Ninja on MacOS][blog_guo] by Yilong Guo (Intel), May 2021. 52 | - [Code alignment options in LLVM](https://easyperf.net/blog/2018/01/25/Code_alignment_options_in_llvm) by Denis Bakhvalov, January 2018. 53 | 54 | ## Books [**▴**](#top) 55 | 56 | - [Learn LLVM 17][book_nacke_2nd] (2nd Edition) by Kai Nacke, January 2024.
(Packt, ISBN 978-1-83763-134-6, 416 pages) 57 | - [Advanced Compiler Design with LLVM][book_chisnall] by David Chisnall, March 2022.
(Pearson, ISBN 978-0-1337-9864-7, 360 pages) 58 | - [LLVM Techniques, Tips and Best Practices][book_hsu] by Min-Yih Hsu, April 2021.
(Packt Publishing, ISBN 978-1-8388-2495-2, 370 pages) 59 | - [Tutorial: Creating an LLVM Backend for the Cpu0 Architecture][book_cpu0] by Chen Chung-Shu, February 2020 (*Release 3.9.1*). 60 | - [Mapping High Level Constructs to LVVM IR](https://mapping-high-level-constructs-to-llvm-ir.readthedocs.io/en/latest/) (*ebook*) by Michael Rodle, 2018. 61 | - [LLVM Essentials][book_sarda] by S. Sarda & M. Pandey, December 2015
(Packt Publishing, ISBN 978-1-78528-080-1, 166 pages). 62 | - [LLVM Cookbook][book_pandey], by M. Pandey & S. Sarda, May 2015.
(Packt Publishing, ISBN 978-1-78528-598-1, 296 pages) 63 | - [Getting Started with LLVM Core Libraries][book_lopez] by B. Cardoso Lopez & R. Auler, August 2014.
(Packt Publishing, ISBN 978-1-78216-692-4, 314 pages) 64 | 67 | 68 | ## Courses 69 | 70 | - [Introduction to the Low-Level Virtual Machine (LLVM)](https://www.youtube.com/playlist?list=PLDSTpI7ZVmVnvqtebWnnI8YeB8bJoGOyv), October 2021. 71 | - [CS 6120: Advanced Compilers: The Self-Guided Online Course](https://www.cs.cornell.edu/courses/cs6120/2020fa/self-guided/) by Adrian Sampson, 2020. 72 | - [DCC888: Static Program Analysis](https://homepages.dcc.ufmg.br/~fernando/classes/dcc888/) by Fernando Pereira, January 2020. 73 | - [Compilers](https://anoopsarkar.github.io/compilers-class/index.html): [*Code Generation with LLVM](https://anoopsarkar.github.io/compilers-class/llvm-practice.html) by [Anoop Sarkar](https://www2.cs.sfu.ca/~anoop/) (instructor), Summer 2019. 74 | - [EEECS 582: Advanced Compilers](http://web.eecs.umich.edu/~mahlke/courses/583f18/), Fall 2018. 75 | - [Advanced compilers][course_hirvisalo] by Vesa Hirvisalo (instructor), 2015. 76 | 77 | ## News [**▴**](#top) 78 | 79 | - [*LLVM Weekly*][news_llvmweekly] - A weekly newsletter covering developments in LLVM, Clang, and related projects. 80 | - [*Planet Clang*][news_planet_clang] - Planet Clang is a window into the world, work and lives of Clang developers, contributors and the standards they implement. 81 | 82 | 85 | 86 | ## Papers 87 | 88 | - [Alive2: Bounded Translation Validation for LLVM](https://www.cs.utah.edu/~regehr/#pubs) by Nuno P. Lopes, PLDI 2021, Jun 2021. 89 | 90 | > **Note:** See page "LLVM Related Publications" on the official LLVM website. 91 | > 92 | > We mention here only publications from Chris Lattner's and Vikram Adve: 93 | > 94 | > - Design decisions that shapped LLVM by Chris Lattner (March 2012). 95 | > - The LLVM Instruction Set and Compilation Strategy by Chris Lattner and Vikram Adve (August 2002). 96 | > - LLVM: An infrastructure for Multi-Stage Optimization by Chris Lattner (Master Thesis, December 2002). 97 | 98 | ## Tools 99 | 100 | 103 | - [Compiler Explorer][tools_godbolt] (type your C/C++ code in the left pane, then select "*x86-64 clang 13.0.1*" and add a new pane "*IR output*"). 104 | - [Polly](https://polly.llvm.org/) – a high-level loop and data-locality optimizer and optimization infrastructure for LLVM. 105 | - [Utilizing TableGen for Non-Compiling Processes](https://www.embecosm.com/2015/04/14/utilizing-tablegen-for-non-compiling-processes/) by Simon Cook, April 2015. 106 | - [LLVM TableGen](https://wiki.aalto.fi/display/t1065450/LLVM+TableGen) by Sami Teräväinen, February 2015. 107 | 108 | 116 | 117 | *** 118 | 119 | *[mics](https://lampwww.epfl.ch/~michelou/)/August 2024* [**▲**](#top) 120 |   121 | 122 | 123 | 124 | [article_clang_tidy]: https://blog.wholetomato.com/2021/01/08/a-brief-introduction-to-clang-tidy-and-its-role-in-visual-assist/ 125 | [article_compiler_perf]: http://pling.jondgoodwin.com/post/compiler-performance/ 126 | [article_data_types]: https://developers.redhat.com/blog/2019/04/01/a-look-at-llvm-advanced-data-types-and-trivially-copyable-types/ 127 | [article_ir_go]: https://blog.gopheracademy.com/advent-2018/llvm-ir-and-go/ 128 | [article_kleine]: https://developers.redhat.com/blog/2021/04/22/remote-llvm-development-with-visual-studio-code# 129 | [article_mir]: https://developers.redhat.com/blog/2020/01/20/mir-a-lightweight-jit-compiler-project/ 130 | [article_power_sums]: https://kristerw.blogspot.com/2019/04/how-llvm-optimizes-geometric-sums.html 131 | [article_sen_1]: https://www.ibm.com/developerworks/library/os-createcompilerllvm1/index.html 132 | [article_sen_2]: https://www.ibm.com/developerworks/library/os-createcompilerllvm2/index.html 133 | [article_toy_compiler]: https://gnuu.org/2009/09/18/writing-your-own-toy-compiler/ 134 | [article_yegulalp]: https://www.infoworld.com/article/3247799/what-is-llvm-the-power-behind-swift-rust-clang-and-more.html 135 | [blog_exterman]: https://www.incredibuild.com/blog/compiling-with-clang-optimization-flags 136 | [blog_guo]: https://blog.nuullll.com/2021/05/15/building-llvm-project-with-ninja-on-macos.html 137 | [blog_llvm2021]: https://blog.llvm.org/posts/2021-03-26-the-new-pass-manager/ 138 | [blog_llvm2022]: https://blog.llvm.org/posts/2022-01-07-moving-to-discourse/ 139 | [blog_modebadze]: https://www.bexxmodd.com/log/llvm-infrastrucutre-and-rust/7 140 | [book_chisnall]: https://www.amazon.com/Advanced-Compiler-Pearson-Software-Development/dp/013379864X 141 | [book_cpu0]: https://jonathan2251.github.io/lbd/llvmstructure.html 142 | [book_hsu]: https://www.packtpub.com/product/llvm-techniques-tips-and-best-practices-clang-and-middle-end-libraries/9781838824952 143 | [book_lopez]: https://www.packtpub.com/application-development/getting-started-llvm-core-libraries 144 | [book_nacke]: https://www.packtpub.com/product/learn-llvm-12/978183921350 145 | [book_nacke_2nd]: https://www.packtpub.com/product/learn-llvm-17-second-edition/9781837631346 146 | [book_pandey]: https://www.packtpub.com/application-development/llvm-cookbook 147 | [book_sarda]: https://www.packtpub.com/application-development/llvm-essentials 148 | [course_hirvisalo]: https://wiki.aalto.fi/display/t1065450/Advanced+compilers+2015 149 | [news_llvmweekly]: http://llvmweekly.org/ "LLVM Weekly" 150 | [news_planet_clang]: http://planet.clang.org/ "Planet Clang" 151 | [tools_godbolt]: https://www.godbolt.org/ 152 | -------------------------------------------------------------------------------- /bin/llvm/build.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | @rem only for interactive debugging ! 5 | set _DEBUG=0 6 | 7 | @rem ######################################################################### 8 | @rem ## Environment setup 9 | 10 | set _EXITCODE=0 11 | 12 | call :env 13 | if not %_EXITCODE%==0 goto end 14 | 15 | call :args %* 16 | if not %_EXITCODE%==0 goto end 17 | 18 | @rem ######################################################################### 19 | @rem ## Main 20 | 21 | if %_HELP%==1 ( 22 | call :help 23 | exit /b !_EXITCODE! 24 | ) 25 | if %_CLEAN%==1 ( 26 | call :clean 27 | if not !_EXITCODE!==0 goto end 28 | ) 29 | if %_COMPILE%==1 ( 30 | call :compile 31 | if not !_EXITCODE!==0 goto end 32 | ) 33 | if %_RUN%==1 ( 34 | call :run 35 | if not !_EXITCODE!==0 goto end 36 | ) 37 | if %_INSTALL%==1 ( 38 | call :install 39 | if not !_EXITCODE!==0 goto end 40 | ) 41 | goto end 42 | 43 | @rem ######################################################################### 44 | @rem ## Subroutines 45 | 46 | @rem output parameters: _PROJ_NAME, _PROJ_CONFIG, _TARGET_DIR, _TARGET_OUTPUT_DIR 47 | @rem _MSBUILD_CMD, _MSBUILD_OPTS, _DEBUG_LABEL, _ERROR_LABEL 48 | :env 49 | set _BASENAME=%~n0 50 | set "_ROOT_DIR=%~dp0" 51 | 52 | call :env_colors 53 | set _DEBUG_LABEL=%_NORMAL_BG_CYAN%[%_BASENAME%]%_RESET% 54 | set _ERROR_LABEL=%_STRONG_FG_RED%Error%_RESET%: 55 | set _WARNING_LABEL=%_STRONG_FG_YELLOW%Warning%_RESET%: 56 | 57 | for /f "delims=" %%f in ('where /r "%MSVS_HOME%" vcvarsall.bat') do set "_VCVARSALL_FILE=%%f" 58 | if not exist "%_VCVARSALL_FILE%" ( 59 | echo %_ERROR_LABEL% Internal error ^(vcvarsall.bat not found^) 1>&2 60 | set _EXITCODE=1 61 | goto :eof 62 | ) 63 | set "__CMAKE_LIST_FILE=%_ROOT_DIR%CMakeLists.txt" 64 | if not exist "%__CMAKE_LIST_FILE%" ( 65 | echo %_ERROR_LABEL% File CMakeLists.txt not found 1>&2 66 | set _EXITCODE=1 67 | goto end 68 | ) 69 | set _PROJ_NAME=LLVM 70 | for /f "tokens=1,2,* delims=( " %%f in ('findstr /b project "%__CMAKE_LIST_FILE%" 2^>NUL') do set "_PROJ_NAME=%%g" 71 | @rem set _PROJ_CONFIG=Debug 72 | set _PROJ_CONFIG=Release 73 | set _PROJ_PLATFORM=x64 74 | 75 | set "_TARGET_DIR=%_ROOT_DIR%build" 76 | set "_TARGET_OUTPUT_DIR=%_TARGET_DIR%\%_PROJ_CONFIG%" 77 | 78 | set _MSBUILD_CMD=msbuild.exe 79 | set _MSBUILD_OPTS=/nologo /p:Configuration=%_PROJ_CONFIG% /p:Platform="%_PROJ_PLATFORM%" 80 | 81 | @rem use newer PowerShell version if available 82 | where /q pwsh.exe 83 | if %ERRORLEVEL%==0 ( set _PWSH_CMD=pwsh.exe 84 | ) else ( set _PWSH_CMD=powershell.exe 85 | ) 86 | goto :eof 87 | 88 | :env_colors 89 | @rem ANSI colors in standard Windows 10 shell 90 | @rem see https://gist.github.com/mlocati/#file-win10colors-cmd 91 | 92 | @rem normal foreground colors 93 | set _NORMAL_FG_BLACK= 94 | set _NORMAL_FG_RED= 95 | set _NORMAL_FG_GREEN= 96 | set _NORMAL_FG_YELLOW= 97 | set _NORMAL_FG_BLUE= 98 | set _NORMAL_FG_MAGENTA= 99 | set _NORMAL_FG_CYAN= 100 | set _NORMAL_FG_WHITE= 101 | 102 | @rem normal background colors 103 | set _NORMAL_BG_BLACK= 104 | set _NORMAL_BG_RED= 105 | set _NORMAL_BG_GREEN= 106 | set _NORMAL_BG_YELLOW= 107 | set _NORMAL_BG_BLUE= 108 | set _NORMAL_BG_MAGENTA= 109 | set _NORMAL_BG_CYAN= 110 | set _NORMAL_BG_WHITE= 111 | 112 | @rem strong foreground colors 113 | set _STRONG_FG_BLACK= 114 | set _STRONG_FG_RED= 115 | set _STRONG_FG_GREEN= 116 | set _STRONG_FG_YELLOW= 117 | set _STRONG_FG_BLUE= 118 | set _STRONG_FG_MAGENTA= 119 | set _STRONG_FG_CYAN= 120 | set _STRONG_FG_WHITE= 121 | 122 | @rem strong background colors 123 | set _STRONG_BG_BLACK= 124 | set _STRONG_BG_RED= 125 | set _STRONG_BG_GREEN= 126 | set _STRONG_BG_YELLOW= 127 | set _STRONG_BG_BLUE= 128 | 129 | @rem we define _RESET in last position to avoid crazy console output with type command 130 | set _BOLD= 131 | set _UNDERSCORE= 132 | set _INVERSE= 133 | set _RESET= 134 | goto :eof 135 | 136 | @rem input parameter: %* 137 | @rem output parameters: _CLEAN, _COMPILE, _RUN, _DEBUG, _VERBOSE 138 | :args 139 | set _CLEAN=0 140 | set _COMPILE=0 141 | set _INSTALL=0 142 | set _RUN=0 143 | set _DEBUG=0 144 | set _HELP=0 145 | set _TIMER=0 146 | set _TOOLSET=msvc 147 | set _VERBOSE=0 148 | set __N=0 149 | :args_loop 150 | set "__ARG=%~1" 151 | if not defined __ARG ( 152 | if !__N!==0 set _HELP=1 153 | goto args_done 154 | ) 155 | if "%__ARG:~0,1%"=="-" ( 156 | @rem option 157 | if "%__ARG%"=="-debug" ( set _DEBUG=1 158 | ) else if "%__ARG%"=="-help" ( set _HELP=1 159 | ) else if "%__ARG%"=="-timer" ( set _TIMER=1 160 | ) else if "%__ARG%"=="-verbose" ( set _VERBOSE=1 161 | ) else ( 162 | echo %_ERROR_LABEL% Unknown option "%__ARG%" 1>&2 163 | set _EXITCODE=1 164 | goto args_done 165 | ) 166 | ) else ( 167 | @rem subcommand 168 | if "%__ARG%"=="clean" ( set _CLEAN=1 169 | ) else if "%__ARG%"=="compile" ( set _COMPILE=1 170 | ) else if "%__ARG%"=="help" ( set _HELP=1 171 | ) else if "%__ARG%"=="run" ( set _COMPILE=1 & set _RUN=1 172 | ) else if "%__ARG%"=="install" ( set _INSTALL=1 173 | ) else ( 174 | echo %_ERROR_LABEL% Unknown subcommand "%__ARG%" 1>&2 175 | set _EXITCODE=1 176 | goto args_done 177 | ) 178 | set /a __N+=1 179 | ) 180 | shift 181 | goto args_loop 182 | :args_done 183 | set _STDOUT_REDIRECT=1^>NUL 184 | if %_DEBUG%==1 set _STDOUT_REDIRECT=1^>CON 185 | 186 | if %_DEBUG%==1 ( 187 | echo %_DEBUG_LABEL% Options : _TIMER=%_TIMER% _TOOLSET=%_TOOLSET% _VERBOSE=%_VERBOSE% 1>&2 188 | echo %_DEBUG_LABEL% Subcommands: _CLEAN=%_CLEAN% _COMPILE=%_COMPILE% _RUN=%_RUN% _INSTALL=%_INSTALL% 1>&2 189 | echo %_DEBUG_LABEL% Variables : "LLVM_HOME=%LLVM_HOME%" 1>&2 190 | echo %_DEBUG_LABEL% Variables : "MSVS_HOME=%MSVS_HOME%" 1>&2 191 | echo %_DEBUG_LABEL% Variables : "MSYS_HOME=%MSYS_HOME%" 1>&2 192 | ) 193 | if %_TIMER%==1 for /f "delims=" %%i in ('call "%_PWSH_CMD%" -c "(Get-Date)"') do set _TIMER_START=%%i 194 | goto :eof 195 | 196 | :help 197 | if %_VERBOSE%==1 ( 198 | set __BEG_P=%_STRONG_FG_CYAN% 199 | set __BEG_O=%_STRONG_FG_GREEN% 200 | set __BEG_N=%_NORMAL_FG_YELLOW% 201 | set __END=%_RESET% 202 | ) else ( 203 | set __BEG_P= 204 | set __BEG_O= 205 | set __BEG_N= 206 | set __END= 207 | ) 208 | echo Usage: %__BEG_O%%_BASENAME% { ^ ^| ^ }%__END% 209 | echo. 210 | echo %__BEG_P%Options:%__END% 211 | echo %__BEG_O%-debug%__END% print commands executed by this script 212 | echo %__BEG_O%-timer%__END% print total execution time 213 | echo %__BEG_O%-verbose%__END% print progress messages 214 | echo. 215 | echo %__BEG_P%Subcommands:%__END% 216 | echo %__BEG_O%clean%__END% delete generated files 217 | echo %__BEG_O%compile%__END% generate executable 218 | echo %__BEG_O%help%__END% print this help message 219 | echo %__BEG_O%install%__END% install files generated in directory "%__BEG_O%!_TARGET_DIR:%_ROOT_DIR%=!%__END%" 220 | echo %__BEG_O%run%__END% run the generated executable 221 | goto :eof 222 | 223 | :clean 224 | call :rmdir "%_TARGET_DIR%" 225 | goto :eof 226 | 227 | @rem input parameter: %1=directory path 228 | :rmdir 229 | set "__DIR=%~1" 230 | if not exist "!__DIR!\" goto :eof 231 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% rmdir /s /q "%__DIR%" 1>&2 232 | ) else if %_VERBOSE%==1 ( echo Delete directory "!__DIR:%_ROOT_DIR%=!" 1>&2 233 | ) 234 | rmdir /s /q "%__DIR%" 235 | if not %ERRORLEVEL%==0 ( 236 | echo %_ERROR_LABEL% Failed to delete directory "!__DIR:%_ROOT_DIR%=!" 1>&2 237 | set _EXITCODE=1 238 | goto :eof 239 | ) 240 | goto :eof 241 | 242 | :compile 243 | setlocal 244 | if not exist "%_TARGET_DIR%" mkdir "%_TARGET_DIR%" 245 | 246 | if %_TOOLSET%==clang ( set _TOOLSET_NAME=Clang/GNU Make 247 | ) else if %_TOOLSET%==gcc ( set _TOOLSET_NAME=GCC/GNU Make 248 | ) else ( set _TOOLSET_NAME=MSVC/MSBuild 249 | ) 250 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% Toolset: %_TOOLSET_NAME%, Project: %_PROJ_NAME% 1>&2 251 | ) else if %_VERBOSE%==1 ( echo Toolset: %_TOOLSET_NAME%, Project: %_PROJ_NAME% 1>&2 252 | ) 253 | call :compile_msvc 254 | 255 | endlocal 256 | goto :eof 257 | 258 | :init_msvc 259 | call "%_VCVARSALL_FILE%" amd64 260 | if not %ERRORLEVEL%==0 ( 261 | set _EXITCODE=1 262 | goto :eof 263 | ) 264 | set /a __SHOW_ALL=_DEBUG+_VERBOSE 265 | if not %__SHOW_ALL%==0 ( 266 | echo INCLUDE="%INCLUDE%" 1>&2 267 | echo LIB="%LIB%" 1>&2 268 | ) 269 | goto :eof 270 | 271 | :compile_msvc 272 | call :init_msvc 273 | if not %_EXITCODE%==0 goto :eof 274 | 275 | set "__PYTHON_CMD=%PYTHON_HOME%\python.exe" 276 | set "__CMAKE_CMD=%CMAKE_HOME%\bin\cmake.exe" 277 | set __CMAKE_OPTS=-Thost=%_PROJ_PLATFORM% -A %_PROJ_PLATFORM% -Wdeprecated -DPYTHON_EXECUTABLE=%__PYTHON_CMD% 278 | @rem see http://lists.llvm.org/pipermail/llvm-dev/2017-February/110590.html 279 | set __CMAKE_OPTS=%__CMAKE_OPTS% -G "Visual Studio 16 2019" 280 | 281 | if %_VERBOSE%==1 echo Configuration: %_PROJ_CONFIG%, Platform: %_PROJ_PLATFORM% 1>&2 282 | 283 | pushd "%_TARGET_DIR%" 284 | if %_DEBUG%==1 echo %_DEBUG_LABEL% Current directory is: %CD% 285 | 286 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%__CMAKE_CMD%" %__CMAKE_OPTS% .. 1>&2 287 | ) else if %_VERBOSE%==1 ( echo Generate configuration files into directory "!_TARGET_DIR:%_ROOT_DIR%=!" 1>&2 288 | ) 289 | call "%__CMAKE_CMD%" %__CMAKE_OPTS% .. %_STDOUT_REDIRECT% 290 | if not %ERRORLEVEL%==0 ( 291 | popd 292 | echo %_ERROR_LABEL% Generation of build configuration failed 1>&2 293 | set _EXITCODE=1 294 | goto :eof 295 | ) 296 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_MSBUILD_CMD%" %_MSBUILD_OPTS% "%_PROJ_NAME%.sln" 1>&2 297 | ) else if %_VERBOSE%==1 ( echo Generate LLVM executables ^(%_PROJ_NAME%.sln^) 1>&2 298 | ) 299 | call "%_MSBUILD_CMD%" %_MSBUILD_OPTS% "%_PROJ_NAME%.sln" %_STDOUT_REDIRECT% 300 | if not %ERRORLEVEL%==0 ( 301 | popd 302 | echo %_ERROR_LABEL% Generation of LLVM executables failed 1>&2 303 | set _EXITCODE=1 304 | goto :eof 305 | ) 306 | popd 307 | goto :eof 308 | 309 | :run 310 | set "__EXE_FILE=%_TARGET_OUTPUT_DIR%\bin\lli.exe" 311 | set __EXE_ARGS=--version 312 | if not exist "%__EXE_FILE%" ( 313 | echo %_ERROR_LABEL% Executable not found ^(!__EXE_FILE:%_ROOT_DIR%=!^) 1>&2 314 | set _EXITCODE=1 315 | goto :eof 316 | ) 317 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%__EXE_FILE%" %__EXE_ARGS% 1>&2 318 | ) else if %_VERBOSE%==1 ( echo Execute !__EXE_FILE:%_ROOT_DIR%=! %__EXE_ARGS% 1>&2 319 | ) 320 | call "%__EXE_FILE%" %__EXE_ARGS% 321 | if not %ERRORLEVEL%==0 ( 322 | echo %_ERROR_LABEL% Execution status is %ERRORLEVEL% 1>&2 323 | set _EXITCODE= 324 | goto :eof 325 | ) 326 | goto :eof 327 | 328 | @rem input parameter(s): %1=source directory, %2=target directory, %3=exclude file, %4=recursive 329 | :xcopy 330 | set __SOURCE_DIR=%~1 331 | set __TARGET_DIR=%~2 332 | set __EXCLUDE_FILE=%~3 333 | set __RECURSIVE=%~4 334 | 335 | @rem see https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/xcopy 336 | @rem option '/e' copies all subdirectories, even if they are empty. 337 | @rem option '/d' allows you to update files that have changed 338 | if defined __RECURSIVE ( set __XCOPY_OPTS=/d /e /y 339 | ) else ( set __XCOPY_OPTS=/d /y 340 | ) 341 | if exist "%__EXCLUDE_FILE%" set __XCOPY_OPTS=%__XCOPY_OPTS% /exclude:%__EXCLUDE_FILE% 342 | 343 | if not exist "%__SOURCE_DIR%" ( 344 | echo %_ERROR_LABEL% Directory !__SOURCE_DIR:%_ROOT_DIR%=! not found 1>&2 345 | set _EXITCODE=1 346 | goto :eof 347 | ) 348 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% xcopy %__XCOPY_OPTS% "%__SOURCE_DIR%" "%__TARGET_DIR%\" 1>&2 349 | ) else if %_VERBOSE%==1 ( echo Copy files from directory "!__SOURCE_DIR:%_ROOT_DIR%=!" to "%__TARGET_DIR%\" 1>&2 350 | ) 351 | xcopy %__XCOPY_OPTS% "%__SOURCE_DIR%" "%__TARGET_DIR%\" %_STDOUT_REDIRECT% 352 | if not %ERRORLEVEL%==0 ( 353 | set _EXITCODE=1 354 | goto :eof 355 | ) 356 | goto :eof 357 | 358 | :install 359 | if not exist "%LLVM_HOME%" ( 360 | echo %_ERROR_LABEL% LLVM installation directory not found 1>&2 361 | set _EXITCODE=1 362 | goto :eof 363 | ) 364 | set /p __INSTALL_ANSWER="Do really want to copy files from '%_ROOT_DIR%' to '%LLVM_HOME%\' (Y/N)? " 365 | if not "%__INSTALL_ANSWER%"=="y" ( 366 | echo Copy operation aborted 367 | goto :eof 368 | ) 369 | @rem .ilk files ==> https://docs.microsoft.com/en-us/cpp/build/reference/dot-ilk-files-as-linker-input?view=vs-2019 370 | set "__EXCLUDE_BIN=%_TARGET_DIR%\exclude_bin.txt" 371 | ( 372 | echo BrainF 373 | echo BuildingAJIT-Ch 374 | echo Fibonacci 375 | echo Kaleidoscope-Ch 376 | echo .ilk\ 377 | ) > "%__EXCLUDE_BIN%" 378 | set "__EXCLUDE_NONE=%_TARGET_DIR%\exclude_none.txt" 379 | 380 | call :xcopy "%_TARGET_OUTPUT_DIR%\bin" "%LLVM_HOME%\bin" "%__EXCLUDE_BIN%" 381 | if not %_EXITCODE%==0 goto :eof 382 | 383 | call :xcopy "%_TARGET_OUTPUT_DIR%\lib" "%LLVM_HOME%\lib" "%__EXCLUDE_NONE%" 384 | if not %_EXITCODE%==0 goto :eof 385 | 386 | call :xcopy "%_TARGET_DIR%\lib\cmake" "%LLVM_HOME%\lib\cmake" "%__EXCLUDE_NONE%" recursive 387 | if not %_EXITCODE%==0 goto :eof 388 | 389 | call :xcopy "%_ROOT_DIR%include" "%LLVM_HOME%\include" "%__EXCLUDE_NONE%" recursive 390 | if not %_EXITCODE%==0 goto :eof 391 | 392 | goto :eof 393 | 394 | @rem input parameter(s): %1=start time, %2=end time 395 | @rem output parameter: _DURATION 396 | :duration 397 | set __START=%~1 398 | set __END=%~2 399 | 400 | for /f "delims=" %%i in ('call "%_PWSH_CMD%" -c "$interval = New-TimeSpan -Start '%__START%' -End '%__END%'; Write-Host $interval"') do set _DURATION=%%i 401 | goto :eof 402 | 403 | @rem ######################################################################### 404 | @rem ## Cleanups 405 | 406 | :end 407 | if %_TIMER%==1 ( 408 | for /f "delims=" %%i in ('call "%_PWSH_CMD%" -c "(Get-Date)"') do set __TIMER_END=%%i 409 | call :duration "%_TIMER_START%" "!__TIMER_END!" 410 | echo Total execution time: !_DURATION! 1>&2 411 | ) 412 | if %_DEBUG%==1 echo %_DEBUG_LABEL% _EXITCODE=%_EXITCODE% 1>&2 413 | exit /b %_EXITCODE% 414 | endlocal 415 | -------------------------------------------------------------------------------- /bin/pelook.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/bin/pelook.exe -------------------------------------------------------------------------------- /bin/updatemds.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal enabledelayedexpansion 3 | 4 | @rem only for interactive debugging ! 5 | set _DEBUG=0 6 | 7 | @rem ######################################################################### 8 | @rem ## Environment setup 9 | 10 | set _EXITCODE=0 11 | 12 | @rem files README.md, RESOURCES.md, etc. 13 | set _LAST_MODIFIED_OLD=michelou/)/July 2024 14 | set _LAST_MODIFIED_NEW=michelou/)/August 2024 15 | 16 | set _LAST_DOWNLOAD_OLD=(\*July 2024\*) 17 | set _LAST_DOWNLOAD_NEW=(*August 2024*) 18 | 19 | @rem to be transformed into -not -path ".//*" 20 | set _EXCLUDE_TOPDIRS=bin docs llvm-15.0.6.src llvm-15.0.7.src llvm-16.0.6.src 21 | set _EXCLUDE_SUBDIRS=_LOCAL 22 | 23 | call :env 24 | if not %_EXITCODE%==0 goto end 25 | 26 | call :args %* 27 | if not %_EXITCODE%==0 goto end 28 | 29 | @rem ######################################################################### 30 | @rem ## Main 31 | 32 | if %_HELP%==1 ( 33 | call :help 34 | exit /b !_EXITCODE! 35 | ) 36 | if %_RUN%==1 ( 37 | call :run 38 | if not !_EXITCODE!==0 goto end 39 | ) 40 | goto end 41 | 42 | @rem ######################################################################### 43 | @rem ## Subroutines 44 | 45 | @rem output parameters: _DEBUG_LABEL, _ERROR_LABEL, _WARNING_LABEL 46 | :env 47 | set _BASENAME=%~n0 48 | for /f "delims=" %%f in ("%~dp0\.") do set "_ROOT_DIR=%%~dpf" 49 | @rem remove trailing backslash for virtual drives 50 | if "%_ROOT_DIR:~-2%"==":\" set "_ROOT_DIR=%_ROOT_DIR:~0,-1%" 51 | 52 | call :env_colors 53 | set _DEBUG_LABEL=%_NORMAL_BG_CYAN%[%_BASENAME%]%_RESET% 54 | set _ERROR_LABEL=%_STRONG_FG_RED%Error%_RESET%: 55 | set _WARNING_LABEL=%_STRONG_FG_YELLOW%Warning%_RESET%: 56 | 57 | if not exist "%GIT_HOME%\usr\bin\grep.exe" ( 58 | echo %_ERROR_LABEL% Grep command not found 1>&2 59 | set _EXITCODE=1 60 | goto :eof 61 | ) 62 | set "_CYGPATH_CMD=%GIT_HOME%\usr\bin\cygpath.exe" 63 | set "_FIND_CMD=%GIT_HOME%\usr\bin\find.exe" 64 | set "_GREP_CMD=%GIT_HOME%\usr\bin\grep.exe" 65 | set "_SED_CMD=%GIT_HOME%\usr\bin\sed.exe" 66 | set "_UNIX2DOS_CMD=%GIT_HOME%\usr\bin\unix2dos.exe" 67 | goto :eof 68 | 69 | :env_colors 70 | @rem ANSI colors in standard Windows 10 shell 71 | @rem see https://gist.github.com/mlocati/#file-win10colors-cmd 72 | 73 | @rem normal foreground colors 74 | set _NORMAL_FG_BLACK= 75 | set _NORMAL_FG_RED= 76 | set _NORMAL_FG_GREEN= 77 | set _NORMAL_FG_YELLOW= 78 | set _NORMAL_FG_BLUE= 79 | set _NORMAL_FG_MAGENTA= 80 | set _NORMAL_FG_CYAN= 81 | set _NORMAL_FG_WHITE= 82 | 83 | @rem normal background colors 84 | set _NORMAL_BG_BLACK= 85 | set _NORMAL_BG_RED= 86 | set _NORMAL_BG_GREEN= 87 | set _NORMAL_BG_YELLOW= 88 | set _NORMAL_BG_BLUE= 89 | set _NORMAL_BG_MAGENTA= 90 | set _NORMAL_BG_CYAN= 91 | set _NORMAL_BG_WHITE= 92 | 93 | @rem strong foreground colors 94 | set _STRONG_FG_BLACK= 95 | set _STRONG_FG_RED= 96 | set _STRONG_FG_GREEN= 97 | set _STRONG_FG_YELLOW= 98 | set _STRONG_FG_BLUE= 99 | set _STRONG_FG_MAGENTA= 100 | set _STRONG_FG_CYAN= 101 | set _STRONG_FG_WHITE= 102 | 103 | @rem strong background colors 104 | set _STRONG_BG_BLACK= 105 | set _STRONG_BG_RED= 106 | set _STRONG_BG_GREEN= 107 | set _STRONG_BG_YELLOW= 108 | set _STRONG_BG_BLUE= 109 | 110 | @rem we define _RESET in last position to avoid crazy console output with type command 111 | set _BOLD= 112 | set _UNDERSCORE= 113 | set _INVERSE= 114 | set _RESET= 115 | goto :eof 116 | 117 | @rem input parameter: %* 118 | :args 119 | set _HELP=0 120 | set _RUN=1 121 | set _VERBOSE=0 122 | set __N=0 123 | :args_loop 124 | set "__ARG=%~1" 125 | if not defined __ARG goto args_done 126 | 127 | if "%__ARG:~0,1%"=="-" ( 128 | @rem option 129 | if "%__ARG%"=="-debug" ( set _DEBUG=1 130 | ) else if "%__ARG%"=="-help" ( set _HELP=1 131 | ) else if "%__ARG%"=="-verbose" ( set _VERBOSE=1 132 | ) else ( 133 | echo %_ERROR_LABEL% Unknown option "%__ARG%" 1>&2 134 | set _EXITCODE=1 135 | goto args_done 136 | ) 137 | ) else ( 138 | @rem subcommand 139 | if "%__ARG%"=="help" ( set _HELP=1 140 | ) else if "%__ARG%"=="run" ( set _RUN=1 141 | ) else ( 142 | echo %_ERROR_LABEL% Unknown subcommand "%__ARG%" 1>&2 143 | set _EXITCODE=1 144 | goto args_done 145 | ) 146 | set /a __N+=1 147 | ) 148 | shift 149 | goto args_loop 150 | :args_done 151 | if %_DEBUG%==1 ( 152 | echo %_DEBUG_LABEL% Options : _VERBOSE=%_VERBOSE% 1>&2 153 | echo %_DEBUG_LABEL% Subcommands: _HELP=%_HELP% _RUN=%_RUN% 1>&2 154 | ) 155 | goto :eof 156 | 157 | :help 158 | if %_VERBOSE%==1 ( 159 | set __BEG_P=%_STRONG_FG_CYAN% 160 | set __BEG_O=%_STRONG_FG_GREEN% 161 | set __BEG_N=%_NORMAL_FG_YELLOW% 162 | set __END=%_RESET% 163 | ) else ( 164 | set __BEG_P= 165 | set __BEG_O= 166 | set __BEG_N= 167 | set __END= 168 | ) 169 | echo Usage: %__BEG_O%%_BASENAME% { ^ ^| ^ }%__END% 170 | echo. 171 | echo %__BEG_P%Options:%__END% 172 | echo %__BEG_O%-debug%__END% print commands executed by this script 173 | echo %__BEG_O%-verbose%__END% print progress messages 174 | echo. 175 | echo %__BEG_P%Subcommands:%__END% 176 | echo %__BEG_O%help%__END% print this help message 177 | echo %__BEG_O%run%__END% replace old patterns with new ones 178 | goto :eof 179 | 180 | :run 181 | for /f "delims=" %%f in ('"%_CYGPATH_CMD%" %_ROOT_DIR%\') do set "__ROOT_DIR=%%~f" 182 | 183 | set __FIND_EXCLUDES= 184 | for %%i in (%_EXCLUDE_TOPDIRS%) do ( 185 | set __FIND_EXCLUDES=!__FIND_EXCLUDES! -not -path "%__ROOT_DIR%%%i/*" 186 | ) 187 | for %%i in (%_EXCLUDE_SUBDIRS%) do ( 188 | set __FIND_EXCLUDES=!__FIND_EXCLUDES! -not -path "*/*%%i*/*" 189 | ) 190 | set __N_MD=0 191 | if %_DEBUG%==1 echo %_DEBUG_LABEL% "%_FIND_CMD%" "%__ROOT_DIR%" -type f -name "*.md" %__FIND_EXCLUDES% 1>&2 192 | for /f "delims=" %%f in ('%_FIND_CMD% "%__ROOT_DIR%" -type f -name "*.md" %__FIND_EXCLUDES%') do ( 193 | set "__INPUT_FILE=%%f" 194 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_GREP_CMD%" -q "%_LAST_MODIFIED_OLD%" "!__INPUT_FILE!" 1>&2 195 | ) else if %_VERBOSE%==1 ( echo Check file "!__INPUT_FILE!" 1>&2 196 | ) 197 | call "%_GREP_CMD%" -q "%_LAST_MODIFIED_OLD%" "!__INPUT_FILE!" 198 | if !ERRORLEVEL!==0 ( 199 | if %_DEBUG%==1 ( echo %_DEBUG_LABEL% "%_SED_CMD%" -i "s@%_LAST_MODIFIED_OLD%@%_LAST_MODIFIED_NEW%@g" "!__INPUT_FILE!" 1>&2 200 | ) else if %_VERBOSE%==1 ( echo Replace pattern "%_LAST_MODIFIED_OLD%" by "%_LAST_MODIFIED_NEW%" 1>&2 201 | ) 202 | call "%_SED_CMD%" -i "s@%_LAST_MODIFIED_OLD%@%_LAST_MODIFIED_NEW%@g" "!__INPUT_FILE!" 203 | call "%_UNIX2DOS_CMD%" -q "!__INPUT_FILE!" 204 | set /a __N_MD+=1 205 | ) 206 | if %_DEBUG%==1 echo %_DEBUG_LABEL% "%_GREP_CMD%" -q "%_LAST_DOWNLOAD_OLD%" "!__INPUT_FILE!" 1>&2 207 | call "%_GREP_CMD%" -q "%_LAST_DOWNLOAD_OLD%" "!__INPUT_FILE!" 208 | if !ERRORLEVEL!==0 ( 209 | if %_DEBUG%==1 echo %_DEBUG_LABEL% "%_SED_CMD%" -i "s@%_LAST_DOWNLOAD_OLD%@%_LAST_DOWNLOAD_NEW%@g" "!__INPUT_FILE!" 1>&2 210 | call "%_SED_CMD%" -i "s@%_LAST_DOWNLOAD_OLD%@%_LAST_DOWNLOAD_NEW%@g" "!__INPUT_FILE!" 211 | call "%_UNIX2DOS_CMD%" -q "!__INPUT_FILE!" 212 | if !__N_MD!==0 set /a __N_MD+=1 213 | ) 214 | ) 215 | call :message %__N_MD% "Markdown" 216 | goto :eof 217 | 218 | @rem input parameters: %1=nr of updates, %2=file name 219 | :message 220 | set __N=%~1 221 | set __FILE_NAME=%~2 222 | if %__N% gtr 1 ( set __STR=files ) else ( set __STR=file ) 223 | echo Updated %__N% %__FILE_NAME% %__STR% 224 | goto :eof 225 | 226 | @rem ######################################################################### 227 | @rem ## Cleanups 228 | 229 | :end 230 | if %_DEBUG%==1 echo %_DEBUG_LABEL% _EXITCODE=%_EXITCODE% 1>&2 231 | exit /b %_EXITCODE% 232 | endlocal 233 | -------------------------------------------------------------------------------- /bin/vswhere.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/bin/vswhere.exe -------------------------------------------------------------------------------- /docs/2002-08-09-LLVMCompilationStrategy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2002-08-09-LLVMCompilationStrategy.pdf -------------------------------------------------------------------------------- /docs/2002-08-09-LLVMCompilationStrategy.txt: -------------------------------------------------------------------------------- 1 | Source: https://llvm.org/pubs/2002-08-09-LLVMCompilationStrategy.pdf 2 | -------------------------------------------------------------------------------- /docs/2002-12-LattnerMSThesis.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2002-12-LattnerMSThesis.pdf -------------------------------------------------------------------------------- /docs/2002-12-LattnerMSThesis.txt: -------------------------------------------------------------------------------- 1 | Source: http://llvm.org/pubs/2002-12-LattnerMSThesis.pdf 2 | Web: http://llvm.org/pubs/2002-12-LattnerMSThesis.html 3 | -------------------------------------------------------------------------------- /docs/2015_1405.4565.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2015_1405.4565.pdf -------------------------------------------------------------------------------- /docs/2015_1405.4565.txt: -------------------------------------------------------------------------------- 1 | Source: https://arxiv.org/pdf/1405.4565.pdf 2 | -------------------------------------------------------------------------------- /docs/2016_VMIL_Efficient_Execution_of_LLVM_IR_on_Truffle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2016_VMIL_Efficient_Execution_of_LLVM_IR_on_Truffle.pdf -------------------------------------------------------------------------------- /docs/2016_VMIL_Efficient_Execution_of_LLVM_IR_on_Truffle.txt: -------------------------------------------------------------------------------- 1 | Source: http://ssw.jku.at/General/Staff/ManuelRigger/VMIL16.pdf 2 | -------------------------------------------------------------------------------- /docs/2018_LLVM_Documentation_Release_8.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2018_LLVM_Documentation_Release_8.pdf -------------------------------------------------------------------------------- /docs/2018_LLVM_Documentation_Release_8.txt: -------------------------------------------------------------------------------- 1 | Source: https://buildmedia.readthedocs.org/media/pdf/llvm/latest/llvm.pdf 2 | -------------------------------------------------------------------------------- /docs/2018_Rigger_Safe_and_Efficient_Execution_of LLVM_based_Languages.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2018_Rigger_Safe_and_Efficient_Execution_of LLVM_based_Languages.pdf -------------------------------------------------------------------------------- /docs/2018_Rigger_Safe_and_Efficient_Execution_of LLVM_based_Languages.txt: -------------------------------------------------------------------------------- 1 | Source: https://www.manuelrigger.at/preprints/ 2 | -------------------------------------------------------------------------------- /docs/2021_PLDI_Alive2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2021_PLDI_Alive2.pdf -------------------------------------------------------------------------------- /docs/2021_PLDI_Alive2.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2021_PLDI_Alive2.txt -------------------------------------------------------------------------------- /docs/2024_First_Steps_towards_Deductive_Verification_of_LLVM_IR.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/2024_First_Steps_towards_Deductive_Verification_of_LLVM_IR.pdf -------------------------------------------------------------------------------- /docs/2024_First_Steps_towards_Deductive_Verification_of_LLVM_IR.txt: -------------------------------------------------------------------------------- 1 | Source: https://link.springer.com/chapter/10.1007/978-3-031-57259-3_15 2 | -------------------------------------------------------------------------------- /docs/TutorialLLVMBackendCpu0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/TutorialLLVMBackendCpu0.pdf -------------------------------------------------------------------------------- /docs/TutorialLLVMBackendCpu0.txt: -------------------------------------------------------------------------------- 1 | Source: http://jonathan2251.github.io/lbd/TutorialLLVMBackendCpu0.pdf 2 | -------------------------------------------------------------------------------- /docs/images/llvm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/michelou/llvm-examples/970d96586c6ec569e62d24f283d120df6cb2afc4/docs/images/llvm.png -------------------------------------------------------------------------------- /examples/JITTutorial1/00download.txt: -------------------------------------------------------------------------------- 1 | Source: http://releases.llvm.org/2.6/docs/tutorial/JITTutorial1.html 2 | -------------------------------------------------------------------------------- /examples/JITTutorial1/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.14) 2 | 3 | project(JITTutorial1 VERSION 1.0.0 LANGUAGES CXX) 4 | 5 | find_package(LLVM REQUIRED CONFIG) 6 | 7 | list(APPEND CMAKE_MODULE_PATH "${LLVM_DIR}") 8 | message(STATUS "[DEBUG] CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}") 9 | message(STATUS "[DEBUG] LLVM_DIR=${LLVM_DIR}") 10 | 11 | # macro "add_llvm_executable" 12 | include(AddLLVM) 13 | 14 | add_definitions(${LLVM_DEFINITIONS}) 15 | include_directories(${LLVM_INCLUDE_DIRS}) 16 | link_directories(${LLVM_LIBRARY_DIRS}) 17 | 18 | if(MSVC) 19 | set(CMAKE_CXX_STANDARD 17) 20 | set(CMAKE_CXX_FLAGS "/O2 /wd4141 /wd4146 /wd4244 /wd4267 /wd4624 /wd4996") 21 | else() 22 | set(CMAKE_CXX_STANDARD 14) 23 | set(CMAKE_CXX_FLAGS "-O2 -Wall") 24 | endif() 25 | 26 | set(LLVM_LINK_COMPONENTS Core) 27 | 28 | file(GLOB SOURCE_FILES src/*.cpp src/*.h) 29 | 30 | add_llvm_executable(JITTutorial1 ${SOURCE_FILES}) 31 | -------------------------------------------------------------------------------- /examples/JITTutorial1/Makefile: -------------------------------------------------------------------------------- 1 | ## 2 | ## Copyright (c) 2018-2024 Stéphane Micheloud 3 | ## 4 | ## Licensed under the MIT License. 5 | ## 6 | ############################################################################## 7 | 8 | include ../Makefile.inc 9 | 10 | ############################################################################## 11 | ## main rules 12 | 13 | SOURCE_FILES = $(wildcard src/main/cpp/*.cpp) 14 | 15 | PROGRAM_NAME = JITTutorial1 16 | 17 | CONFIG = $(shell $(LLVM_CONFIG) --cxxflags --ldflags --system-libs --libs core) 18 | 19 | all: build 20 | 21 | build: $(SOURCE_FILES) 22 | "$(CXX)" -g -O3 $(CONFIG) -o main $< 23 | 24 | executable: build 25 | ./main 26 | "$(LLC)" -filetype=obj $(PROGRAM_NAME).ll -o $(PROGRAM_NAME).o 27 | "$(CXX)" $(PROGRAM_NAME).o -o $(PROGRAM_NAME) 28 | @$(ECHO) "'$(PROGRAM_NAME)' created!" 29 | 30 | run: executable 31 | ./$(PROGRAM_NAME) 32 | 33 | clean: 34 | #[ -f "main" ] && $(RM) -f main 35 | #[ -d "main.dSYM" ] && $(RM) -rf main.dSYM 36 | #[ -f "$(PROGRAM_NAME).ll" ] && $(RM) -f $(PROGRAM_NAME).ll 37 | #[ -f "$(PROGRAM_NAME).o" ] && $(RM) -f $(PROGRAM_NAME).o 38 | #[ -f "$(PROGRAM_NAME)" ] && $(RM) -f $(PROGRAM_NAME) 39 | 40 | help: 41 | @$(ECHO) "Usage: make all|build|clean|executable|help|run" 42 | @$(ECHO) "" 43 | @$(ECHO) " Subcommands:" 44 | @$(ECHO) " all alias for build" 45 | @$(ECHO) " build compile C++ source files" 46 | @$(ECHO) " clean delete generated files" 47 | @$(ECHO) " help display this help message" 48 | @$(ECHO) " run execute main program \"$(PROGRAM_NAME)\"" 49 | 50 | ############################################################################## 51 | ## phony 52 | 53 | .PHONY: all build clean executable help run 54 | 55 | .SUFFIXES: 56 | .SUFFIXES: .c .cpp .o .obj .exe 57 | -------------------------------------------------------------------------------- /examples/JITTutorial1/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # 3 | # Copyright (c) 2018-2024 Stéphane Micheloud 4 | # 5 | # Licensed under the MIT License. 6 | # 7 | 8 | ############################################################################## 9 | ## Subroutines 10 | 11 | getHome() { 12 | local source="${BASH_SOURCE[0]}" 13 | while [ -h "$source" ] ; do 14 | local linked="$(readlink "$source")" 15 | local dir="$( cd -P $(dirname "$source") && cd -P $(dirname "$linked") && pwd )" 16 | source="$dir/$(basename "$linked")" 17 | done 18 | ( cd -P "$(dirname "$source")" && pwd ) 19 | } 20 | 21 | debug() { 22 | local DEBUG_LABEL="[DEBUG]" 23 | $DEBUG && echo "$DEBUG_LABEL $1" 1>&2 24 | } 25 | 26 | warning() { 27 | local WARNING_LABEL="[WARNING]" 28 | echo "$WARNING_LABEL $1" 1>&2 29 | } 30 | 31 | error() { 32 | local ERROR_LABEL="Error:" 33 | echo "$ERROR_LABEL $1" 1>&2 34 | } 35 | 36 | # use variables EXITCODE, TIMER_START 37 | cleanup() { 38 | [[ $1 =~ ^[0-1]$ ]] && EXITCODE=$1 39 | 40 | if $TIMER; then 41 | local TIMER_END=$(date +'%s') 42 | local duration=$((TIMER_END - TIMER_START)) 43 | echo "Total elapsed time: $(date -d @$duration +'%H:%M:%S')" 1>&2 44 | fi 45 | debug "EXITCODE=$EXITCODE" 46 | exit $EXITCODE 47 | } 48 | 49 | args() { 50 | [[ $# -eq 0 ]] && HELP=true && return 1 51 | 52 | for arg in "$@"; do 53 | case "$arg" in 54 | ## options 55 | -clang) TOOLSET=clang ;; 56 | -debug) DEBUG=true ;; 57 | -gcc) TOOLSET=gcc ;; 58 | -help) HELP=true ;; 59 | -msvc) TOOLSET=msvc ;; 60 | -timer) TIMER=true ;; 61 | -verbose) VERBOSE=true ;; 62 | -*) 63 | error "Unknown option $arg" 64 | EXITCODE=1 && return 0 65 | ;; 66 | ## subcommands 67 | clean) CLEAN=true ;; 68 | compile) COMPILE=true ;; 69 | help) HELP=true ;; 70 | run) COMPILE=true && RUN=true ;; 71 | *) 72 | error "Unknown subcommand $arg" 73 | EXITCODE=1 && return 0 74 | ;; 75 | esac 76 | done 77 | debug "Options : TIMER=$TIMER VERBOSE=$VERBOSE" 78 | debug "Subcommands: CLEAN=$CLEAN COMPILE=$COMPILE HELP=$HELP RUN=$RUN" 79 | debug "Variables : DOXYGEN_HOME=$DOXYGEN_HOME" 80 | debug "Variables : LLVM_HOME=$LLVM_HOME" 81 | # See http://www.cyberciti.biz/faq/linux-unix-formatting-dates-for-display/ 82 | $TIMER && TIMER_START=$(date +"%s") 83 | } 84 | 85 | help() { 86 | cat << EOS 87 | Usage: $BASENAME {