├── README.md └── llvm_note ├── class1 ├── mspdb140.dll └── note.md ├── class10 ├── 1.png ├── 2.png ├── android │ ├── jni │ │ ├── android.mk │ │ ├── application.mk │ │ └── test.c │ └── libs │ │ └── arm64-v8a │ │ ├── test_ollvm2 │ │ └── test_ollvm2.i64 ├── arm64-v8a │ └── test_ollvm └── note.md ├── class11 └── note.md ├── class12 └── note.md ├── class13 └── note.md ├── class14 ├── 1.png ├── 2.png ├── 3.png └── note.md ├── class15 └── note.md ├── class2 └── note.md ├── class3 ├── examples │ ├── AnnotateFunctions │ │ ├── AnnotateFunctions.cpp │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ ├── PrintFunctionNames │ │ ├── CMakeLists.txt │ │ ├── PrintFunctionNames.cpp │ │ └── README.txt │ ├── clang-interpreter │ │ ├── CMakeLists.txt │ │ ├── README.txt │ │ ├── Test.cxx │ │ └── main.cpp │ └── myplugin │ │ ├── CMakeLists.txt │ │ └── MyPlugin.cpp └── note.md ├── class4 ├── examples │ ├── AnnotateFunctions │ │ ├── AnnotateFunctions.cpp │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ ├── CodeChecker │ │ ├── CMakeLists.txt │ │ └── CodeChecker.cpp │ ├── PrintFunctionNames │ │ ├── CMakeLists.txt │ │ ├── PrintFunctionNames.cpp │ │ └── README.txt │ ├── clang-interpreter │ │ ├── CMakeLists.txt │ │ ├── README.txt │ │ ├── Test.cxx │ │ └── main.cpp │ └── myplugin │ │ ├── CMakeLists.txt │ │ └── MyPlugin.cpp ├── note.md └── test │ ├── test.jpg │ ├── testclang.zip │ └── testclang │ ├── testclang.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcuserdata │ │ │ └── haidragon.xcuserdatad │ │ │ └── UserInterfaceState.xcuserstate │ └── xcuserdata │ │ └── haidragon.xcuserdatad │ │ └── xcschemes │ │ └── xcschememanagement.plist │ ├── testclang │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ └── Main.storyboard │ ├── Info.plist │ ├── ViewController.h │ ├── ViewController.m │ ├── main.m │ ├── test_clang.h │ ├── test_clang.m │ └── testclang.entitlements │ ├── testclangTests │ ├── Info.plist │ └── testclangTests.m │ └── testclangUITests │ ├── Info.plist │ └── testclangUITests.m ├── class5 ├── LLVMHello.dylib ├── note.md ├── opt.png ├── test.bc └── test.m ├── class9 ├── note.md ├── test.c ├── test.png ├── test2.png ├── test3.png ├── test_1 ├── test_fla ├── test_ollvm ├── xc2.png └── xcode.png ├── class_5 └── note.md ├── class_6 └── note.md └── class_7 └── note.md /README.md: -------------------------------------------------------------------------------- 1 | # 更完整的视频教程 https://edu.csdn.net/course/detail/31214 2 | 3 | 4 | 5 | # study_obscure 6 | 混淆反混淆视频教程 7 | # 第一章 llvm项目简单使用 8 | * 第一课 llvm项目 编译(windows xcode) 9 | * 链接: https://pan.baidu.com/s/1ILvoVripdAcHF9NLKJYZ2A 10 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class1/note.md 11 | * 第二课 clang编译与调试(xcode) 12 | * 链接: https://pan.baidu.com/s/1MHvB4IysZ0v_0vMz1NJOhA 13 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class2/note.md 14 | * 第三课 clang插件编写 15 | * 链接: https://pan.baidu.com/s/1iwi0AIcis8M8ZBIBg27Nwg 16 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class3/note.md 17 | * 第四课 实现一个自定义检查规范的 Clang 插件 18 | * 链接: https://pan.baidu.com/s/1rWOowwOMAm2SrOh-nxPT6w 19 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class4/note.md 20 | * 第五课 llvm-词法分析 21 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class_5/note.md 22 | * 第六课 llvm-语法分析 23 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class_6/note.md 24 | * 第七课 单个函数的解释器实现 25 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class_7/note.md 26 | # 第二章 llvm与ollvm混淆使用 27 | * 第八课 llvm pass 编译与调试 28 | * 链接: https://pan.baidu.com/s/1yMFw-FlG_-eXRCJl25tNXg 29 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class5/note.md 30 | * 第九课 ollvm编译(mac/linux) 31 | * 链接: https://pan.baidu.com/s/1qC3YY3nJYa46fe2xtl4iPw 32 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/note.md 33 | * 第十课 ollvm 集成android(ndk) 34 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class10/note.md 35 | * 第十一课 ollvm android中使用 36 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class11/note.md 37 | * 第十二课 ollvm 集成xcode 38 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class12/note.md 39 | * 第十三课 ollvm ios中使用 40 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class13/note.md 41 | * 第十四课 ollvm 在windows上的使用 42 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class14/note.md 43 | * 第十五课 ollvm 在驱动中的应用 44 | * https://github.com/haidragon/study_obscure/blob/master/llvm_note/class15/note.md 45 | # 第三章 ollvm源码分析 46 | * 47 | # 第四章 ollvm反混淆 48 | # 第五章 Unicorn 49 | # 视频持续更新....... 50 | # 其它教程 51 | * study_firewall https://github.com/haidragon/study_firewall 52 | * study_frida https://github.com/haidragon/study_frida 53 | * study_Android_Mchange https://github.com/haidragon/study_Android_Mchange 54 | * study_exploits https://github.com/haidragon/study_exploits 55 | * study_executable_file_formats https://github.com/haidragon/study_executable_file_formats 56 | * study_computer_forensics https://github.com/haidragon/study_computer_forensics 57 | * study_anti_rootkit https://github.com/haidragon/study_anti_rootkit 58 | * study_file_filter https://github.com/haidragon/study_file_filter 59 | * study_injection_and_hook https://github.com/haidragon/study_injection_and_hook 60 | * study_reverse_analysis https://github.com/haidragon/study_reverse_analysis 61 | * study_tools https://github.com/haidragon/study_tools 62 | * study_exceptions_and_debugging https://github.com/haidragon/study_exceptions_and_debugging 63 | * study_Xposed https://github.com/haidragon/study_Xposed 64 | * study_protocol_analysis https://github.com/haidragon/study_protocol_analysis 65 | * 有的课题可能没第一时在这写,可以关注我微博 [haidragonx](https://weibo.com/haidragon)同时我也会出其它教程,比如 主动防御(window驱动/linux驱动/mac驱动)、android/ios逆向、流量分析等等 有任何问题。可以联系作者 66 | * qq/wechat:2207344074 67 | 68 | -------------------------------------------------------------------------------- /llvm_note/class1/mspdb140.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class1/mspdb140.dll -------------------------------------------------------------------------------- /llvm_note/class1/note.md: -------------------------------------------------------------------------------- 1 | # 第一课 llvm项目 编译(windows mac) 2 | ## mac下 3 | * 命令行 4 | ``` 5 | git clone https://github.com/llvm/llvm-project 6 | cd llvm-project 7 | mkdir build 8 | cd build 9 | cmake -G "Unix Makefiles" ../llvm 10 | make -j 10 11 | ``` 12 | * xcode 13 | ``` 14 | git clone https://github.com/llvm/llvm-project 15 | cd llvm-project 16 | mkdir build 17 | cd build 18 | cmake -G "Xcode" ../llvm 19 | ``` 20 | * 编译clang 21 | ``` 22 | git clone https://github.com/llvm/llvm-project 23 | cd llvm-project 24 | mkdir build 25 | cd build 26 | cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm 27 | cmake -DLLVM_ENABLE_PROJECTS=clang -G "Xcode" ../llvm 28 | ``` 29 | ## 说明 30 | 建议用git上的项目,直接下载官网的项目生成Xcode环境编译会出现各种问题,命令行是没有问题。 31 | ## windows vs项目 32 | * 命令行 (用cygwin) 33 | ``` 34 | git clone https://github.com/llvm/llvm-project -b xxx 35 | cd llvm-project 36 | mkdir build 37 | cd build 38 | //cmake -G "Visual Studio 14 2015" ../llvm (可能不行要用最高vs版本) 39 | cmake -G "Visual Studio 16 2019" ../llvm (ml.exe可能报少库) 40 | ``` 41 | # cmake-gui 42 | * (ml.exe可能报少库,这里报少[mspdb140.dll](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class1/mspdb140.dll) 网上下载放入对应目录这里是[C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\x86_amd64]) 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /llvm_note/class10/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class10/1.png -------------------------------------------------------------------------------- /llvm_note/class10/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class10/2.png -------------------------------------------------------------------------------- /llvm_note/class10/android/jni/android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_ARM_MODE := arm 6 | LOCAL_MODULE := test_ollvm 7 | LOCAL_SRC_FILES := test.c 8 | LOCAL_CFLAGS := -mllvm -fla -mllvm -split -mllvm -split_num=3 -mllvm -sub -mllvm -sub_loop=3 -mllvm -bcf -mllvm -bcf_loop=3 -mllvm -sobf 9 | include $(BUILD_EXECUTABLE) #include $(BUILD_SHARED_LIBRARY) 生成库 10 | -------------------------------------------------------------------------------- /llvm_note/class10/android/jni/application.mk: -------------------------------------------------------------------------------- 1 | APP_ABI := all 2 | -------------------------------------------------------------------------------- /llvm_note/class10/android/jni/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int add (int a,int b){ 4 | return a+b; 5 | } 6 | 7 | int main(int argc, char **argv)//注意main有参数 8 | { 9 | add(1,2); 10 | if (argc == 1) { 11 | printf("%d\n", argc); 12 | return 0; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /llvm_note/class10/android/libs/arm64-v8a/test_ollvm2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class10/android/libs/arm64-v8a/test_ollvm2 -------------------------------------------------------------------------------- /llvm_note/class10/android/libs/arm64-v8a/test_ollvm2.i64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class10/android/libs/arm64-v8a/test_ollvm2.i64 -------------------------------------------------------------------------------- /llvm_note/class10/arm64-v8a/test_ollvm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class10/arm64-v8a/test_ollvm -------------------------------------------------------------------------------- /llvm_note/class10/note.md: -------------------------------------------------------------------------------- 1 | # 第十课 ollvm 集成android(ndk) 2 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class10/1.png) 3 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class10/2.png) 4 | 5 | 6 | -------------------------------------------------------------------------------- /llvm_note/class11/note.md: -------------------------------------------------------------------------------- 1 | # 第十一课 ollvm android中使用 2 | 3 | 4 | -------------------------------------------------------------------------------- /llvm_note/class12/note.md: -------------------------------------------------------------------------------- 1 | # 第十二课 ollvm 集成xcode 2 | # xcode集成配置 3 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/xc2.png) 4 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/xcode.png) 5 | 6 | 7 | -------------------------------------------------------------------------------- /llvm_note/class13/note.md: -------------------------------------------------------------------------------- 1 | # 第十三课 ollvm ios中使用 2 | 3 | 4 | -------------------------------------------------------------------------------- /llvm_note/class14/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class14/1.png -------------------------------------------------------------------------------- /llvm_note/class14/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class14/2.png -------------------------------------------------------------------------------- /llvm_note/class14/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class14/3.png -------------------------------------------------------------------------------- /llvm_note/class14/note.md: -------------------------------------------------------------------------------- 1 | # 第十四课 ollvm 在windows上的使用 2 | ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class14/1.png) 3 | ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class14/2.png) 4 | ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class14/3.png) 5 | 6 | 7 | -------------------------------------------------------------------------------- /llvm_note/class15/note.md: -------------------------------------------------------------------------------- 1 | # 第十五课 ollvm 在驱动中的应用 2 | 待更新。。。。。 3 | 4 | 5 | -------------------------------------------------------------------------------- /llvm_note/class2/note.md: -------------------------------------------------------------------------------- 1 | # 第二课 clang编译与调试(xcode) 2 | * clang 编译 3 | ``` 4 | git clone https://github.com/llvm/llvm-project 5 | cd llvm-project 6 | mkdir build 7 | cd build 8 | cmake -DLLVM_ENABLE_PROJECTS=clang -G "Unix Makefiles" ../llvm 9 | cmake -DLLVM_ENABLE_PROJECTS=clang -G "Xcode" ../llvm 10 | ``` 11 | * lldb 命令 12 | ``` 13 | image list 14 | image lookup -n main 查看函数符号信息 15 | ``` 16 | 17 | 18 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/AnnotateFunctions/AnnotateFunctions.cpp: -------------------------------------------------------------------------------- 1 | //===- AnnotateFunctions.cpp ----------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // Example clang plugin which adds an annotation to every function in 10 | // translation units that start with #pragma enable_annotate. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "clang/Frontend/FrontendPluginRegistry.h" 15 | #include "clang/AST/AST.h" 16 | #include "clang/AST/ASTConsumer.h" 17 | #include "clang/Lex/Preprocessor.h" 18 | #include "clang/Lex/LexDiagnostic.h" 19 | using namespace clang; 20 | 21 | namespace { 22 | 23 | static bool EnableAnnotate = false; 24 | static bool HandledDecl = false; 25 | 26 | class AnnotateFunctionsConsumer : public ASTConsumer { 27 | public: 28 | bool HandleTopLevelDecl(DeclGroupRef DG) override { 29 | HandledDecl = true; 30 | if (!EnableAnnotate) 31 | return true; 32 | for (auto D : DG) 33 | if (FunctionDecl *FD = dyn_cast(D)) 34 | FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(), 35 | "example_annotation")); 36 | return true; 37 | } 38 | }; 39 | 40 | class AnnotateFunctionsAction : public PluginASTAction { 41 | public: 42 | std::unique_ptr CreateASTConsumer(CompilerInstance &CI, 43 | llvm::StringRef) override { 44 | return llvm::make_unique(); 45 | } 46 | 47 | bool ParseArgs(const CompilerInstance &CI, 48 | const std::vector &args) override { 49 | return true; 50 | } 51 | 52 | PluginASTAction::ActionType getActionType() override { 53 | return AddBeforeMainAction; 54 | } 55 | }; 56 | 57 | class PragmaAnnotateHandler : public PragmaHandler { 58 | public: 59 | PragmaAnnotateHandler() : PragmaHandler("enable_annotate") { } 60 | 61 | void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, 62 | Token &PragmaTok) override { 63 | 64 | Token Tok; 65 | PP.LexUnexpandedToken(Tok); 66 | if (Tok.isNot(tok::eod)) 67 | PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma"; 68 | 69 | if (HandledDecl) { 70 | DiagnosticsEngine &D = PP.getDiagnostics(); 71 | unsigned ID = D.getCustomDiagID( 72 | DiagnosticsEngine::Error, 73 | "#pragma enable_annotate not allowed after declarations"); 74 | D.Report(PragmaTok.getLocation(), ID); 75 | } 76 | 77 | EnableAnnotate = true; 78 | } 79 | }; 80 | 81 | } 82 | 83 | static FrontendPluginRegistry::Add 84 | X("annotate-fns", "annotate functions"); 85 | 86 | static PragmaHandlerRegistry::Add 87 | Y("enable_annotate","enable annotation"); 88 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/AnnotateFunctions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_library(AnnotateFunctions MODULE AnnotateFunctions.cpp PLUGIN_TOOL clang) 2 | 3 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 4 | set(LLVM_LINK_COMPONENTS 5 | Support 6 | ) 7 | clang_target_link_libraries(AnnotateFunctions PRIVATE 8 | clangAST 9 | clangBasic 10 | clangFrontend 11 | clangLex 12 | ) 13 | endif() 14 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT CLANG_BUILD_EXAMPLES) 2 | set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON) 3 | set(EXCLUDE_FROM_ALL ON) 4 | endif() 5 | 6 | add_subdirectory(clang-interpreter) 7 | add_subdirectory(PrintFunctionNames) 8 | add_subdirectory(AnnotateFunctions) 9 | add_subdirectory(myplugin) 10 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/PrintFunctionNames/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # If we don't need RTTI or EH, there's no reason to export anything 2 | # from the plugin. 3 | if( NOT MSVC ) # MSVC mangles symbols differently, and 4 | # PrintFunctionNames.export contains C++ symbols. 5 | if( NOT LLVM_REQUIRES_RTTI ) 6 | if( NOT LLVM_REQUIRES_EH ) 7 | set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/PrintFunctionNames.exports) 8 | endif() 9 | endif() 10 | endif() 11 | 12 | add_llvm_library(PrintFunctionNames MODULE PrintFunctionNames.cpp PLUGIN_TOOL clang) 13 | 14 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 15 | set(LLVM_LINK_COMPONENTS 16 | Support 17 | ) 18 | clang_target_link_libraries(PrintFunctionNames PRIVATE 19 | clangAST 20 | clangBasic 21 | clangFrontend 22 | ) 23 | endif() 24 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/PrintFunctionNames/PrintFunctionNames.cpp: -------------------------------------------------------------------------------- 1 | //===- PrintFunctionNames.cpp ---------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // Example clang plugin which simply prints the names of all the top-level decls 10 | // in the input file. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "clang/Frontend/FrontendPluginRegistry.h" 15 | #include "clang/AST/AST.h" 16 | #include "clang/AST/ASTConsumer.h" 17 | #include "clang/AST/RecursiveASTVisitor.h" 18 | #include "clang/Frontend/CompilerInstance.h" 19 | #include "clang/Sema/Sema.h" 20 | #include "llvm/Support/raw_ostream.h" 21 | using namespace clang; 22 | 23 | namespace { 24 | 25 | class PrintFunctionsConsumer : public ASTConsumer { 26 | CompilerInstance &Instance; 27 | std::set ParsedTemplates; 28 | 29 | public: 30 | PrintFunctionsConsumer(CompilerInstance &Instance, 31 | std::set ParsedTemplates) 32 | : Instance(Instance), ParsedTemplates(ParsedTemplates) {} 33 | 34 | bool HandleTopLevelDecl(DeclGroupRef DG) override { 35 | for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) { 36 | const Decl *D = *i; 37 | if (const NamedDecl *ND = dyn_cast(D)) 38 | llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n"; 39 | } 40 | 41 | return true; 42 | } 43 | 44 | void HandleTranslationUnit(ASTContext& context) override { 45 | if (!Instance.getLangOpts().DelayedTemplateParsing) 46 | return; 47 | 48 | // This demonstrates how to force instantiation of some templates in 49 | // -fdelayed-template-parsing mode. (Note: Doing this unconditionally for 50 | // all templates is similar to not using -fdelayed-template-parsig in the 51 | // first place.) 52 | // The advantage of doing this in HandleTranslationUnit() is that all 53 | // codegen (when using -add-plugin) is completely finished and this can't 54 | // affect the compiler output. 55 | struct Visitor : public RecursiveASTVisitor { 56 | const std::set &ParsedTemplates; 57 | Visitor(const std::set &ParsedTemplates) 58 | : ParsedTemplates(ParsedTemplates) {} 59 | bool VisitFunctionDecl(FunctionDecl *FD) { 60 | if (FD->isLateTemplateParsed() && 61 | ParsedTemplates.count(FD->getNameAsString())) 62 | LateParsedDecls.insert(FD); 63 | return true; 64 | } 65 | 66 | std::set LateParsedDecls; 67 | } v(ParsedTemplates); 68 | v.TraverseDecl(context.getTranslationUnitDecl()); 69 | clang::Sema &sema = Instance.getSema(); 70 | for (const FunctionDecl *FD : v.LateParsedDecls) { 71 | clang::LateParsedTemplate &LPT = 72 | *sema.LateParsedTemplateMap.find(FD)->second; 73 | sema.LateTemplateParser(sema.OpaqueParser, LPT); 74 | llvm::errs() << "late-parsed-decl: \"" << FD->getNameAsString() << "\"\n"; 75 | } 76 | } 77 | }; 78 | 79 | class PrintFunctionNamesAction : public PluginASTAction { 80 | std::set ParsedTemplates; 81 | protected: 82 | std::unique_ptr CreateASTConsumer(CompilerInstance &CI, 83 | llvm::StringRef) override { 84 | return llvm::make_unique(CI, ParsedTemplates); 85 | } 86 | 87 | bool ParseArgs(const CompilerInstance &CI, 88 | const std::vector &args) override { 89 | for (unsigned i = 0, e = args.size(); i != e; ++i) { 90 | llvm::errs() << "PrintFunctionNames arg = " << args[i] << "\n"; 91 | 92 | // Example error handling. 93 | DiagnosticsEngine &D = CI.getDiagnostics(); 94 | if (args[i] == "-an-error") { 95 | unsigned DiagID = D.getCustomDiagID(DiagnosticsEngine::Error, 96 | "invalid argument '%0'"); 97 | D.Report(DiagID) << args[i]; 98 | return false; 99 | } else if (args[i] == "-parse-template") { 100 | if (i + 1 >= e) { 101 | D.Report(D.getCustomDiagID(DiagnosticsEngine::Error, 102 | "missing -parse-template argument")); 103 | return false; 104 | } 105 | ++i; 106 | ParsedTemplates.insert(args[i]); 107 | } 108 | } 109 | if (!args.empty() && args[0] == "help") 110 | PrintHelp(llvm::errs()); 111 | 112 | return true; 113 | } 114 | void PrintHelp(llvm::raw_ostream& ros) { 115 | ros << "Help for PrintFunctionNames plugin goes here\n"; 116 | } 117 | 118 | }; 119 | 120 | } 121 | 122 | static FrontendPluginRegistry::Add 123 | X("print-fns", "print function names"); 124 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/PrintFunctionNames/README.txt: -------------------------------------------------------------------------------- 1 | This is a simple example demonstrating how to use clang's facility for 2 | providing AST consumers using a plugin. 3 | 4 | Build the plugin by running `make` in this directory. 5 | 6 | Once the plugin is built, you can run it using: 7 | -- 8 | Linux: 9 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns some-input-file.c 10 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns -plugin-arg-print-fns help -plugin-arg-print-fns --example-argument some-input-file.c 11 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns -plugin-arg-print-fns -an-error some-input-file.c 12 | 13 | Mac: 14 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns some-input-file.c 15 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns -plugin-arg-print-fns help -plugin-arg-print-fns --example-argument some-input-file.c 16 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns -plugin-arg-print-fns -an-error some-input-file.c 17 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/clang-interpreter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Core 3 | ExecutionEngine 4 | MC 5 | MCJIT 6 | Object 7 | OrcJit 8 | Option 9 | RuntimeDyld 10 | Support 11 | native 12 | ) 13 | 14 | add_clang_executable(clang-interpreter 15 | main.cpp 16 | ) 17 | 18 | add_dependencies(clang-interpreter 19 | clang-resource-headers 20 | ) 21 | 22 | clang_target_link_libraries(clang-interpreter 23 | PRIVATE 24 | clangBasic 25 | clangCodeGen 26 | clangDriver 27 | clangFrontend 28 | clangSerialization 29 | ) 30 | 31 | export_executable_symbols(clang-interpreter) 32 | 33 | if (MSVC) 34 | # Is this a CMake bug that even with export_executable_symbols, Windows 35 | # needs to explictly export the type_info vtable 36 | set_property(TARGET clang-interpreter 37 | APPEND_STRING PROPERTY LINK_FLAGS " /EXPORT:??_7type_info@@6B@") 38 | endif() 39 | 40 | function(clang_enable_exceptions TARGET) 41 | # Really have to jump through hoops to enable exception handling independent 42 | # of how LLVM is being built. 43 | if (NOT LLVM_REQUIRES_EH AND NOT LLVM_REQUIRES_RTTI) 44 | if (MSVC) 45 | # /EHs to allow throwing from extern "C" 46 | set(excptnExceptions_ON "/D _HAS_EXCEPTIONS=1 /EHs /wd4714") 47 | set(excptnExceptions_OFF "/D _HAS_EXCEPTIONS=0 /EHs-c-") 48 | set(excptnRTTI_ON "/GR") 49 | set(excptnRTTI_OFF "/GR-") 50 | set(excptnEHRTTIRegEx "(/EHs(-c-?)|_HAS_EXCEPTIONS=(0|1))") 51 | else() 52 | set(excptnExceptions_ON "-fexceptions") 53 | set(excptnExceptions_OFF "-fno-exceptions") 54 | set(excptnRTTI_ON "-frtti") 55 | set(excptnRTTI_OFF "-fno-rtti") 56 | set(excptnEHRTTIRegEx "-f(exceptions|no-exceptions)") 57 | endif() 58 | if (LLVM_REQUIRES_EH) 59 | set(excptnExceptions_DFLT ${excptnExceptions_ON}) 60 | else() 61 | set(excptnExceptions_DFLT ${excptnExceptions_OFF}) 62 | endif() 63 | if (LLVM_REQUIRES_RTTI) 64 | set(excptnRTTI_DFLT ${excptnRTTI_ON}) 65 | else() 66 | set(excptnRTTI_DFLT ${excptnRTTI_OFF}) 67 | endif() 68 | 69 | # Strip the exception & rtti flags from the target 70 | get_property(addedFlags TARGET ${TARGET} PROPERTY COMPILE_FLAGS) 71 | string(REGEX REPLACE ${excptnEHRTTIRegEx} "" editedFlags "${addedFlags}") 72 | string(REPLACE ${excptnRTTI_OFF} "" editedFlags "${editedFlags}") 73 | set_property(TARGET ${TARGET} PROPERTY COMPILE_FLAGS "${editedFlags}") 74 | 75 | get_property(addedFlags TARGET ${TARGET} PROPERTY COMPILE_DEFINITIONS) 76 | string(REGEX REPLACE ${excptnEHRTTIRegEx} "" editedFlags "${addedFlags}") 77 | string(REPLACE ${excptnRTTI_OFF} "" editedFlags "${editedFlags}") 78 | set_property(TARGET ${TARGET} PROPERTY COMPILE_DEFINITIONS "${editedFlags}") 79 | 80 | # Re-add the exception & rtti flags from LLVM 81 | set_property(SOURCE main.cpp APPEND_STRING PROPERTY COMPILE_FLAGS 82 | " ${excptnExceptions_DFLT} ${excptnRTTI_DFLT} ") 83 | set_property(SOURCE Manager.cpp APPEND_STRING PROPERTY COMPILE_FLAGS 84 | " ${excptnExceptions_DFLT} ${excptnRTTI_DFLT} ") 85 | 86 | # Invoke with exceptions & rtti 87 | set_property(SOURCE Invoke.cpp APPEND_STRING PROPERTY COMPILE_FLAGS 88 | " ${excptnExceptions_ON} ${excptnRTTI_ON} ") 89 | 90 | endif() 91 | endfunction(clang_enable_exceptions) 92 | 93 | clang_enable_exceptions(clang-interpreter) 94 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/clang-interpreter/README.txt: -------------------------------------------------------------------------------- 1 | This is an example of Clang based interpreter, for executing standalone C/C++ 2 | programs. 3 | 4 | It demonstrates the following features: 5 | 1. Parsing standard compiler command line arguments using the Driver library. 6 | 7 | 2. Constructing a Clang compiler instance, using the appropriate arguments 8 | derived in step #1. 9 | 10 | 3. Invoking the Clang compiler to lex, parse, syntax check, and then generate 11 | LLVM code. 12 | 13 | 4. Use the LLVM JIT functionality to execute the final module. 14 | 15 | 5. Intercepting a Win64 library call to allow throwing and catching exceptions 16 | in and from the JIT. 17 | 18 | The implementation has many limitations and is not designed to be a full fledged 19 | interpreter. It is designed to demonstrate a simple but functional use of the 20 | Clang compiler libraries. 21 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/clang-interpreter/Test.cxx: -------------------------------------------------------------------------------- 1 | //===-- examples/clang-interpreter/Test.cxx - Clang C Interpreter Example -===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Example throwing in and from the JIT (particularly on Win64). 10 | // 11 | // ./bin/clang-interpreter /tools/clang/examples/clang-interpreter/Test.cxx 12 | 13 | #include 14 | #include 15 | 16 | static void ThrowerAnError(const char* Name) { 17 | throw std::runtime_error(Name); 18 | } 19 | 20 | int main(int argc, const char** argv) { 21 | for (int I = 0; I < argc; ++I) 22 | printf("arg[%d]='%s'\n", I, argv[I]); 23 | 24 | try { 25 | ThrowerAnError("In JIT"); 26 | } catch (const std::exception& E) { 27 | printf("Caught: '%s'\n", E.what()); 28 | } catch (...) { 29 | printf("Unknown exception\n"); 30 | } 31 | ThrowerAnError("From JIT"); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/clang-interpreter/main.cpp: -------------------------------------------------------------------------------- 1 | //===-- examples/clang-interpreter/main.cpp - Clang C Interpreter Example -===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #include "clang/Basic/DiagnosticOptions.h" 10 | #include "clang/CodeGen/CodeGenAction.h" 11 | #include "clang/Driver/Compilation.h" 12 | #include "clang/Driver/Driver.h" 13 | #include "clang/Driver/Tool.h" 14 | #include "clang/Frontend/CompilerInstance.h" 15 | #include "clang/Frontend/CompilerInvocation.h" 16 | #include "clang/Frontend/FrontendDiagnostic.h" 17 | #include "clang/Frontend/TextDiagnosticPrinter.h" 18 | #include "llvm/ADT/SmallString.h" 19 | #include "llvm/ExecutionEngine/ExecutionEngine.h" 20 | #include "llvm/ExecutionEngine/Orc/CompileUtils.h" 21 | #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" 22 | #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" 23 | #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" 24 | #include "llvm/ExecutionEngine/SectionMemoryManager.h" 25 | #include "llvm/IR/DataLayout.h" 26 | #include "llvm/IR/Mangler.h" 27 | #include "llvm/IR/Module.h" 28 | #include "llvm/Support/FileSystem.h" 29 | #include "llvm/Support/Host.h" 30 | #include "llvm/Support/ManagedStatic.h" 31 | #include "llvm/Support/Path.h" 32 | #include "llvm/Support/TargetSelect.h" 33 | #include "llvm/Support/raw_ostream.h" 34 | #include "llvm/Target/TargetMachine.h" 35 | 36 | using namespace clang; 37 | using namespace clang::driver; 38 | 39 | // This function isn't referenced outside its translation unit, but it 40 | // can't use the "static" keyword because its address is used for 41 | // GetMainExecutable (since some platforms don't support taking the 42 | // address of main, and some platforms can't implement GetMainExecutable 43 | // without being given the address of a function in the main executable). 44 | std::string GetExecutablePath(const char *Argv0, void *MainAddr) { 45 | return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); 46 | } 47 | 48 | namespace llvm { 49 | namespace orc { 50 | 51 | class SimpleJIT { 52 | private: 53 | ExecutionSession ES; 54 | std::unique_ptr TM; 55 | const DataLayout DL; 56 | MangleAndInterner Mangle{ES, DL}; 57 | RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr}; 58 | IRCompileLayer CompileLayer{ES, ObjectLayer, SimpleCompiler(*TM)}; 59 | 60 | static std::unique_ptr createMemMgr() { 61 | return llvm::make_unique(); 62 | } 63 | 64 | SimpleJIT(std::unique_ptr TM, DataLayout DL, 65 | DynamicLibrarySearchGenerator ProcessSymbolsGenerator) 66 | : TM(std::move(TM)), DL(std::move(DL)) { 67 | llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr); 68 | ES.getMainJITDylib().setGenerator(std::move(ProcessSymbolsGenerator)); 69 | } 70 | 71 | public: 72 | static Expected> Create() { 73 | auto JTMB = JITTargetMachineBuilder::detectHost(); 74 | if (!JTMB) 75 | return JTMB.takeError(); 76 | 77 | auto TM = JTMB->createTargetMachine(); 78 | if (!TM) 79 | return TM.takeError(); 80 | 81 | auto DL = (*TM)->createDataLayout(); 82 | 83 | auto ProcessSymbolsGenerator = 84 | DynamicLibrarySearchGenerator::GetForCurrentProcess( 85 | DL.getGlobalPrefix()); 86 | 87 | if (!ProcessSymbolsGenerator) 88 | return ProcessSymbolsGenerator.takeError(); 89 | 90 | return std::unique_ptr(new SimpleJIT( 91 | std::move(*TM), std::move(DL), std::move(*ProcessSymbolsGenerator))); 92 | } 93 | 94 | const TargetMachine &getTargetMachine() const { return *TM; } 95 | 96 | Error addModule(ThreadSafeModule M) { 97 | return CompileLayer.add(ES.getMainJITDylib(), std::move(M)); 98 | } 99 | 100 | Expected findSymbol(const StringRef &Name) { 101 | return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name)); 102 | } 103 | 104 | Expected getSymbolAddress(const StringRef &Name) { 105 | auto Sym = findSymbol(Name); 106 | if (!Sym) 107 | return Sym.takeError(); 108 | return Sym->getAddress(); 109 | } 110 | }; 111 | 112 | } // end namespace orc 113 | } // end namespace llvm 114 | 115 | llvm::ExitOnError ExitOnErr; 116 | 117 | int main(int argc, const char **argv) { 118 | // This just needs to be some symbol in the binary; C++ doesn't 119 | // allow taking the address of ::main however. 120 | void *MainAddr = (void*) (intptr_t) GetExecutablePath; 121 | std::string Path = GetExecutablePath(argv[0], MainAddr); 122 | IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); 123 | TextDiagnosticPrinter *DiagClient = 124 | new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); 125 | 126 | IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); 127 | DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); 128 | 129 | const std::string TripleStr = llvm::sys::getProcessTriple(); 130 | llvm::Triple T(TripleStr); 131 | 132 | // Use ELF on Windows-32 and MingW for now. 133 | #ifndef CLANG_INTERPRETER_COFF_FORMAT 134 | if (T.isOSBinFormatCOFF()) 135 | T.setObjectFormat(llvm::Triple::ELF); 136 | #endif 137 | 138 | ExitOnErr.setBanner("clang interpreter"); 139 | 140 | Driver TheDriver(Path, T.str(), Diags); 141 | TheDriver.setTitle("clang interpreter"); 142 | TheDriver.setCheckInputsExist(false); 143 | 144 | // FIXME: This is a hack to try to force the driver to do something we can 145 | // recognize. We need to extend the driver library to support this use model 146 | // (basically, exactly one input, and the operation mode is hard wired). 147 | SmallVector Args(argv, argv + argc); 148 | Args.push_back("-fsyntax-only"); 149 | std::unique_ptr C(TheDriver.BuildCompilation(Args)); 150 | if (!C) 151 | return 0; 152 | 153 | // FIXME: This is copied from ASTUnit.cpp; simplify and eliminate. 154 | 155 | // We expect to get back exactly one command job, if we didn't something 156 | // failed. Extract that job from the compilation. 157 | const driver::JobList &Jobs = C->getJobs(); 158 | if (Jobs.size() != 1 || !isa(*Jobs.begin())) { 159 | SmallString<256> Msg; 160 | llvm::raw_svector_ostream OS(Msg); 161 | Jobs.Print(OS, "; ", true); 162 | Diags.Report(diag::err_fe_expected_compiler_job) << OS.str(); 163 | return 1; 164 | } 165 | 166 | const driver::Command &Cmd = cast(*Jobs.begin()); 167 | if (llvm::StringRef(Cmd.getCreator().getName()) != "clang") { 168 | Diags.Report(diag::err_fe_expected_clang_command); 169 | return 1; 170 | } 171 | 172 | // Initialize a compiler invocation object from the clang (-cc1) arguments. 173 | const llvm::opt::ArgStringList &CCArgs = Cmd.getArguments(); 174 | std::unique_ptr CI(new CompilerInvocation); 175 | CompilerInvocation::CreateFromArgs(*CI, 176 | const_cast(CCArgs.data()), 177 | const_cast(CCArgs.data()) + 178 | CCArgs.size(), 179 | Diags); 180 | 181 | // Show the invocation, with -v. 182 | if (CI->getHeaderSearchOpts().Verbose) { 183 | llvm::errs() << "clang invocation:\n"; 184 | Jobs.Print(llvm::errs(), "\n", true); 185 | llvm::errs() << "\n"; 186 | } 187 | 188 | // FIXME: This is copied from cc1_main.cpp; simplify and eliminate. 189 | 190 | // Create a compiler instance to handle the actual work. 191 | CompilerInstance Clang; 192 | Clang.setInvocation(std::move(CI)); 193 | 194 | // Create the compilers actual diagnostics engine. 195 | Clang.createDiagnostics(); 196 | if (!Clang.hasDiagnostics()) 197 | return 1; 198 | 199 | // Infer the builtin include path if unspecified. 200 | if (Clang.getHeaderSearchOpts().UseBuiltinIncludes && 201 | Clang.getHeaderSearchOpts().ResourceDir.empty()) 202 | Clang.getHeaderSearchOpts().ResourceDir = 203 | CompilerInvocation::GetResourcesPath(argv[0], MainAddr); 204 | 205 | // Create and execute the frontend to generate an LLVM bitcode module. 206 | std::unique_ptr Act(new EmitLLVMOnlyAction()); 207 | if (!Clang.ExecuteAction(*Act)) 208 | return 1; 209 | 210 | llvm::InitializeNativeTarget(); 211 | llvm::InitializeNativeTargetAsmPrinter(); 212 | 213 | int Res = 255; 214 | std::unique_ptr Ctx(Act->takeLLVMContext()); 215 | std::unique_ptr Module = Act->takeModule(); 216 | 217 | if (Module) { 218 | auto J = ExitOnErr(llvm::orc::SimpleJIT::Create()); 219 | 220 | ExitOnErr(J->addModule( 221 | llvm::orc::ThreadSafeModule(std::move(Module), std::move(Ctx)))); 222 | auto Main = (int (*)(...))ExitOnErr(J->getSymbolAddress("main")); 223 | Res = Main(); 224 | } 225 | 226 | // Shutdown. 227 | llvm::llvm_shutdown(); 228 | 229 | return Res; 230 | } 231 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/myplugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_library(MyPlugin MODULE MyPlugin.cpp PLUGIN_TOOL clang) 2 | 3 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 4 | target_link_libraries(MyPlugin PRIVATE 5 | clangAST 6 | clangBasic 7 | clangFrontend 8 | clangLex 9 | LLVMSupport 10 | ) 11 | endif() 12 | -------------------------------------------------------------------------------- /llvm_note/class3/examples/myplugin/MyPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "clang/AST/AST.h" 3 | #include "clang/AST/ASTConsumer.h" 4 | #include "clang/AST/RecursiveASTVisitor.h" 5 | #include "clang/Frontend/CompilerInstance.h" 6 | #include "clang/Frontend/FrontendPluginRegistry.h" 7 | using namespace clang; 8 | using namespace std; 9 | using namespace llvm; 10 | namespace MyPlugin 11 | { 12 | class MyASTVisitor: public 13 | RecursiveASTVisitor < MyASTVisitor > 14 | { 15 | private: 16 | ASTContext *context; 17 | public: 18 | void setContext(ASTContext &context) 19 | { 20 | this->context = &context; 21 | } 22 | 23 | bool VisitDecl(Decl *decl) 24 | { 25 | cout << "-------- VisitDecl: haidragon"< (decl)) { 27 | ObjCInterfaceDecl *interDecl = (ObjCInterfaceDecl *)decl; 28 | if (interDecl->getSuperClass()) { 29 | string interName = interDecl->getNameAsString(); 30 | string superClassName = interDecl->getSuperClass()->getNameAsString(); 31 | 32 | cout << "-------- ClassName:" << interName << " superClassName:" << superClassName << endl; 33 | } 34 | } 35 | 36 | return true; 37 | } 38 | }; 39 | 40 | class MyASTConsumer: public ASTConsumer 41 | { 42 | private: 43 | MyASTVisitor visitor; 44 | void HandleTranslationUnit(ASTContext &context) 45 | { 46 | visitor.setContext(context); 47 | visitor.TraverseDecl(context.getTranslationUnitDecl()); 48 | } 49 | }; 50 | class MyASTAction: public PluginASTAction 51 | { 52 | public: 53 | unique_ptr < ASTConsumer > CreateASTConsumer(CompilerInstance & Compiler, StringRef InFile) { 54 | return unique_ptr < MyASTConsumer > (new MyASTConsumer); 55 | } 56 | bool ParseArgs(const CompilerInstance &CI, const std::vector < std::string >& args) 57 | { 58 | return true; 59 | } 60 | }; 61 | } 62 | static clang::FrontendPluginRegistry::Add 63 | < MyPlugin::MyASTAction > X("MyPlugin", 64 | "MyPlugin desc"); 65 | 66 | -------------------------------------------------------------------------------- /llvm_note/class3/note.md: -------------------------------------------------------------------------------- 1 | # 第三课 clang插件编写 2 | * https://github.com/llvm-mirror/llvm 3 | ``` 4 | mkdir llvm_build; cd llvm_build 5 | cmake -G Xcode ../llvm -DCMAKE_BUILD_TYPE:STRING=MinSizeRel 6 | 7 | ``` 8 | * github clone 9 | ``` 10 | git clone -b release_90 https://github.com/llvm-mirror/llvm.git 11 | git clone -b release_90 https://github.com/llvm-mirror/clang.git llvm/tools/clang 12 | git clone -b release_90 https://github.com/llvm-mirror/compiler-rt.git llvm/projects/compiler-rt 13 | git clone -b release_90 https://github.com/llvm-mirror/clang-tools-extra.git llvm/tools/clang/extra 14 | 15 | ``` 16 | * github error 17 | ``` 18 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 19 | ➜ git config --global user.name haidragon [2020-01-03 16:04:08] 20 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 21 | ➜ git config --global user.email 18684797674@163.com [2020-01-03 16:04:22] 22 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 23 | ➜ ssh-keygen -t rsa -C 18684797674@163.com [2020-01-03 16:04:34] 24 | Generating public/private rsa key pair. 25 | Enter file in which to save the key (/Users/haidragon/.ssh/id_rsa): 26 | Enter passphrase (empty for no passphrase): 27 | Enter same passphrase again: 28 | Your identification has been saved in /Users/haidragon/.ssh/id_rsa. 29 | Your public key has been saved in /Users/haidragon/.ssh/id_rsa.pub. 30 | The key fingerprint is: 31 | SHA256:fshDbkDn/A4F9+ih912uryfPINLFqzDvOWl7++BvZPo 18684797674@163.com 32 | The key's randomart image is: 33 | +---[RSA 2048]----+ 34 | | | 35 | | | 36 | | . o . | 37 | | . + o o . | 38 | | . S + . o | 39 | | * * o . .o| 40 | | X O o.++.| 41 | | . * *+*+*o| 42 | | .oB+*&E| 43 | +----[SHA256]-----+ 44 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 45 | ➜ open /Users/haidragon/.ssh/id_rsa.pub [2020-01-03 16:05:06] 46 | No application knows how to open /Users/haidragon/.ssh/id_rsa.pub. 47 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 48 | ➜ open -n Xcode /Users/haidragon/.ssh/id_rsa.pub [2020-01-03 16:06:12] 49 | The file /Users/haidragon/Xcode does not exist. 50 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 51 | ➜ open -a Xcode /Users/haidragon/.ssh/id_rsa.pub [2020-01-03 16:06:37] 52 | [haidragon@haidragondeMacBook-Pro]: /Users/haidragon 53 | ➜ git clone -b release_90 git@github.com:llvm-mirror/llvm.git llvm [2020-01-03 16:06:46] 54 | fatal: destination path 'llvm' already exists and is not an empty directory. 55 | ``` 56 | * 插件 57 | ``` 58 | ./clang++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Xclang -load -Xclang ./MyPlugin.dylib -Xclang -add-plugin -Xclang MyPlugin -c /Users/haidragon/Desktop/llvm_note/class3/testcpp/testcpp/main.cpp 59 | ``` 60 | * 参考 61 | * https://www.cnblogs.com/yun6853992/p/9348540.html 62 | * https://blog.csdn.net/qq_43768946/article/details/90411154 63 | * https://blog.csdn.net/taishanduba/article/details/57507176 64 | 65 | 66 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/AnnotateFunctions/AnnotateFunctions.cpp: -------------------------------------------------------------------------------- 1 | //===- AnnotateFunctions.cpp ----------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // Example clang plugin which adds an annotation to every function in 10 | // translation units that start with #pragma enable_annotate. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "clang/Frontend/FrontendPluginRegistry.h" 15 | #include "clang/AST/AST.h" 16 | #include "clang/AST/ASTConsumer.h" 17 | #include "clang/Lex/Preprocessor.h" 18 | #include "clang/Lex/LexDiagnostic.h" 19 | using namespace clang; 20 | 21 | namespace { 22 | 23 | static bool EnableAnnotate = false; 24 | static bool HandledDecl = false; 25 | 26 | class AnnotateFunctionsConsumer : public ASTConsumer { 27 | public: 28 | bool HandleTopLevelDecl(DeclGroupRef DG) override { 29 | HandledDecl = true; 30 | if (!EnableAnnotate) 31 | return true; 32 | for (auto D : DG) 33 | if (FunctionDecl *FD = dyn_cast(D)) 34 | FD->addAttr(AnnotateAttr::CreateImplicit(FD->getASTContext(), 35 | "example_annotation")); 36 | return true; 37 | } 38 | }; 39 | 40 | class AnnotateFunctionsAction : public PluginASTAction { 41 | public: 42 | std::unique_ptr CreateASTConsumer(CompilerInstance &CI, 43 | llvm::StringRef) override { 44 | return llvm::make_unique(); 45 | } 46 | 47 | bool ParseArgs(const CompilerInstance &CI, 48 | const std::vector &args) override { 49 | return true; 50 | } 51 | 52 | PluginASTAction::ActionType getActionType() override { 53 | return AddBeforeMainAction; 54 | } 55 | }; 56 | 57 | class PragmaAnnotateHandler : public PragmaHandler { 58 | public: 59 | PragmaAnnotateHandler() : PragmaHandler("enable_annotate") { } 60 | 61 | void HandlePragma(Preprocessor &PP, PragmaIntroducer Introducer, 62 | Token &PragmaTok) override { 63 | 64 | Token Tok; 65 | PP.LexUnexpandedToken(Tok); 66 | if (Tok.isNot(tok::eod)) 67 | PP.Diag(Tok, diag::ext_pp_extra_tokens_at_eol) << "pragma"; 68 | 69 | if (HandledDecl) { 70 | DiagnosticsEngine &D = PP.getDiagnostics(); 71 | unsigned ID = D.getCustomDiagID( 72 | DiagnosticsEngine::Error, 73 | "#pragma enable_annotate not allowed after declarations"); 74 | D.Report(PragmaTok.getLocation(), ID); 75 | } 76 | 77 | EnableAnnotate = true; 78 | } 79 | }; 80 | 81 | } 82 | 83 | static FrontendPluginRegistry::Add 84 | X("annotate-fns", "annotate functions"); 85 | 86 | static PragmaHandlerRegistry::Add 87 | Y("enable_annotate","enable annotation"); 88 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/AnnotateFunctions/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_library(AnnotateFunctions MODULE AnnotateFunctions.cpp PLUGIN_TOOL clang) 2 | 3 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 4 | set(LLVM_LINK_COMPONENTS 5 | Support 6 | ) 7 | clang_target_link_libraries(AnnotateFunctions PRIVATE 8 | clangAST 9 | clangBasic 10 | clangFrontend 11 | clangLex 12 | ) 13 | endif() 14 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | if(NOT CLANG_BUILD_EXAMPLES) 2 | set_property(DIRECTORY PROPERTY EXCLUDE_FROM_ALL ON) 3 | set(EXCLUDE_FROM_ALL ON) 4 | endif() 5 | 6 | add_subdirectory(clang-interpreter) 7 | add_subdirectory(PrintFunctionNames) 8 | add_subdirectory(AnnotateFunctions) 9 | add_subdirectory(myplugin) 10 | add_subdirectory(CodeChecker) 11 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/CodeChecker/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_library(CodeChecker MODULE CodeChecker.cpp PLUGIN_TOOL clang) 2 | 3 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 4 | target_link_libraries(CodeChecker PRIVATE 5 | clangAST 6 | clangBasic 7 | clangFrontend 8 | clangLex 9 | LLVMSupport 10 | ) 11 | endif() 12 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/CodeChecker/CodeChecker.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "clang/Frontend/FrontendPluginRegistry.h" 10 | #include "clang/Rewrite/Core/Rewriter.h" 11 | #include "clang/AST/AST.h" 12 | #include "clang/AST/ASTConsumer.h" 13 | #include "clang/AST/RecursiveASTVisitor.h" 14 | #include "clang/Frontend/CompilerInstance.h" 15 | #include "clang/Sema/Sema.h" 16 | 17 | using namespace clang; 18 | using namespace std; 19 | 20 | namespace 21 | { 22 | static vector split(const string &s, char delim) 23 | { 24 | vector elems; 25 | stringstream ss; 26 | ss.str(s); 27 | string item; 28 | while (getline(ss, item, delim)) { 29 | elems.push_back(item); 30 | } 31 | return elems; 32 | } 33 | 34 | class CodeVisitor : public RecursiveASTVisitor 35 | { 36 | private: 37 | CompilerInstance &Instance; 38 | ASTContext *Context; 39 | 40 | public: 41 | 42 | void setASTContext (ASTContext &context) 43 | { 44 | this -> Context = &context; 45 | } 46 | 47 | private: 48 | 49 | /** 50 | 判断是否为用户源码 51 | 52 | @param decl 声明 53 | @return true 为用户源码,false 非用户源码 54 | */ 55 | bool isUserSourceCode (Decl *decl) 56 | { 57 | string filename = Instance.getSourceManager().getFilename(decl->getSourceRange().getBegin()).str(); 58 | 59 | if (filename.empty()) 60 | return false; 61 | 62 | //非XCode中的源码都认为是用户源码 63 | if(filename.find("/Applications/Xcode.app/") == 0) 64 | return false; 65 | 66 | return true; 67 | } 68 | 69 | /** 70 | 检测类名是否存在小写开头 71 | 72 | @param decl 类声明 73 | */ 74 | void checkClassNameForLowercaseName(ObjCInterfaceDecl *decl) 75 | { 76 | StringRef className = decl -> getName(); 77 | 78 | //类名称必须以大写字母开头 79 | char c = className[0]; 80 | if (isLowercase(c)) 81 | { 82 | //修正提示 83 | std::string tempName = className; 84 | tempName[0] = toUppercase(c); 85 | StringRef replacement(tempName); 86 | SourceLocation nameStart = decl->getLocation(); 87 | SourceLocation nameEnd = nameStart.getLocWithOffset(className.size() - 1); 88 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 89 | 90 | //报告警告 91 | DiagnosticsEngine &D = Instance.getDiagnostics(); 92 | int diagID = D.getCustomDiagID(DiagnosticsEngine::Error, "Class name should not start with lowercase letter"); 93 | SourceLocation location = decl->getLocation(); 94 | D.Report(location, diagID).AddFixItHint(fixItHint); 95 | } 96 | } 97 | 98 | /** 99 | 检测类名是否包含下划线 100 | 101 | @param decl 类声明 102 | */ 103 | void checkClassNameForUnderscoreInName(ObjCInterfaceDecl *decl) 104 | { 105 | StringRef className = decl -> getName(); 106 | 107 | //类名不能包含下划线 108 | size_t underscorePos = className.find('_'); 109 | if (underscorePos != StringRef::npos) 110 | { 111 | //修正提示 112 | std::string tempName = className; 113 | std::string::iterator end_pos = std::remove(tempName.begin(), tempName.end(), '_'); 114 | tempName.erase(end_pos, tempName.end()); 115 | StringRef replacement(tempName); 116 | SourceLocation nameStart = decl->getLocation(); 117 | SourceLocation nameEnd = nameStart.getLocWithOffset(className.size() - 1); 118 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 119 | 120 | //报告错误 121 | DiagnosticsEngine &diagEngine = Instance.getDiagnostics(); 122 | unsigned diagID = diagEngine.getCustomDiagID(DiagnosticsEngine::Error, "Class name with `_` forbidden"); 123 | SourceLocation location = decl->getLocation().getLocWithOffset(underscorePos); 124 | diagEngine.Report(location, diagID).AddFixItHint(fixItHint); 125 | } 126 | } 127 | 128 | 129 | /** 130 | 检测方法名是否存在大写开头 131 | 132 | @param decl 方法声明 133 | */ 134 | void checkMethodNameForUppercaseName(ObjCMethodDecl *decl) 135 | { 136 | //检查名称的每部分,都不允许以大写字母开头 137 | Selector sel = decl -> getSelector(); 138 | int selectorPartCount = decl -> getNumSelectorLocs(); 139 | for (int i = 0; i < selectorPartCount; i++) 140 | { 141 | StringRef selName = sel.getNameForSlot(i); 142 | char c = selName[0]; 143 | if (isUppercase(c)) 144 | { 145 | //修正提示 146 | std::string tempName = selName; 147 | tempName[0] = toLowercase(c); 148 | StringRef replacement(tempName); 149 | SourceLocation nameStart = decl -> getSelectorLoc(i); 150 | SourceLocation nameEnd = nameStart.getLocWithOffset(selName.size() - 1); 151 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 152 | 153 | //报告警告 154 | DiagnosticsEngine &D = Instance.getDiagnostics(); 155 | int diagID = D.getCustomDiagID(DiagnosticsEngine::Error, "Selector name should not start with uppercase letter"); 156 | SourceLocation location = decl->getLocation(); 157 | D.Report(location, diagID).AddFixItHint(fixItHint); 158 | } 159 | } 160 | } 161 | 162 | /** 163 | 检测方法中定义的参数名称是否存在大写开头 164 | 165 | @param decl 方法声明 166 | */ 167 | void checkMethodParamsNameForUppercaseName(ObjCMethodDecl *decl) 168 | { 169 | for (ObjCMethodDecl::param_iterator it = decl -> param_begin(); it != decl -> param_end(); it++) 170 | { 171 | ParmVarDecl *parmVarDecl = *it; 172 | StringRef name = parmVarDecl -> getName(); 173 | char c = name[0]; 174 | if (isUppercase(c)) 175 | { 176 | //修正提示 177 | std::string tempName = name; 178 | tempName[0] = toLowercase(c); 179 | StringRef replacement(tempName); 180 | SourceLocation nameStart = parmVarDecl -> getLocation(); 181 | SourceLocation nameEnd = nameStart.getLocWithOffset(name.size() - 1); 182 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 183 | 184 | //报告警告 185 | DiagnosticsEngine &D = Instance.getDiagnostics(); 186 | int diagID = D.getCustomDiagID(DiagnosticsEngine::Warning, "Selector's param name should not start with uppercase letter"); 187 | SourceLocation location = decl->getLocation(); 188 | D.Report(location, diagID).AddFixItHint(fixItHint); 189 | } 190 | } 191 | } 192 | 193 | /** 194 | 检测方法实现是否超过500行代码 195 | 196 | @param decl 方法声明 197 | */ 198 | void checkMethodBodyForOver500Lines(ObjCMethodDecl *decl) 199 | { 200 | if (decl -> hasBody()) 201 | { 202 | //存在方法体 203 | Stmt *methodBody = decl -> getBody(); 204 | 205 | string srcCode; 206 | srcCode.assign(Instance.getSourceManager().getCharacterData(methodBody->getSourceRange().getBegin()), 207 | methodBody->getSourceRange().getEnd().getRawEncoding() - methodBody->getSourceRange().getBegin().getRawEncoding() + 1); 208 | vector lines = split(srcCode, '\n'); 209 | if(lines.size() > 500) 210 | { 211 | DiagnosticsEngine &D = Instance.getDiagnostics(); 212 | unsigned diagID = D.getCustomDiagID(DiagnosticsEngine::Warning, "Single method should not have body over 500 lines"); 213 | D.Report(decl -> getSourceRange().getBegin(), diagID); 214 | } 215 | } 216 | } 217 | 218 | /** 219 | 检测属性名是否存在大写开头 220 | 221 | @param decl 属性声明 222 | */ 223 | void checkPropertyNameForUppercaseName(ObjCPropertyDecl *decl) 224 | { 225 | bool checkUppercaseNameIndex = 0; 226 | 227 | StringRef name = decl -> getName(); 228 | 229 | if (name.find('_') == 0) 230 | { 231 | //表示以下划线开头 232 | checkUppercaseNameIndex = 1; 233 | } 234 | 235 | //名称必须以小写字母开头 236 | char c = name[checkUppercaseNameIndex]; 237 | if (isUppercase(c)) 238 | { 239 | //修正提示 240 | std::string tempName = name; 241 | tempName[checkUppercaseNameIndex] = toLowercase(c); 242 | StringRef replacement(tempName); 243 | SourceLocation nameStart = decl->getLocation(); 244 | SourceLocation nameEnd = nameStart.getLocWithOffset(name.size() - 1); 245 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 246 | 247 | //报告错误 248 | DiagnosticsEngine &D = Instance.getDiagnostics(); 249 | int diagID = D.getCustomDiagID(DiagnosticsEngine::Error, "Property name should not start with uppercase letter"); 250 | SourceLocation location = decl->getLocation(); 251 | D.Report(location, diagID).AddFixItHint(fixItHint); 252 | } 253 | } 254 | 255 | /** 256 | 检测属性名是否包含下划线 257 | 258 | @param decl 属性声明 259 | */ 260 | void checkPropertyNameForUnderscoreInName(ObjCPropertyDecl *decl) 261 | { 262 | StringRef name = decl -> getName(); 263 | 264 | if (name.size() == 1) 265 | { 266 | //不需要检测 267 | return; 268 | } 269 | 270 | //类名不能包含下划线 271 | size_t underscorePos = name.find('_', 1); 272 | if (underscorePos != StringRef::npos) 273 | { 274 | //修正提示 275 | std::string tempName = name; 276 | std::string::iterator end_pos = std::remove(tempName.begin() + 1, tempName.end(), '_'); 277 | tempName.erase(end_pos, tempName.end()); 278 | StringRef replacement(tempName); 279 | SourceLocation nameStart = decl->getLocation(); 280 | SourceLocation nameEnd = nameStart.getLocWithOffset(name.size() - 1); 281 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 282 | 283 | //报告错误 284 | DiagnosticsEngine &diagEngine = Instance.getDiagnostics(); 285 | unsigned diagID = diagEngine.getCustomDiagID(DiagnosticsEngine::Error, "Property name with `_` forbidden"); 286 | SourceLocation location = decl->getLocation().getLocWithOffset(underscorePos); 287 | diagEngine.Report(location, diagID).AddFixItHint(fixItHint); 288 | } 289 | } 290 | 291 | 292 | /** 293 | 检测委托属性是否有使用weak修饰 294 | 295 | @param decl 属性声明 296 | */ 297 | void checkDelegatePropertyForUsageWeak (ObjCPropertyDecl *decl) 298 | { 299 | QualType type = decl -> getType(); 300 | StringRef typeStr = type.getAsString(); 301 | 302 | //Delegate 303 | if(typeStr.find("<") != string::npos && typeStr.find(">") != string::npos) 304 | { 305 | ObjCPropertyDecl::PropertyAttributeKind attrKind = decl -> getPropertyAttributes(); 306 | 307 | string typeSrcCode; 308 | typeSrcCode.assign(Instance.getSourceManager().getCharacterData(decl -> getSourceRange().getBegin()), 309 | decl -> getSourceRange().getEnd().getRawEncoding() - decl -> getSourceRange().getBegin().getRawEncoding()); 310 | 311 | if(!(attrKind & ObjCPropertyDecl::OBJC_PR_weak)) 312 | { 313 | DiagnosticsEngine &diagEngine = Instance.getDiagnostics(); 314 | unsigned diagID = diagEngine.getCustomDiagID(DiagnosticsEngine::Warning, "Delegate should be declared as weak."); 315 | diagEngine.Report(decl -> getLocation(), diagID); 316 | } 317 | } 318 | } 319 | 320 | 321 | /** 322 | 检测常量名称是否存在小写开头 323 | 324 | @param decl 常量声明 325 | */ 326 | void checkConstantNameForLowercaseName (VarDecl *decl) 327 | { 328 | StringRef className = decl -> getName(); 329 | 330 | //类名称必须以大写字母开头 331 | char c = className[0]; 332 | if (isLowercase(c)) 333 | { 334 | //修正提示 335 | std::string tempName = className; 336 | tempName[0] = toUppercase(c); 337 | StringRef replacement(tempName); 338 | SourceLocation nameStart = decl->getLocation(); 339 | SourceLocation nameEnd = nameStart.getLocWithOffset(className.size() - 1); 340 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 341 | 342 | //报告警告 343 | DiagnosticsEngine &D = Instance.getDiagnostics(); 344 | int diagID = D.getCustomDiagID(DiagnosticsEngine::Warning, "Constant name should not start with lowercase letter"); 345 | SourceLocation location = decl->getLocation(); 346 | D.Report(location, diagID).AddFixItHint(fixItHint); 347 | } 348 | } 349 | 350 | 351 | /** 352 | 检测变量名称是否存在大写开头 353 | 354 | @param decl 变量声明 355 | */ 356 | void checkVarNameForUppercaseName (VarDecl *decl) 357 | { 358 | StringRef className = decl -> getName(); 359 | 360 | //类名称必须以大写字母开头 361 | char c = className[0]; 362 | if (isUppercase(c)) 363 | { 364 | //修正提示 365 | std::string tempName = className; 366 | tempName[0] = toLowercase(c); 367 | StringRef replacement(tempName); 368 | SourceLocation nameStart = decl->getLocation(); 369 | SourceLocation nameEnd = nameStart.getLocWithOffset(className.size() - 1); 370 | FixItHint fixItHint = FixItHint::CreateReplacement(SourceRange(nameStart, nameEnd), replacement); 371 | 372 | //报告警告 373 | DiagnosticsEngine &D = Instance.getDiagnostics(); 374 | int diagID = D.getCustomDiagID(DiagnosticsEngine::Warning, "Variable name should not start with uppercase letter"); 375 | SourceLocation location = decl->getLocation(); 376 | D.Report(location, diagID).AddFixItHint(fixItHint); 377 | } 378 | } 379 | 380 | 381 | /** 382 | 检测变量名称 383 | 384 | @param decl 变量声明 385 | */ 386 | void checkVarName(VarDecl *decl) 387 | { 388 | if (decl -> isStaticLocal()) 389 | { 390 | //静态变量 391 | 392 | if (decl -> getType().isConstant(*this -> Context)) 393 | { 394 | //常量 395 | checkConstantNameForLowercaseName(decl); 396 | } 397 | else 398 | { 399 | //非常量 400 | checkVarNameForUppercaseName(decl); 401 | } 402 | 403 | } 404 | else if (decl -> isLocalVarDecl()) 405 | { 406 | //本地变量 407 | if (decl -> getType().isConstant(*this -> Context)) 408 | { 409 | //常量 410 | checkConstantNameForLowercaseName(decl); 411 | } 412 | else 413 | { 414 | //非常量 415 | checkVarNameForUppercaseName(decl); 416 | } 417 | } 418 | else if (decl -> isFileVarDecl()) 419 | { 420 | //文件定义变量 421 | if (decl -> getType().isConstant(*this -> Context)) 422 | { 423 | //常量 424 | checkConstantNameForLowercaseName(decl); 425 | } 426 | else 427 | { 428 | //非常量 429 | checkVarNameForUppercaseName(decl); 430 | } 431 | } 432 | } 433 | 434 | public: 435 | 436 | CodeVisitor (CompilerInstance &Instance) 437 | :Instance(Instance) 438 | { 439 | 440 | } 441 | 442 | /** 443 | 观察ObjC的类声明 444 | 445 | @param declaration 声明对象 446 | @return 返回 447 | */ 448 | bool VisitObjCInterfaceDecl(ObjCInterfaceDecl *declaration) 449 | { 450 | if (isUserSourceCode(declaration)) 451 | { 452 | checkClassNameForLowercaseName(declaration); 453 | checkClassNameForUnderscoreInName(declaration); 454 | } 455 | 456 | return true; 457 | } 458 | 459 | 460 | /** 461 | 观察类方法声明 462 | 463 | @param declaration 声明对象 464 | @return 返回 465 | */ 466 | bool VisitObjCMethodDecl(ObjCMethodDecl *declaration) 467 | { 468 | if (isUserSourceCode(declaration)) 469 | { 470 | checkMethodNameForUppercaseName(declaration); 471 | checkMethodParamsNameForUppercaseName(declaration); 472 | checkMethodBodyForOver500Lines(declaration); 473 | } 474 | 475 | return true; 476 | } 477 | 478 | 479 | /** 480 | 观察类属性声明 481 | 482 | @param declaration 声明对象 483 | @return 返回 484 | */ 485 | bool VisitObjCPropertyDecl(ObjCPropertyDecl *declaration) 486 | { 487 | if (isUserSourceCode(declaration)) 488 | { 489 | checkPropertyNameForUppercaseName(declaration); 490 | checkPropertyNameForUnderscoreInName(declaration); 491 | checkDelegatePropertyForUsageWeak(declaration); 492 | } 493 | 494 | return true; 495 | } 496 | 497 | /** 498 | 观察变量声明 499 | 500 | @param declaration 声明对象 501 | @return 返回 502 | */ 503 | bool VisitVarDecl(VarDecl *declaration) 504 | { 505 | if (isUserSourceCode(declaration)) 506 | { 507 | checkVarName(declaration); 508 | } 509 | 510 | return true; 511 | } 512 | 513 | /** 514 | 观察枚举常量声明 515 | 516 | @param declaration 声明对象 517 | @return 返回 518 | */ 519 | // bool VisitEnumConstantDecl (EnumConstantDecl *declaration) 520 | // { 521 | // return true; 522 | // } 523 | }; 524 | 525 | class CodeConsumer : public ASTConsumer 526 | { 527 | CompilerInstance &Instance; 528 | std::set ParsedTemplates; 529 | public: 530 | CodeConsumer(CompilerInstance &Instance, 531 | std::set ParsedTemplates) 532 | : Instance(Instance), ParsedTemplates(ParsedTemplates), visitor(Instance) 533 | { 534 | 535 | } 536 | 537 | bool HandleTopLevelDecl(DeclGroupRef DG) override 538 | { 539 | return true; 540 | } 541 | 542 | void HandleTranslationUnit(ASTContext& context) override 543 | { 544 | visitor.setASTContext(context); 545 | visitor.TraverseDecl(context.getTranslationUnitDecl()); 546 | } 547 | 548 | private: 549 | CodeVisitor visitor; 550 | }; 551 | 552 | class CodeASTAction : public PluginASTAction 553 | { 554 | std::set ParsedTemplates; 555 | protected: 556 | std::unique_ptr CreateASTConsumer(CompilerInstance &CI, 557 | llvm::StringRef) override 558 | { 559 | return llvm::make_unique(CI, ParsedTemplates); 560 | } 561 | 562 | bool ParseArgs(const CompilerInstance &CI, 563 | const std::vector &args) override 564 | { 565 | // DiagnosticsEngine &D = CI.getDiagnostics(); 566 | // D.Report(D.getCustomDiagID(DiagnosticsEngine::Error, 567 | // "My plugin Started...")); 568 | 569 | return true; 570 | } 571 | }; 572 | } 573 | 574 | static clang::FrontendPluginRegistry::Add 575 | X("CodeChecker", "Code Checker"); 576 | 577 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/PrintFunctionNames/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # If we don't need RTTI or EH, there's no reason to export anything 2 | # from the plugin. 3 | if( NOT MSVC ) # MSVC mangles symbols differently, and 4 | # PrintFunctionNames.export contains C++ symbols. 5 | if( NOT LLVM_REQUIRES_RTTI ) 6 | if( NOT LLVM_REQUIRES_EH ) 7 | set(LLVM_EXPORTED_SYMBOL_FILE ${CMAKE_CURRENT_SOURCE_DIR}/PrintFunctionNames.exports) 8 | endif() 9 | endif() 10 | endif() 11 | 12 | add_llvm_library(PrintFunctionNames MODULE PrintFunctionNames.cpp PLUGIN_TOOL clang) 13 | 14 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 15 | set(LLVM_LINK_COMPONENTS 16 | Support 17 | ) 18 | clang_target_link_libraries(PrintFunctionNames PRIVATE 19 | clangAST 20 | clangBasic 21 | clangFrontend 22 | ) 23 | endif() 24 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/PrintFunctionNames/PrintFunctionNames.cpp: -------------------------------------------------------------------------------- 1 | //===- PrintFunctionNames.cpp ---------------------------------------------===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | // 9 | // Example clang plugin which simply prints the names of all the top-level decls 10 | // in the input file. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #include "clang/Frontend/FrontendPluginRegistry.h" 15 | #include "clang/AST/AST.h" 16 | #include "clang/AST/ASTConsumer.h" 17 | #include "clang/AST/RecursiveASTVisitor.h" 18 | #include "clang/Frontend/CompilerInstance.h" 19 | #include "clang/Sema/Sema.h" 20 | #include "llvm/Support/raw_ostream.h" 21 | using namespace clang; 22 | 23 | namespace { 24 | 25 | class PrintFunctionsConsumer : public ASTConsumer { 26 | CompilerInstance &Instance; 27 | std::set ParsedTemplates; 28 | 29 | public: 30 | PrintFunctionsConsumer(CompilerInstance &Instance, 31 | std::set ParsedTemplates) 32 | : Instance(Instance), ParsedTemplates(ParsedTemplates) {} 33 | 34 | bool HandleTopLevelDecl(DeclGroupRef DG) override { 35 | for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) { 36 | const Decl *D = *i; 37 | if (const NamedDecl *ND = dyn_cast(D)) 38 | llvm::errs() << "top-level-decl: \"" << ND->getNameAsString() << "\"\n"; 39 | } 40 | 41 | return true; 42 | } 43 | 44 | void HandleTranslationUnit(ASTContext& context) override { 45 | if (!Instance.getLangOpts().DelayedTemplateParsing) 46 | return; 47 | 48 | // This demonstrates how to force instantiation of some templates in 49 | // -fdelayed-template-parsing mode. (Note: Doing this unconditionally for 50 | // all templates is similar to not using -fdelayed-template-parsig in the 51 | // first place.) 52 | // The advantage of doing this in HandleTranslationUnit() is that all 53 | // codegen (when using -add-plugin) is completely finished and this can't 54 | // affect the compiler output. 55 | struct Visitor : public RecursiveASTVisitor { 56 | const std::set &ParsedTemplates; 57 | Visitor(const std::set &ParsedTemplates) 58 | : ParsedTemplates(ParsedTemplates) {} 59 | bool VisitFunctionDecl(FunctionDecl *FD) { 60 | if (FD->isLateTemplateParsed() && 61 | ParsedTemplates.count(FD->getNameAsString())) 62 | LateParsedDecls.insert(FD); 63 | return true; 64 | } 65 | 66 | std::set LateParsedDecls; 67 | } v(ParsedTemplates); 68 | v.TraverseDecl(context.getTranslationUnitDecl()); 69 | clang::Sema &sema = Instance.getSema(); 70 | for (const FunctionDecl *FD : v.LateParsedDecls) { 71 | clang::LateParsedTemplate &LPT = 72 | *sema.LateParsedTemplateMap.find(FD)->second; 73 | sema.LateTemplateParser(sema.OpaqueParser, LPT); 74 | llvm::errs() << "late-parsed-decl: \"" << FD->getNameAsString() << "\"\n"; 75 | } 76 | } 77 | }; 78 | 79 | class PrintFunctionNamesAction : public PluginASTAction { 80 | std::set ParsedTemplates; 81 | protected: 82 | std::unique_ptr CreateASTConsumer(CompilerInstance &CI, 83 | llvm::StringRef) override { 84 | return llvm::make_unique(CI, ParsedTemplates); 85 | } 86 | 87 | bool ParseArgs(const CompilerInstance &CI, 88 | const std::vector &args) override { 89 | for (unsigned i = 0, e = args.size(); i != e; ++i) { 90 | llvm::errs() << "PrintFunctionNames arg = " << args[i] << "\n"; 91 | 92 | // Example error handling. 93 | DiagnosticsEngine &D = CI.getDiagnostics(); 94 | if (args[i] == "-an-error") { 95 | unsigned DiagID = D.getCustomDiagID(DiagnosticsEngine::Error, 96 | "invalid argument '%0'"); 97 | D.Report(DiagID) << args[i]; 98 | return false; 99 | } else if (args[i] == "-parse-template") { 100 | if (i + 1 >= e) { 101 | D.Report(D.getCustomDiagID(DiagnosticsEngine::Error, 102 | "missing -parse-template argument")); 103 | return false; 104 | } 105 | ++i; 106 | ParsedTemplates.insert(args[i]); 107 | } 108 | } 109 | if (!args.empty() && args[0] == "help") 110 | PrintHelp(llvm::errs()); 111 | 112 | return true; 113 | } 114 | void PrintHelp(llvm::raw_ostream& ros) { 115 | ros << "Help for PrintFunctionNames plugin goes here\n"; 116 | } 117 | 118 | }; 119 | 120 | } 121 | 122 | static FrontendPluginRegistry::Add 123 | X("print-fns", "print function names"); 124 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/PrintFunctionNames/README.txt: -------------------------------------------------------------------------------- 1 | This is a simple example demonstrating how to use clang's facility for 2 | providing AST consumers using a plugin. 3 | 4 | Build the plugin by running `make` in this directory. 5 | 6 | Once the plugin is built, you can run it using: 7 | -- 8 | Linux: 9 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns some-input-file.c 10 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns -plugin-arg-print-fns help -plugin-arg-print-fns --example-argument some-input-file.c 11 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.so -plugin print-fns -plugin-arg-print-fns -an-error some-input-file.c 12 | 13 | Mac: 14 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns some-input-file.c 15 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns -plugin-arg-print-fns help -plugin-arg-print-fns --example-argument some-input-file.c 16 | $ clang -cc1 -load ../../Debug+Asserts/lib/libPrintFunctionNames.dylib -plugin print-fns -plugin-arg-print-fns -an-error some-input-file.c 17 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/clang-interpreter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LLVM_LINK_COMPONENTS 2 | Core 3 | ExecutionEngine 4 | MC 5 | MCJIT 6 | Object 7 | OrcJit 8 | Option 9 | RuntimeDyld 10 | Support 11 | native 12 | ) 13 | 14 | add_clang_executable(clang-interpreter 15 | main.cpp 16 | ) 17 | 18 | add_dependencies(clang-interpreter 19 | clang-resource-headers 20 | ) 21 | 22 | clang_target_link_libraries(clang-interpreter 23 | PRIVATE 24 | clangBasic 25 | clangCodeGen 26 | clangDriver 27 | clangFrontend 28 | clangSerialization 29 | ) 30 | 31 | export_executable_symbols(clang-interpreter) 32 | 33 | if (MSVC) 34 | # Is this a CMake bug that even with export_executable_symbols, Windows 35 | # needs to explictly export the type_info vtable 36 | set_property(TARGET clang-interpreter 37 | APPEND_STRING PROPERTY LINK_FLAGS " /EXPORT:??_7type_info@@6B@") 38 | endif() 39 | 40 | function(clang_enable_exceptions TARGET) 41 | # Really have to jump through hoops to enable exception handling independent 42 | # of how LLVM is being built. 43 | if (NOT LLVM_REQUIRES_EH AND NOT LLVM_REQUIRES_RTTI) 44 | if (MSVC) 45 | # /EHs to allow throwing from extern "C" 46 | set(excptnExceptions_ON "/D _HAS_EXCEPTIONS=1 /EHs /wd4714") 47 | set(excptnExceptions_OFF "/D _HAS_EXCEPTIONS=0 /EHs-c-") 48 | set(excptnRTTI_ON "/GR") 49 | set(excptnRTTI_OFF "/GR-") 50 | set(excptnEHRTTIRegEx "(/EHs(-c-?)|_HAS_EXCEPTIONS=(0|1))") 51 | else() 52 | set(excptnExceptions_ON "-fexceptions") 53 | set(excptnExceptions_OFF "-fno-exceptions") 54 | set(excptnRTTI_ON "-frtti") 55 | set(excptnRTTI_OFF "-fno-rtti") 56 | set(excptnEHRTTIRegEx "-f(exceptions|no-exceptions)") 57 | endif() 58 | if (LLVM_REQUIRES_EH) 59 | set(excptnExceptions_DFLT ${excptnExceptions_ON}) 60 | else() 61 | set(excptnExceptions_DFLT ${excptnExceptions_OFF}) 62 | endif() 63 | if (LLVM_REQUIRES_RTTI) 64 | set(excptnRTTI_DFLT ${excptnRTTI_ON}) 65 | else() 66 | set(excptnRTTI_DFLT ${excptnRTTI_OFF}) 67 | endif() 68 | 69 | # Strip the exception & rtti flags from the target 70 | get_property(addedFlags TARGET ${TARGET} PROPERTY COMPILE_FLAGS) 71 | string(REGEX REPLACE ${excptnEHRTTIRegEx} "" editedFlags "${addedFlags}") 72 | string(REPLACE ${excptnRTTI_OFF} "" editedFlags "${editedFlags}") 73 | set_property(TARGET ${TARGET} PROPERTY COMPILE_FLAGS "${editedFlags}") 74 | 75 | get_property(addedFlags TARGET ${TARGET} PROPERTY COMPILE_DEFINITIONS) 76 | string(REGEX REPLACE ${excptnEHRTTIRegEx} "" editedFlags "${addedFlags}") 77 | string(REPLACE ${excptnRTTI_OFF} "" editedFlags "${editedFlags}") 78 | set_property(TARGET ${TARGET} PROPERTY COMPILE_DEFINITIONS "${editedFlags}") 79 | 80 | # Re-add the exception & rtti flags from LLVM 81 | set_property(SOURCE main.cpp APPEND_STRING PROPERTY COMPILE_FLAGS 82 | " ${excptnExceptions_DFLT} ${excptnRTTI_DFLT} ") 83 | set_property(SOURCE Manager.cpp APPEND_STRING PROPERTY COMPILE_FLAGS 84 | " ${excptnExceptions_DFLT} ${excptnRTTI_DFLT} ") 85 | 86 | # Invoke with exceptions & rtti 87 | set_property(SOURCE Invoke.cpp APPEND_STRING PROPERTY COMPILE_FLAGS 88 | " ${excptnExceptions_ON} ${excptnRTTI_ON} ") 89 | 90 | endif() 91 | endfunction(clang_enable_exceptions) 92 | 93 | clang_enable_exceptions(clang-interpreter) 94 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/clang-interpreter/README.txt: -------------------------------------------------------------------------------- 1 | This is an example of Clang based interpreter, for executing standalone C/C++ 2 | programs. 3 | 4 | It demonstrates the following features: 5 | 1. Parsing standard compiler command line arguments using the Driver library. 6 | 7 | 2. Constructing a Clang compiler instance, using the appropriate arguments 8 | derived in step #1. 9 | 10 | 3. Invoking the Clang compiler to lex, parse, syntax check, and then generate 11 | LLVM code. 12 | 13 | 4. Use the LLVM JIT functionality to execute the final module. 14 | 15 | 5. Intercepting a Win64 library call to allow throwing and catching exceptions 16 | in and from the JIT. 17 | 18 | The implementation has many limitations and is not designed to be a full fledged 19 | interpreter. It is designed to demonstrate a simple but functional use of the 20 | Clang compiler libraries. 21 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/clang-interpreter/Test.cxx: -------------------------------------------------------------------------------- 1 | //===-- examples/clang-interpreter/Test.cxx - Clang C Interpreter Example -===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | // Example throwing in and from the JIT (particularly on Win64). 10 | // 11 | // ./bin/clang-interpreter /tools/clang/examples/clang-interpreter/Test.cxx 12 | 13 | #include 14 | #include 15 | 16 | static void ThrowerAnError(const char* Name) { 17 | throw std::runtime_error(Name); 18 | } 19 | 20 | int main(int argc, const char** argv) { 21 | for (int I = 0; I < argc; ++I) 22 | printf("arg[%d]='%s'\n", I, argv[I]); 23 | 24 | try { 25 | ThrowerAnError("In JIT"); 26 | } catch (const std::exception& E) { 27 | printf("Caught: '%s'\n", E.what()); 28 | } catch (...) { 29 | printf("Unknown exception\n"); 30 | } 31 | ThrowerAnError("From JIT"); 32 | return 0; 33 | } 34 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/clang-interpreter/main.cpp: -------------------------------------------------------------------------------- 1 | //===-- examples/clang-interpreter/main.cpp - Clang C Interpreter Example -===// 2 | // 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | // See https://llvm.org/LICENSE.txt for license information. 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | // 7 | //===----------------------------------------------------------------------===// 8 | 9 | #include "clang/Basic/DiagnosticOptions.h" 10 | #include "clang/CodeGen/CodeGenAction.h" 11 | #include "clang/Driver/Compilation.h" 12 | #include "clang/Driver/Driver.h" 13 | #include "clang/Driver/Tool.h" 14 | #include "clang/Frontend/CompilerInstance.h" 15 | #include "clang/Frontend/CompilerInvocation.h" 16 | #include "clang/Frontend/FrontendDiagnostic.h" 17 | #include "clang/Frontend/TextDiagnosticPrinter.h" 18 | #include "llvm/ADT/SmallString.h" 19 | #include "llvm/ExecutionEngine/ExecutionEngine.h" 20 | #include "llvm/ExecutionEngine/Orc/CompileUtils.h" 21 | #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h" 22 | #include "llvm/ExecutionEngine/Orc/IRCompileLayer.h" 23 | #include "llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h" 24 | #include "llvm/ExecutionEngine/SectionMemoryManager.h" 25 | #include "llvm/IR/DataLayout.h" 26 | #include "llvm/IR/Mangler.h" 27 | #include "llvm/IR/Module.h" 28 | #include "llvm/Support/FileSystem.h" 29 | #include "llvm/Support/Host.h" 30 | #include "llvm/Support/ManagedStatic.h" 31 | #include "llvm/Support/Path.h" 32 | #include "llvm/Support/TargetSelect.h" 33 | #include "llvm/Support/raw_ostream.h" 34 | #include "llvm/Target/TargetMachine.h" 35 | 36 | using namespace clang; 37 | using namespace clang::driver; 38 | 39 | // This function isn't referenced outside its translation unit, but it 40 | // can't use the "static" keyword because its address is used for 41 | // GetMainExecutable (since some platforms don't support taking the 42 | // address of main, and some platforms can't implement GetMainExecutable 43 | // without being given the address of a function in the main executable). 44 | std::string GetExecutablePath(const char *Argv0, void *MainAddr) { 45 | return llvm::sys::fs::getMainExecutable(Argv0, MainAddr); 46 | } 47 | 48 | namespace llvm { 49 | namespace orc { 50 | 51 | class SimpleJIT { 52 | private: 53 | ExecutionSession ES; 54 | std::unique_ptr TM; 55 | const DataLayout DL; 56 | MangleAndInterner Mangle{ES, DL}; 57 | RTDyldObjectLinkingLayer ObjectLayer{ES, createMemMgr}; 58 | IRCompileLayer CompileLayer{ES, ObjectLayer, SimpleCompiler(*TM)}; 59 | 60 | static std::unique_ptr createMemMgr() { 61 | return llvm::make_unique(); 62 | } 63 | 64 | SimpleJIT(std::unique_ptr TM, DataLayout DL, 65 | DynamicLibrarySearchGenerator ProcessSymbolsGenerator) 66 | : TM(std::move(TM)), DL(std::move(DL)) { 67 | llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr); 68 | ES.getMainJITDylib().setGenerator(std::move(ProcessSymbolsGenerator)); 69 | } 70 | 71 | public: 72 | static Expected> Create() { 73 | auto JTMB = JITTargetMachineBuilder::detectHost(); 74 | if (!JTMB) 75 | return JTMB.takeError(); 76 | 77 | auto TM = JTMB->createTargetMachine(); 78 | if (!TM) 79 | return TM.takeError(); 80 | 81 | auto DL = (*TM)->createDataLayout(); 82 | 83 | auto ProcessSymbolsGenerator = 84 | DynamicLibrarySearchGenerator::GetForCurrentProcess( 85 | DL.getGlobalPrefix()); 86 | 87 | if (!ProcessSymbolsGenerator) 88 | return ProcessSymbolsGenerator.takeError(); 89 | 90 | return std::unique_ptr(new SimpleJIT( 91 | std::move(*TM), std::move(DL), std::move(*ProcessSymbolsGenerator))); 92 | } 93 | 94 | const TargetMachine &getTargetMachine() const { return *TM; } 95 | 96 | Error addModule(ThreadSafeModule M) { 97 | return CompileLayer.add(ES.getMainJITDylib(), std::move(M)); 98 | } 99 | 100 | Expected findSymbol(const StringRef &Name) { 101 | return ES.lookup({&ES.getMainJITDylib()}, Mangle(Name)); 102 | } 103 | 104 | Expected getSymbolAddress(const StringRef &Name) { 105 | auto Sym = findSymbol(Name); 106 | if (!Sym) 107 | return Sym.takeError(); 108 | return Sym->getAddress(); 109 | } 110 | }; 111 | 112 | } // end namespace orc 113 | } // end namespace llvm 114 | 115 | llvm::ExitOnError ExitOnErr; 116 | 117 | int main(int argc, const char **argv) { 118 | // This just needs to be some symbol in the binary; C++ doesn't 119 | // allow taking the address of ::main however. 120 | void *MainAddr = (void*) (intptr_t) GetExecutablePath; 121 | std::string Path = GetExecutablePath(argv[0], MainAddr); 122 | IntrusiveRefCntPtr DiagOpts = new DiagnosticOptions(); 123 | TextDiagnosticPrinter *DiagClient = 124 | new TextDiagnosticPrinter(llvm::errs(), &*DiagOpts); 125 | 126 | IntrusiveRefCntPtr DiagID(new DiagnosticIDs()); 127 | DiagnosticsEngine Diags(DiagID, &*DiagOpts, DiagClient); 128 | 129 | const std::string TripleStr = llvm::sys::getProcessTriple(); 130 | llvm::Triple T(TripleStr); 131 | 132 | // Use ELF on Windows-32 and MingW for now. 133 | #ifndef CLANG_INTERPRETER_COFF_FORMAT 134 | if (T.isOSBinFormatCOFF()) 135 | T.setObjectFormat(llvm::Triple::ELF); 136 | #endif 137 | 138 | ExitOnErr.setBanner("clang interpreter"); 139 | 140 | Driver TheDriver(Path, T.str(), Diags); 141 | TheDriver.setTitle("clang interpreter"); 142 | TheDriver.setCheckInputsExist(false); 143 | 144 | // FIXME: This is a hack to try to force the driver to do something we can 145 | // recognize. We need to extend the driver library to support this use model 146 | // (basically, exactly one input, and the operation mode is hard wired). 147 | SmallVector Args(argv, argv + argc); 148 | Args.push_back("-fsyntax-only"); 149 | std::unique_ptr C(TheDriver.BuildCompilation(Args)); 150 | if (!C) 151 | return 0; 152 | 153 | // FIXME: This is copied from ASTUnit.cpp; simplify and eliminate. 154 | 155 | // We expect to get back exactly one command job, if we didn't something 156 | // failed. Extract that job from the compilation. 157 | const driver::JobList &Jobs = C->getJobs(); 158 | if (Jobs.size() != 1 || !isa(*Jobs.begin())) { 159 | SmallString<256> Msg; 160 | llvm::raw_svector_ostream OS(Msg); 161 | Jobs.Print(OS, "; ", true); 162 | Diags.Report(diag::err_fe_expected_compiler_job) << OS.str(); 163 | return 1; 164 | } 165 | 166 | const driver::Command &Cmd = cast(*Jobs.begin()); 167 | if (llvm::StringRef(Cmd.getCreator().getName()) != "clang") { 168 | Diags.Report(diag::err_fe_expected_clang_command); 169 | return 1; 170 | } 171 | 172 | // Initialize a compiler invocation object from the clang (-cc1) arguments. 173 | const llvm::opt::ArgStringList &CCArgs = Cmd.getArguments(); 174 | std::unique_ptr CI(new CompilerInvocation); 175 | CompilerInvocation::CreateFromArgs(*CI, 176 | const_cast(CCArgs.data()), 177 | const_cast(CCArgs.data()) + 178 | CCArgs.size(), 179 | Diags); 180 | 181 | // Show the invocation, with -v. 182 | if (CI->getHeaderSearchOpts().Verbose) { 183 | llvm::errs() << "clang invocation:\n"; 184 | Jobs.Print(llvm::errs(), "\n", true); 185 | llvm::errs() << "\n"; 186 | } 187 | 188 | // FIXME: This is copied from cc1_main.cpp; simplify and eliminate. 189 | 190 | // Create a compiler instance to handle the actual work. 191 | CompilerInstance Clang; 192 | Clang.setInvocation(std::move(CI)); 193 | 194 | // Create the compilers actual diagnostics engine. 195 | Clang.createDiagnostics(); 196 | if (!Clang.hasDiagnostics()) 197 | return 1; 198 | 199 | // Infer the builtin include path if unspecified. 200 | if (Clang.getHeaderSearchOpts().UseBuiltinIncludes && 201 | Clang.getHeaderSearchOpts().ResourceDir.empty()) 202 | Clang.getHeaderSearchOpts().ResourceDir = 203 | CompilerInvocation::GetResourcesPath(argv[0], MainAddr); 204 | 205 | // Create and execute the frontend to generate an LLVM bitcode module. 206 | std::unique_ptr Act(new EmitLLVMOnlyAction()); 207 | if (!Clang.ExecuteAction(*Act)) 208 | return 1; 209 | 210 | llvm::InitializeNativeTarget(); 211 | llvm::InitializeNativeTargetAsmPrinter(); 212 | 213 | int Res = 255; 214 | std::unique_ptr Ctx(Act->takeLLVMContext()); 215 | std::unique_ptr Module = Act->takeModule(); 216 | 217 | if (Module) { 218 | auto J = ExitOnErr(llvm::orc::SimpleJIT::Create()); 219 | 220 | ExitOnErr(J->addModule( 221 | llvm::orc::ThreadSafeModule(std::move(Module), std::move(Ctx)))); 222 | auto Main = (int (*)(...))ExitOnErr(J->getSymbolAddress("main")); 223 | Res = Main(); 224 | } 225 | 226 | // Shutdown. 227 | llvm::llvm_shutdown(); 228 | 229 | return Res; 230 | } 231 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/myplugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_llvm_library(MyPlugin MODULE MyPlugin.cpp PLUGIN_TOOL clang) 2 | 3 | if(LLVM_ENABLE_PLUGINS AND (WIN32 OR CYGWIN)) 4 | target_link_libraries(MyPlugin PRIVATE 5 | clangAST 6 | clangBasic 7 | clangFrontend 8 | clangLex 9 | LLVMSupport 10 | ) 11 | endif() 12 | -------------------------------------------------------------------------------- /llvm_note/class4/examples/myplugin/MyPlugin.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "clang/AST/AST.h" 3 | #include "clang/AST/ASTConsumer.h" 4 | #include "clang/AST/RecursiveASTVisitor.h" 5 | #include "clang/Frontend/CompilerInstance.h" 6 | #include "clang/Frontend/FrontendPluginRegistry.h" 7 | using namespace clang; 8 | using namespace std; 9 | using namespace llvm; 10 | namespace MyPlugin 11 | { 12 | class MyASTVisitor: public 13 | RecursiveASTVisitor < MyASTVisitor > 14 | { 15 | private: 16 | ASTContext *context; 17 | public: 18 | void setContext(ASTContext &context) 19 | { 20 | this->context = &context; 21 | } 22 | 23 | bool VisitDecl(Decl *decl) 24 | { 25 | //cout << "-------- VisitDecl: haidragon"< (decl)) { 27 | ObjCInterfaceDecl *interDecl = (ObjCInterfaceDecl *)decl; 28 | if (interDecl->getSuperClass()) { 29 | string interName = interDecl->getNameAsString(); 30 | string superClassName = interDecl->getSuperClass()->getNameAsString(); 31 | 32 | cout << "-------- ClassName:" << interName << " superClassName:" << superClassName << endl; 33 | } 34 | } 35 | 36 | return true; 37 | } 38 | }; 39 | 40 | class MyASTConsumer: public ASTConsumer 41 | { 42 | private: 43 | MyASTVisitor visitor; 44 | void HandleTranslationUnit(ASTContext &context) 45 | { 46 | visitor.setContext(context); 47 | visitor.TraverseDecl(context.getTranslationUnitDecl()); 48 | } 49 | }; 50 | class MyASTAction: public PluginASTAction 51 | { 52 | public: 53 | unique_ptr < ASTConsumer > CreateASTConsumer(CompilerInstance & Compiler, StringRef InFile) { 54 | return unique_ptr < MyASTConsumer > (new MyASTConsumer); 55 | } 56 | bool ParseArgs(const CompilerInstance &CI, const std::vector < std::string >& args) 57 | { 58 | return true; 59 | } 60 | }; 61 | } 62 | static clang::FrontendPluginRegistry::Add 63 | < MyPlugin::MyASTAction > X("MyPlugin", 64 | "MyPlugin desc"); 65 | 66 | -------------------------------------------------------------------------------- /llvm_note/class4/note.md: -------------------------------------------------------------------------------- 1 | # 第四课 实现一个自定义检查规范的 Clang 插件 2 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class4/test/test.jpg) 3 | ## 参考 4 | * https://github.com/CYBoys/Blogs/blob/master/LLVM_Clang/LLVM%20%26%20Clang%20%E5%85%A5%E9%97%A8.md 5 | * https://www.jianshu.com/p/10bca4cbd0ff 6 | 7 | -------------------------------------------------------------------------------- /llvm_note/class4/test/test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class4/test/test.jpg -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class4/test/testclang.zip -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 4B65979B23C2CF9900075A7C /* test_clang.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B65979A23C2CF9900075A7C /* test_clang.m */; }; 11 | 4B65979C23C2CF9900075A7C /* test_clang.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B65979A23C2CF9900075A7C /* test_clang.m */; }; 12 | 4B65979D23C2CF9900075A7C /* test_clang.m in Sources */ = {isa = PBXBuildFile; fileRef = 4B65979A23C2CF9900075A7C /* test_clang.m */; }; 13 | 4BCE97EF23C1B88900F8F7F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE97EE23C1B88900F8F7F7 /* AppDelegate.m */; }; 14 | 4BCE97F223C1B88900F8F7F7 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE97F123C1B88900F8F7F7 /* ViewController.m */; }; 15 | 4BCE97F423C1B88A00F8F7F7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4BCE97F323C1B88A00F8F7F7 /* Assets.xcassets */; }; 16 | 4BCE97F723C1B88A00F8F7F7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4BCE97F523C1B88A00F8F7F7 /* Main.storyboard */; }; 17 | 4BCE97FA23C1B88A00F8F7F7 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE97F923C1B88A00F8F7F7 /* main.m */; }; 18 | 4BCE980523C1B88A00F8F7F7 /* testclangTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE980423C1B88A00F8F7F7 /* testclangTests.m */; }; 19 | 4BCE981023C1B88A00F8F7F7 /* testclangUITests.m in Sources */ = {isa = PBXBuildFile; fileRef = 4BCE980F23C1B88A00F8F7F7 /* testclangUITests.m */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | 4BCE980123C1B88A00F8F7F7 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = 4BCE97E223C1B88900F8F7F7 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = 4BCE97E923C1B88900F8F7F7; 28 | remoteInfo = testclang; 29 | }; 30 | 4BCE980C23C1B88A00F8F7F7 /* PBXContainerItemProxy */ = { 31 | isa = PBXContainerItemProxy; 32 | containerPortal = 4BCE97E223C1B88900F8F7F7 /* Project object */; 33 | proxyType = 1; 34 | remoteGlobalIDString = 4BCE97E923C1B88900F8F7F7; 35 | remoteInfo = testclang; 36 | }; 37 | /* End PBXContainerItemProxy section */ 38 | 39 | /* Begin PBXFileReference section */ 40 | 4B65979923C2CF9900075A7C /* test_clang.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = test_clang.h; sourceTree = ""; }; 41 | 4B65979A23C2CF9900075A7C /* test_clang.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = test_clang.m; sourceTree = ""; }; 42 | 4BCE97EA23C1B88900F8F7F7 /* testclang.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = testclang.app; sourceTree = BUILT_PRODUCTS_DIR; }; 43 | 4BCE97ED23C1B88900F8F7F7 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 44 | 4BCE97EE23C1B88900F8F7F7 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 45 | 4BCE97F023C1B88900F8F7F7 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 46 | 4BCE97F123C1B88900F8F7F7 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 47 | 4BCE97F323C1B88A00F8F7F7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 48 | 4BCE97F623C1B88A00F8F7F7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 49 | 4BCE97F823C1B88A00F8F7F7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 50 | 4BCE97F923C1B88A00F8F7F7 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 51 | 4BCE97FB23C1B88A00F8F7F7 /* testclang.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = testclang.entitlements; sourceTree = ""; }; 52 | 4BCE980023C1B88A00F8F7F7 /* testclangTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = testclangTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 53 | 4BCE980423C1B88A00F8F7F7 /* testclangTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = testclangTests.m; sourceTree = ""; }; 54 | 4BCE980623C1B88A00F8F7F7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 55 | 4BCE980B23C1B88A00F8F7F7 /* testclangUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = testclangUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 56 | 4BCE980F23C1B88A00F8F7F7 /* testclangUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = testclangUITests.m; sourceTree = ""; }; 57 | 4BCE981123C1B88A00F8F7F7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 58 | /* End PBXFileReference section */ 59 | 60 | /* Begin PBXFrameworksBuildPhase section */ 61 | 4BCE97E723C1B88900F8F7F7 /* Frameworks */ = { 62 | isa = PBXFrameworksBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | ); 66 | runOnlyForDeploymentPostprocessing = 0; 67 | }; 68 | 4BCE97FD23C1B88A00F8F7F7 /* Frameworks */ = { 69 | isa = PBXFrameworksBuildPhase; 70 | buildActionMask = 2147483647; 71 | files = ( 72 | ); 73 | runOnlyForDeploymentPostprocessing = 0; 74 | }; 75 | 4BCE980823C1B88A00F8F7F7 /* Frameworks */ = { 76 | isa = PBXFrameworksBuildPhase; 77 | buildActionMask = 2147483647; 78 | files = ( 79 | ); 80 | runOnlyForDeploymentPostprocessing = 0; 81 | }; 82 | /* End PBXFrameworksBuildPhase section */ 83 | 84 | /* Begin PBXGroup section */ 85 | 4BCE97E123C1B88900F8F7F7 = { 86 | isa = PBXGroup; 87 | children = ( 88 | 4BCE97EC23C1B88900F8F7F7 /* testclang */, 89 | 4BCE980323C1B88A00F8F7F7 /* testclangTests */, 90 | 4BCE980E23C1B88A00F8F7F7 /* testclangUITests */, 91 | 4BCE97EB23C1B88900F8F7F7 /* Products */, 92 | ); 93 | sourceTree = ""; 94 | }; 95 | 4BCE97EB23C1B88900F8F7F7 /* Products */ = { 96 | isa = PBXGroup; 97 | children = ( 98 | 4BCE97EA23C1B88900F8F7F7 /* testclang.app */, 99 | 4BCE980023C1B88A00F8F7F7 /* testclangTests.xctest */, 100 | 4BCE980B23C1B88A00F8F7F7 /* testclangUITests.xctest */, 101 | ); 102 | name = Products; 103 | sourceTree = ""; 104 | }; 105 | 4BCE97EC23C1B88900F8F7F7 /* testclang */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 4BCE97ED23C1B88900F8F7F7 /* AppDelegate.h */, 109 | 4BCE97EE23C1B88900F8F7F7 /* AppDelegate.m */, 110 | 4BCE97F023C1B88900F8F7F7 /* ViewController.h */, 111 | 4BCE97F123C1B88900F8F7F7 /* ViewController.m */, 112 | 4BCE97F323C1B88A00F8F7F7 /* Assets.xcassets */, 113 | 4BCE97F523C1B88A00F8F7F7 /* Main.storyboard */, 114 | 4BCE97F823C1B88A00F8F7F7 /* Info.plist */, 115 | 4BCE97F923C1B88A00F8F7F7 /* main.m */, 116 | 4BCE97FB23C1B88A00F8F7F7 /* testclang.entitlements */, 117 | 4B65979923C2CF9900075A7C /* test_clang.h */, 118 | 4B65979A23C2CF9900075A7C /* test_clang.m */, 119 | ); 120 | path = testclang; 121 | sourceTree = ""; 122 | }; 123 | 4BCE980323C1B88A00F8F7F7 /* testclangTests */ = { 124 | isa = PBXGroup; 125 | children = ( 126 | 4BCE980423C1B88A00F8F7F7 /* testclangTests.m */, 127 | 4BCE980623C1B88A00F8F7F7 /* Info.plist */, 128 | ); 129 | path = testclangTests; 130 | sourceTree = ""; 131 | }; 132 | 4BCE980E23C1B88A00F8F7F7 /* testclangUITests */ = { 133 | isa = PBXGroup; 134 | children = ( 135 | 4BCE980F23C1B88A00F8F7F7 /* testclangUITests.m */, 136 | 4BCE981123C1B88A00F8F7F7 /* Info.plist */, 137 | ); 138 | path = testclangUITests; 139 | sourceTree = ""; 140 | }; 141 | /* End PBXGroup section */ 142 | 143 | /* Begin PBXNativeTarget section */ 144 | 4BCE97E923C1B88900F8F7F7 /* testclang */ = { 145 | isa = PBXNativeTarget; 146 | buildConfigurationList = 4BCE981423C1B88A00F8F7F7 /* Build configuration list for PBXNativeTarget "testclang" */; 147 | buildPhases = ( 148 | 4BCE97E623C1B88900F8F7F7 /* Sources */, 149 | 4BCE97E723C1B88900F8F7F7 /* Frameworks */, 150 | 4BCE97E823C1B88900F8F7F7 /* Resources */, 151 | ); 152 | buildRules = ( 153 | ); 154 | dependencies = ( 155 | ); 156 | name = testclang; 157 | productName = testclang; 158 | productReference = 4BCE97EA23C1B88900F8F7F7 /* testclang.app */; 159 | productType = "com.apple.product-type.application"; 160 | }; 161 | 4BCE97FF23C1B88A00F8F7F7 /* testclangTests */ = { 162 | isa = PBXNativeTarget; 163 | buildConfigurationList = 4BCE981723C1B88A00F8F7F7 /* Build configuration list for PBXNativeTarget "testclangTests" */; 164 | buildPhases = ( 165 | 4BCE97FC23C1B88A00F8F7F7 /* Sources */, 166 | 4BCE97FD23C1B88A00F8F7F7 /* Frameworks */, 167 | 4BCE97FE23C1B88A00F8F7F7 /* Resources */, 168 | ); 169 | buildRules = ( 170 | ); 171 | dependencies = ( 172 | 4BCE980223C1B88A00F8F7F7 /* PBXTargetDependency */, 173 | ); 174 | name = testclangTests; 175 | productName = testclangTests; 176 | productReference = 4BCE980023C1B88A00F8F7F7 /* testclangTests.xctest */; 177 | productType = "com.apple.product-type.bundle.unit-test"; 178 | }; 179 | 4BCE980A23C1B88A00F8F7F7 /* testclangUITests */ = { 180 | isa = PBXNativeTarget; 181 | buildConfigurationList = 4BCE981A23C1B88A00F8F7F7 /* Build configuration list for PBXNativeTarget "testclangUITests" */; 182 | buildPhases = ( 183 | 4BCE980723C1B88A00F8F7F7 /* Sources */, 184 | 4BCE980823C1B88A00F8F7F7 /* Frameworks */, 185 | 4BCE980923C1B88A00F8F7F7 /* Resources */, 186 | ); 187 | buildRules = ( 188 | ); 189 | dependencies = ( 190 | 4BCE980D23C1B88A00F8F7F7 /* PBXTargetDependency */, 191 | ); 192 | name = testclangUITests; 193 | productName = testclangUITests; 194 | productReference = 4BCE980B23C1B88A00F8F7F7 /* testclangUITests.xctest */; 195 | productType = "com.apple.product-type.bundle.ui-testing"; 196 | }; 197 | /* End PBXNativeTarget section */ 198 | 199 | /* Begin PBXProject section */ 200 | 4BCE97E223C1B88900F8F7F7 /* Project object */ = { 201 | isa = PBXProject; 202 | attributes = { 203 | LastUpgradeCheck = 1130; 204 | ORGANIZATIONNAME = haidragon; 205 | TargetAttributes = { 206 | 4BCE97E923C1B88900F8F7F7 = { 207 | CreatedOnToolsVersion = 11.3; 208 | }; 209 | 4BCE97FF23C1B88A00F8F7F7 = { 210 | CreatedOnToolsVersion = 11.3; 211 | TestTargetID = 4BCE97E923C1B88900F8F7F7; 212 | }; 213 | 4BCE980A23C1B88A00F8F7F7 = { 214 | CreatedOnToolsVersion = 11.3; 215 | TestTargetID = 4BCE97E923C1B88900F8F7F7; 216 | }; 217 | }; 218 | }; 219 | buildConfigurationList = 4BCE97E523C1B88900F8F7F7 /* Build configuration list for PBXProject "testclang" */; 220 | compatibilityVersion = "Xcode 9.3"; 221 | developmentRegion = en; 222 | hasScannedForEncodings = 0; 223 | knownRegions = ( 224 | en, 225 | Base, 226 | ); 227 | mainGroup = 4BCE97E123C1B88900F8F7F7; 228 | productRefGroup = 4BCE97EB23C1B88900F8F7F7 /* Products */; 229 | projectDirPath = ""; 230 | projectRoot = ""; 231 | targets = ( 232 | 4BCE97E923C1B88900F8F7F7 /* testclang */, 233 | 4BCE97FF23C1B88A00F8F7F7 /* testclangTests */, 234 | 4BCE980A23C1B88A00F8F7F7 /* testclangUITests */, 235 | ); 236 | }; 237 | /* End PBXProject section */ 238 | 239 | /* Begin PBXResourcesBuildPhase section */ 240 | 4BCE97E823C1B88900F8F7F7 /* Resources */ = { 241 | isa = PBXResourcesBuildPhase; 242 | buildActionMask = 2147483647; 243 | files = ( 244 | 4BCE97F423C1B88A00F8F7F7 /* Assets.xcassets in Resources */, 245 | 4BCE97F723C1B88A00F8F7F7 /* Main.storyboard in Resources */, 246 | ); 247 | runOnlyForDeploymentPostprocessing = 0; 248 | }; 249 | 4BCE97FE23C1B88A00F8F7F7 /* Resources */ = { 250 | isa = PBXResourcesBuildPhase; 251 | buildActionMask = 2147483647; 252 | files = ( 253 | ); 254 | runOnlyForDeploymentPostprocessing = 0; 255 | }; 256 | 4BCE980923C1B88A00F8F7F7 /* Resources */ = { 257 | isa = PBXResourcesBuildPhase; 258 | buildActionMask = 2147483647; 259 | files = ( 260 | ); 261 | runOnlyForDeploymentPostprocessing = 0; 262 | }; 263 | /* End PBXResourcesBuildPhase section */ 264 | 265 | /* Begin PBXSourcesBuildPhase section */ 266 | 4BCE97E623C1B88900F8F7F7 /* Sources */ = { 267 | isa = PBXSourcesBuildPhase; 268 | buildActionMask = 2147483647; 269 | files = ( 270 | 4BCE97F223C1B88900F8F7F7 /* ViewController.m in Sources */, 271 | 4BCE97FA23C1B88A00F8F7F7 /* main.m in Sources */, 272 | 4BCE97EF23C1B88900F8F7F7 /* AppDelegate.m in Sources */, 273 | 4B65979B23C2CF9900075A7C /* test_clang.m in Sources */, 274 | ); 275 | runOnlyForDeploymentPostprocessing = 0; 276 | }; 277 | 4BCE97FC23C1B88A00F8F7F7 /* Sources */ = { 278 | isa = PBXSourcesBuildPhase; 279 | buildActionMask = 2147483647; 280 | files = ( 281 | 4BCE980523C1B88A00F8F7F7 /* testclangTests.m in Sources */, 282 | 4B65979C23C2CF9900075A7C /* test_clang.m in Sources */, 283 | ); 284 | runOnlyForDeploymentPostprocessing = 0; 285 | }; 286 | 4BCE980723C1B88A00F8F7F7 /* Sources */ = { 287 | isa = PBXSourcesBuildPhase; 288 | buildActionMask = 2147483647; 289 | files = ( 290 | 4BCE981023C1B88A00F8F7F7 /* testclangUITests.m in Sources */, 291 | 4B65979D23C2CF9900075A7C /* test_clang.m in Sources */, 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | /* End PBXSourcesBuildPhase section */ 296 | 297 | /* Begin PBXTargetDependency section */ 298 | 4BCE980223C1B88A00F8F7F7 /* PBXTargetDependency */ = { 299 | isa = PBXTargetDependency; 300 | target = 4BCE97E923C1B88900F8F7F7 /* testclang */; 301 | targetProxy = 4BCE980123C1B88A00F8F7F7 /* PBXContainerItemProxy */; 302 | }; 303 | 4BCE980D23C1B88A00F8F7F7 /* PBXTargetDependency */ = { 304 | isa = PBXTargetDependency; 305 | target = 4BCE97E923C1B88900F8F7F7 /* testclang */; 306 | targetProxy = 4BCE980C23C1B88A00F8F7F7 /* PBXContainerItemProxy */; 307 | }; 308 | /* End PBXTargetDependency section */ 309 | 310 | /* Begin PBXVariantGroup section */ 311 | 4BCE97F523C1B88A00F8F7F7 /* Main.storyboard */ = { 312 | isa = PBXVariantGroup; 313 | children = ( 314 | 4BCE97F623C1B88A00F8F7F7 /* Base */, 315 | ); 316 | name = Main.storyboard; 317 | sourceTree = ""; 318 | }; 319 | /* End PBXVariantGroup section */ 320 | 321 | /* Begin XCBuildConfiguration section */ 322 | 4BCE981223C1B88A00F8F7F7 /* Debug */ = { 323 | isa = XCBuildConfiguration; 324 | buildSettings = { 325 | ALWAYS_SEARCH_USER_PATHS = NO; 326 | CLANG_ANALYZER_NONNULL = YES; 327 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 328 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 329 | CLANG_CXX_LIBRARY = "libc++"; 330 | CLANG_ENABLE_MODULES = YES; 331 | CLANG_ENABLE_OBJC_ARC = YES; 332 | CLANG_ENABLE_OBJC_WEAK = YES; 333 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 334 | CLANG_WARN_BOOL_CONVERSION = YES; 335 | CLANG_WARN_COMMA = YES; 336 | CLANG_WARN_CONSTANT_CONVERSION = YES; 337 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 338 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 339 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 340 | CLANG_WARN_EMPTY_BODY = YES; 341 | CLANG_WARN_ENUM_CONVERSION = YES; 342 | CLANG_WARN_INFINITE_RECURSION = YES; 343 | CLANG_WARN_INT_CONVERSION = YES; 344 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 345 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 346 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 347 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 348 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 349 | CLANG_WARN_STRICT_PROTOTYPES = YES; 350 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 351 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 352 | CLANG_WARN_UNREACHABLE_CODE = YES; 353 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 354 | COPY_PHASE_STRIP = NO; 355 | DEBUG_INFORMATION_FORMAT = dwarf; 356 | ENABLE_STRICT_OBJC_MSGSEND = YES; 357 | ENABLE_TESTABILITY = YES; 358 | GCC_C_LANGUAGE_STANDARD = gnu11; 359 | GCC_DYNAMIC_NO_PIC = NO; 360 | GCC_NO_COMMON_BLOCKS = YES; 361 | GCC_OPTIMIZATION_LEVEL = 0; 362 | GCC_PREPROCESSOR_DEFINITIONS = ( 363 | "DEBUG=1", 364 | "$(inherited)", 365 | ); 366 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 367 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 368 | GCC_WARN_UNDECLARED_SELECTOR = YES; 369 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 370 | GCC_WARN_UNUSED_FUNCTION = YES; 371 | GCC_WARN_UNUSED_VARIABLE = YES; 372 | MACOSX_DEPLOYMENT_TARGET = 10.15; 373 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 374 | MTL_FAST_MATH = YES; 375 | ONLY_ACTIVE_ARCH = YES; 376 | OTHER_CFLAGS = ( 377 | "-Xclang", 378 | "-load", 379 | "-Xclang", 380 | /Users/haidragon/Desktop/llvm_build/Debug/bin/CodeChecker.dylib, 381 | "-Xclang", 382 | "-add-plugin", 383 | "-Xclang", 384 | CodeChecker, 385 | ); 386 | SDKROOT = macosx; 387 | }; 388 | name = Debug; 389 | }; 390 | 4BCE981323C1B88A00F8F7F7 /* Release */ = { 391 | isa = XCBuildConfiguration; 392 | buildSettings = { 393 | ALWAYS_SEARCH_USER_PATHS = NO; 394 | CLANG_ANALYZER_NONNULL = YES; 395 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 396 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 397 | CLANG_CXX_LIBRARY = "libc++"; 398 | CLANG_ENABLE_MODULES = YES; 399 | CLANG_ENABLE_OBJC_ARC = YES; 400 | CLANG_ENABLE_OBJC_WEAK = YES; 401 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 402 | CLANG_WARN_BOOL_CONVERSION = YES; 403 | CLANG_WARN_COMMA = YES; 404 | CLANG_WARN_CONSTANT_CONVERSION = YES; 405 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 406 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 407 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 408 | CLANG_WARN_EMPTY_BODY = YES; 409 | CLANG_WARN_ENUM_CONVERSION = YES; 410 | CLANG_WARN_INFINITE_RECURSION = YES; 411 | CLANG_WARN_INT_CONVERSION = YES; 412 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 413 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 414 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 415 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 416 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 417 | CLANG_WARN_STRICT_PROTOTYPES = YES; 418 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 419 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 420 | CLANG_WARN_UNREACHABLE_CODE = YES; 421 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 422 | COPY_PHASE_STRIP = NO; 423 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 424 | ENABLE_NS_ASSERTIONS = NO; 425 | ENABLE_STRICT_OBJC_MSGSEND = YES; 426 | GCC_C_LANGUAGE_STANDARD = gnu11; 427 | GCC_NO_COMMON_BLOCKS = YES; 428 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 429 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 430 | GCC_WARN_UNDECLARED_SELECTOR = YES; 431 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 432 | GCC_WARN_UNUSED_FUNCTION = YES; 433 | GCC_WARN_UNUSED_VARIABLE = YES; 434 | MACOSX_DEPLOYMENT_TARGET = 10.15; 435 | MTL_ENABLE_DEBUG_INFO = NO; 436 | MTL_FAST_MATH = YES; 437 | OTHER_CFLAGS = ( 438 | "-Xclang", 439 | "-load", 440 | "-Xclang", 441 | /Users/haidragon/Desktop/llvm_build/Debug/bin/CodeChecker.dylib, 442 | "-Xclang", 443 | "-add-plugin", 444 | "-Xclang", 445 | CodeChecker, 446 | ); 447 | SDKROOT = macosx; 448 | }; 449 | name = Release; 450 | }; 451 | 4BCE981523C1B88A00F8F7F7 /* Debug */ = { 452 | isa = XCBuildConfiguration; 453 | buildSettings = { 454 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 455 | CC = /Users/haidragon/Desktop/llvm_build/Debug/bin/clang; 456 | CODE_SIGN_ENTITLEMENTS = testclang/testclang.entitlements; 457 | CODE_SIGN_STYLE = Automatic; 458 | COMBINE_HIDPI_IMAGES = YES; 459 | COMPILER_INDEX_STORE_ENABLE = NO; 460 | CXX = "/Users/haidragon/Desktop/llvm_build/Debug/bin/clang++"; 461 | DEVELOPMENT_TEAM = JQWK8YZCBB; 462 | ENABLE_HARDENED_RUNTIME = YES; 463 | GCC_VERSION = ""; 464 | INFOPLIST_FILE = testclang/Info.plist; 465 | LD_RUNPATH_SEARCH_PATHS = ( 466 | "$(inherited)", 467 | "@executable_path/../Frameworks", 468 | ); 469 | OTHER_CFLAGS = ( 470 | "-Xclang", 471 | "-load", 472 | "-Xclang", 473 | /Users/haidragon/Desktop/llvm_build/Debug/lib/CodeChecker.dylib, 474 | "-Xclang", 475 | "-add-plugin", 476 | "-Xclang", 477 | CodeChecker, 478 | "-isysroot", 479 | /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk, 480 | ); 481 | PRODUCT_BUNDLE_IDENTIFIER = con.test.haidragon.testclang; 482 | PRODUCT_NAME = "$(TARGET_NAME)"; 483 | }; 484 | name = Debug; 485 | }; 486 | 4BCE981623C1B88A00F8F7F7 /* Release */ = { 487 | isa = XCBuildConfiguration; 488 | buildSettings = { 489 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 490 | CC = /Users/haidragon/Desktop/llvm_build/Debug/bin/clang; 491 | CODE_SIGN_ENTITLEMENTS = testclang/testclang.entitlements; 492 | CODE_SIGN_STYLE = Automatic; 493 | COMBINE_HIDPI_IMAGES = YES; 494 | COMPILER_INDEX_STORE_ENABLE = NO; 495 | CXX = "/Users/haidragon/Desktop/llvm_build/Debug/bin/clang++"; 496 | DEVELOPMENT_TEAM = JQWK8YZCBB; 497 | ENABLE_HARDENED_RUNTIME = YES; 498 | GCC_VERSION = ""; 499 | INFOPLIST_FILE = testclang/Info.plist; 500 | LD_RUNPATH_SEARCH_PATHS = ( 501 | "$(inherited)", 502 | "@executable_path/../Frameworks", 503 | ); 504 | OTHER_CFLAGS = ( 505 | "-Xclang", 506 | "-load", 507 | "-Xclang", 508 | /Users/haidragon/Desktop/llvm_build/Debug/lib/CodeChecker.dylib, 509 | "-Xclang", 510 | "-add-plugin", 511 | "-Xclang", 512 | CodeChecker, 513 | "-isysroot", 514 | /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk, 515 | ); 516 | PRODUCT_BUNDLE_IDENTIFIER = con.test.haidragon.testclang; 517 | PRODUCT_NAME = "$(TARGET_NAME)"; 518 | }; 519 | name = Release; 520 | }; 521 | 4BCE981823C1B88A00F8F7F7 /* Debug */ = { 522 | isa = XCBuildConfiguration; 523 | buildSettings = { 524 | BUNDLE_LOADER = "$(TEST_HOST)"; 525 | CODE_SIGN_STYLE = Automatic; 526 | COMBINE_HIDPI_IMAGES = YES; 527 | DEVELOPMENT_TEAM = JQWK8YZCBB; 528 | INFOPLIST_FILE = testclangTests/Info.plist; 529 | LD_RUNPATH_SEARCH_PATHS = ( 530 | "$(inherited)", 531 | "@executable_path/../Frameworks", 532 | "@loader_path/../Frameworks", 533 | ); 534 | MACOSX_DEPLOYMENT_TARGET = 10.15; 535 | PRODUCT_BUNDLE_IDENTIFIER = con.test.haidragon.testclangTests; 536 | PRODUCT_NAME = "$(TARGET_NAME)"; 537 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testclang.app/Contents/MacOS/testclang"; 538 | }; 539 | name = Debug; 540 | }; 541 | 4BCE981923C1B88A00F8F7F7 /* Release */ = { 542 | isa = XCBuildConfiguration; 543 | buildSettings = { 544 | BUNDLE_LOADER = "$(TEST_HOST)"; 545 | CODE_SIGN_STYLE = Automatic; 546 | COMBINE_HIDPI_IMAGES = YES; 547 | DEVELOPMENT_TEAM = JQWK8YZCBB; 548 | INFOPLIST_FILE = testclangTests/Info.plist; 549 | LD_RUNPATH_SEARCH_PATHS = ( 550 | "$(inherited)", 551 | "@executable_path/../Frameworks", 552 | "@loader_path/../Frameworks", 553 | ); 554 | MACOSX_DEPLOYMENT_TARGET = 10.15; 555 | PRODUCT_BUNDLE_IDENTIFIER = con.test.haidragon.testclangTests; 556 | PRODUCT_NAME = "$(TARGET_NAME)"; 557 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/testclang.app/Contents/MacOS/testclang"; 558 | }; 559 | name = Release; 560 | }; 561 | 4BCE981B23C1B88A00F8F7F7 /* Debug */ = { 562 | isa = XCBuildConfiguration; 563 | buildSettings = { 564 | CODE_SIGN_STYLE = Automatic; 565 | COMBINE_HIDPI_IMAGES = YES; 566 | DEVELOPMENT_TEAM = JQWK8YZCBB; 567 | INFOPLIST_FILE = testclangUITests/Info.plist; 568 | LD_RUNPATH_SEARCH_PATHS = ( 569 | "$(inherited)", 570 | "@executable_path/../Frameworks", 571 | "@loader_path/../Frameworks", 572 | ); 573 | PRODUCT_BUNDLE_IDENTIFIER = con.test.haidragon.testclangUITests; 574 | PRODUCT_NAME = "$(TARGET_NAME)"; 575 | TEST_TARGET_NAME = testclang; 576 | }; 577 | name = Debug; 578 | }; 579 | 4BCE981C23C1B88A00F8F7F7 /* Release */ = { 580 | isa = XCBuildConfiguration; 581 | buildSettings = { 582 | CODE_SIGN_STYLE = Automatic; 583 | COMBINE_HIDPI_IMAGES = YES; 584 | DEVELOPMENT_TEAM = JQWK8YZCBB; 585 | INFOPLIST_FILE = testclangUITests/Info.plist; 586 | LD_RUNPATH_SEARCH_PATHS = ( 587 | "$(inherited)", 588 | "@executable_path/../Frameworks", 589 | "@loader_path/../Frameworks", 590 | ); 591 | PRODUCT_BUNDLE_IDENTIFIER = con.test.haidragon.testclangUITests; 592 | PRODUCT_NAME = "$(TARGET_NAME)"; 593 | TEST_TARGET_NAME = testclang; 594 | }; 595 | name = Release; 596 | }; 597 | /* End XCBuildConfiguration section */ 598 | 599 | /* Begin XCConfigurationList section */ 600 | 4BCE97E523C1B88900F8F7F7 /* Build configuration list for PBXProject "testclang" */ = { 601 | isa = XCConfigurationList; 602 | buildConfigurations = ( 603 | 4BCE981223C1B88A00F8F7F7 /* Debug */, 604 | 4BCE981323C1B88A00F8F7F7 /* Release */, 605 | ); 606 | defaultConfigurationIsVisible = 0; 607 | defaultConfigurationName = Release; 608 | }; 609 | 4BCE981423C1B88A00F8F7F7 /* Build configuration list for PBXNativeTarget "testclang" */ = { 610 | isa = XCConfigurationList; 611 | buildConfigurations = ( 612 | 4BCE981523C1B88A00F8F7F7 /* Debug */, 613 | 4BCE981623C1B88A00F8F7F7 /* Release */, 614 | ); 615 | defaultConfigurationIsVisible = 0; 616 | defaultConfigurationName = Release; 617 | }; 618 | 4BCE981723C1B88A00F8F7F7 /* Build configuration list for PBXNativeTarget "testclangTests" */ = { 619 | isa = XCConfigurationList; 620 | buildConfigurations = ( 621 | 4BCE981823C1B88A00F8F7F7 /* Debug */, 622 | 4BCE981923C1B88A00F8F7F7 /* Release */, 623 | ); 624 | defaultConfigurationIsVisible = 0; 625 | defaultConfigurationName = Release; 626 | }; 627 | 4BCE981A23C1B88A00F8F7F7 /* Build configuration list for PBXNativeTarget "testclangUITests" */ = { 628 | isa = XCConfigurationList; 629 | buildConfigurations = ( 630 | 4BCE981B23C1B88A00F8F7F7 /* Debug */, 631 | 4BCE981C23C1B88A00F8F7F7 /* Release */, 632 | ); 633 | defaultConfigurationIsVisible = 0; 634 | defaultConfigurationName = Release; 635 | }; 636 | /* End XCConfigurationList section */ 637 | }; 638 | rootObject = 4BCE97E223C1B88900F8F7F7 /* Project object */; 639 | } 640 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang.xcodeproj/project.xcworkspace/xcuserdata/haidragon.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class4/test/testclang/testclang.xcodeproj/project.xcworkspace/xcuserdata/haidragon.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang.xcodeproj/xcuserdata/haidragon.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | testclang.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : NSObject 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | - (void)applicationDidFinishLaunching:(NSNotification *)aNotification { 18 | // Insert code here to initialize your application 19 | } 20 | 21 | 22 | - (void)applicationWillTerminate:(NSNotification *)aNotification { 23 | // Insert code here to tear down your application 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | Default 529 | 530 | 531 | 532 | 533 | 534 | 535 | Left to Right 536 | 537 | 538 | 539 | 540 | 541 | 542 | Right to Left 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | Default 554 | 555 | 556 | 557 | 558 | 559 | 560 | Left to Right 561 | 562 | 563 | 564 | 565 | 566 | 567 | Right to Left 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleVersion 22 | 1 23 | LSMinimumSystemVersion 24 | $(MACOSX_DEPLOYMENT_TARGET) 25 | NSHumanReadableCopyright 26 | Copyright © 2020 haidragon. All rights reserved. 27 | NSMainStoryboardFile 28 | Main 29 | NSPrincipalClass 30 | NSApplication 31 | NSSupportsAutomaticTermination 32 | 33 | NSSupportsSuddenTermination 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : NSViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "test_clang.h" 11 | @implementation ViewController 12 | 13 | - (void)viewDidLoad { 14 | [super viewDidLoad]; 15 | [test_clang test]; 16 | // Do any additional setup after loading the view. 17 | } 18 | 19 | 20 | - (void)setRepresentedObject:(id)representedObject { 21 | [super setRepresentedObject:representedObject]; 22 | 23 | // Update the view, if already loaded. 24 | } 25 | 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, const char * argv[]) { 12 | @autoreleasepool { 13 | // Setup code that might create autoreleased objects goes here. 14 | } 15 | return NSApplicationMain(argc, argv); 16 | } 17 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/test_clang.h: -------------------------------------------------------------------------------- 1 | // 2 | // test_clang.h 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/6. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | NS_ASSUME_NONNULL_BEGIN 12 | 13 | @interface test_clang : NSObject 14 | + (void)test; 15 | @end 16 | 17 | NS_ASSUME_NONNULL_END 18 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/test_clang.m: -------------------------------------------------------------------------------- 1 | // 2 | // test_clang.m 3 | // testclang 4 | // 5 | // Created by haidragon on 2020/1/6. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import "test_clang.h" 10 | 11 | @implementation test_clang 12 | + (void)test{ 13 | NSLog(@"tset\n"); 14 | } 15 | @end 16 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclang/testclang.entitlements: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | com.apple.security.app-sandbox 6 | 7 | com.apple.security.files.user-selected.read-only 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclangTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclangTests/testclangTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // testclangTests.m 3 | // testclangTests 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface testclangTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation testclangTests 16 | 17 | - (void)setUp { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | } 20 | 21 | - (void)tearDown { 22 | // Put teardown code here. This method is called after the invocation of each test method in the class. 23 | } 24 | 25 | - (void)testExample { 26 | // This is an example of a functional test case. 27 | // Use XCTAssert and related functions to verify your tests produce the correct results. 28 | } 29 | 30 | - (void)testPerformanceExample { 31 | // This is an example of a performance test case. 32 | [self measureBlock:^{ 33 | // Put the code you want to measure the time of here. 34 | }]; 35 | } 36 | 37 | @end 38 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclangUITests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /llvm_note/class4/test/testclang/testclangUITests/testclangUITests.m: -------------------------------------------------------------------------------- 1 | // 2 | // testclangUITests.m 3 | // testclangUITests 4 | // 5 | // Created by haidragon on 2020/1/5. 6 | // Copyright © 2020 haidragon. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface testclangUITests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation testclangUITests 16 | 17 | - (void)setUp { 18 | // Put setup code here. This method is called before the invocation of each test method in the class. 19 | 20 | // In UI tests it is usually best to stop immediately when a failure occurs. 21 | self.continueAfterFailure = NO; 22 | 23 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this. 24 | } 25 | 26 | - (void)tearDown { 27 | // Put teardown code here. This method is called after the invocation of each test method in the class. 28 | } 29 | 30 | - (void)testExample { 31 | // UI tests must launch the application that they test. 32 | XCUIApplication *app = [[XCUIApplication alloc] init]; 33 | [app launch]; 34 | 35 | // Use recording to get started writing UI tests. 36 | // Use XCTAssert and related functions to verify your tests produce the correct results. 37 | } 38 | 39 | - (void)testLaunchPerformance { 40 | if (@available(macOS 10.15, iOS 13.0, tvOS 13.0, *)) { 41 | // This measures how long it takes to launch your application. 42 | [self measureWithMetrics:@[XCTOSSignpostMetric.applicationLaunchMetric] block:^{ 43 | [[[XCUIApplication alloc] init] launch]; 44 | }]; 45 | } 46 | } 47 | 48 | @end 49 | -------------------------------------------------------------------------------- /llvm_note/class5/LLVMHello.dylib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class5/LLVMHello.dylib -------------------------------------------------------------------------------- /llvm_note/class5/note.md: -------------------------------------------------------------------------------- 1 | # llvm pass 编译与调试 2 | ``` 3 | clang -emit-llvm -c /Users/haidragon/Desktop/llvm_note/class5/test.m -o/Users/haidragon/Desktop/llvm_note/class5/test.bc 4 | ./opt -load /Users/haidragon/Desktop/llvm_note/class5/LLVMHello.dylib -hello -time-passes -disable-output /Users/haidragon/Desktop/llvm_note/class5/test.bc 5 | ``` 6 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class5/opt.png) 7 | 8 | -------------------------------------------------------------------------------- /llvm_note/class5/opt.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class5/opt.png -------------------------------------------------------------------------------- /llvm_note/class5/test.bc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class5/test.bc -------------------------------------------------------------------------------- /llvm_note/class5/test.m: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | int add(int x, int y) { 4 | return x + y; 5 | } 6 | int main(){ 7 | printf("%d",add(3,4)); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /llvm_note/class9/note.md: -------------------------------------------------------------------------------- 1 | # 第九课 ollvm编译(mac/linux) 2 | * mac 3 | ``` 4 | https://github.com/HikariObfuscator/Hikari/releases 5 | https://github.com/heroims/obfuscator 6 | git clone https://github.com/heroims/obfuscator 7 | cd obfuscator 8 | git checkout llvm-8.0 9 | ./clang test.c -o test_fla -mllvm -fla -mllvm -split -mllvm -split_num=3 10 | ./clang test.c -o test_ollvm -mllvm -fla -mllvm -split -mllvm -split_num=3 -mllvm -sub -mllvm -sub_loop=3 -mllvm -bcf -mllvm -bcf_loop=3 -mllvm -sobf -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk 11 | ./clang test.c -o test_1 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk 12 | ``` 13 | * 默认 14 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/test.png) 15 | * fla 16 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/test2.png) 17 | * ollvm全开 18 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/test3.png) 19 | # xcode集成配置 20 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/xc2.png) 21 | * ![](https://github.com/haidragon/study_obscure/blob/master/llvm_note/class9/xcode.png) 22 | * 参考 23 | * https://www.jianshu.com/p/e0637f3169a3 24 | 25 | 26 | -------------------------------------------------------------------------------- /llvm_note/class9/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int add (int a,int b){ 4 | return a+b; 5 | } 6 | 7 | int main(int argc, char **argv) 8 | { 9 | add(1,2); 10 | if (argc == 1) { 11 | printf("%d\n", argc); 12 | return 0; 13 | } 14 | return 0; 15 | } 16 | -------------------------------------------------------------------------------- /llvm_note/class9/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/test.png -------------------------------------------------------------------------------- /llvm_note/class9/test2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/test2.png -------------------------------------------------------------------------------- /llvm_note/class9/test3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/test3.png -------------------------------------------------------------------------------- /llvm_note/class9/test_1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/test_1 -------------------------------------------------------------------------------- /llvm_note/class9/test_fla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/test_fla -------------------------------------------------------------------------------- /llvm_note/class9/test_ollvm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/test_ollvm -------------------------------------------------------------------------------- /llvm_note/class9/xc2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/xc2.png -------------------------------------------------------------------------------- /llvm_note/class9/xcode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/haidragon/study_obscure/779e3d03ab15be4c59b797c168b6c6c338cf17ea/llvm_note/class9/xcode.png -------------------------------------------------------------------------------- /llvm_note/class_5/note.md: -------------------------------------------------------------------------------- 1 | # 第五课 llvm-词法分析 2 | * 等待更新 3 | 4 | -------------------------------------------------------------------------------- /llvm_note/class_6/note.md: -------------------------------------------------------------------------------- 1 | # 第六课 llvm-语法分析 2 | * 等待更新 3 | 4 | 5 | -------------------------------------------------------------------------------- /llvm_note/class_7/note.md: -------------------------------------------------------------------------------- 1 | # 第七课 单个函数的解释器实现 2 | * 等待更新 3 | 4 | 5 | --------------------------------------------------------------------------------