├── .gitignore ├── CMakeLists.txt ├── LICENSE ├── README.md └── skeleton ├── CMakeLists.txt └── Skeleton.cpp /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.12) 2 | project(Skeleton) 3 | 4 | # LLVM uses C++17. 5 | set(CMAKE_CXX_STANDARD 17) 6 | 7 | # Load LLVMConfig.cmake. If this fails, consider setting `LLVM_DIR` to point 8 | # to your LLVM installation's `lib/cmake/llvm` directory. 9 | find_package(LLVM REQUIRED CONFIG) 10 | 11 | # Include the part of LLVM's CMake libraries that defines 12 | # `add_llvm_pass_plugin`. 13 | include(AddLLVM) 14 | 15 | # Use LLVM's preprocessor definitions, include directories, and library search 16 | # paths. 17 | add_definitions(${LLVM_DEFINITIONS}) 18 | include_directories(${LLVM_INCLUDE_DIRS}) 19 | link_directories(${LLVM_LIBRARY_DIRS}) 20 | 21 | # Our pass lives in this subdirectory. 22 | add_subdirectory(skeleton) 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Adrian Sampson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # llvm-pass-skeleton 2 | 3 | A completely useless LLVM pass. 4 | It's for LLVM 17. 5 | 6 | Build: 7 | 8 | $ cd llvm-pass-skeleton 9 | $ mkdir build 10 | $ cd build 11 | $ cmake .. 12 | $ make 13 | $ cd .. 14 | 15 | Run: 16 | 17 | $ clang -fpass-plugin=`echo build/skeleton/SkeletonPass.*` something.c 18 | -------------------------------------------------------------------------------- /skeleton/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_pass_plugin(SkeletonPass 2 | # List your source files here. 3 | Skeleton.cpp 4 | ) 5 | -------------------------------------------------------------------------------- /skeleton/Skeleton.cpp: -------------------------------------------------------------------------------- 1 | #include "llvm/Pass.h" 2 | #include "llvm/IR/Module.h" 3 | #include "llvm/Passes/PassBuilder.h" 4 | #include "llvm/Passes/PassPlugin.h" 5 | #include "llvm/Support/raw_ostream.h" 6 | 7 | using namespace llvm; 8 | 9 | namespace { 10 | 11 | struct SkeletonPass : public PassInfoMixin { 12 | PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM) { 13 | for (auto &F : M) { 14 | errs() << "I saw a function called " << F.getName() << "!\n"; 15 | } 16 | return PreservedAnalyses::all(); 17 | }; 18 | }; 19 | 20 | } 21 | 22 | extern "C" LLVM_ATTRIBUTE_WEAK ::llvm::PassPluginLibraryInfo 23 | llvmGetPassPluginInfo() { 24 | return { 25 | .APIVersion = LLVM_PLUGIN_API_VERSION, 26 | .PluginName = "Skeleton pass", 27 | .PluginVersion = "v0.1", 28 | .RegisterPassBuilderCallbacks = [](PassBuilder &PB) { 29 | PB.registerPipelineStartEPCallback( 30 | [](ModulePassManager &MPM, OptimizationLevel Level) { 31 | MPM.addPass(SkeletonPass()); 32 | }); 33 | } 34 | }; 35 | } 36 | --------------------------------------------------------------------------------