Clang Useful Building Useful Tools With LLVM and Clang For Fun and Profit Peter Goldsborough Cppnow 05-20-2017
Clang Useful Building Useful Tools With LLVM and Clang For Fun and Profit Peter Goldsborough Cppnow 05-20-2017
Clang Useful Building Useful Tools With LLVM and Clang For Fun and Profit Peter Goldsborough Cppnow 05-20-2017
/clang-talk
TUFaceBloomGoogleStartupMIT
Frontend
Frontend Optimizer
C++
Go Optimizer Backend
Rust
C++ x86
Go Optimizer ARM
Rust RISC-V
Lexer
Optimizer Backend
Parser
Frontend
.c,.h
Lexer
Backend
Parser
Frontend Optimizer
.c,.h .ll,.bc
licm loop-unroll
Lexer
Backend
Parser
constprop inline
Frontend Optimizer
.c,.h .ll,.bc
licm loop-unroll
Lexer CodeGen
MD
Parser
constprop inline Optimizer
licm loop-unroll
Lexer CodeGen
MD
Parser
constprop inline Optimizer
template<typename C>
struct L {
char a();
void n(int) const;
bool g;
};
less greater
keyword keyword keyword
identifier
CXXMethodDecl
CXXMethodDecl
CXXMethodDecl
CXXMethodDecl
Type
CXXRecordDecl
CXXMethodDecl
Type
TranslationUnitDecl
CXXRecordDecl
CXXMethodDecl
Type
TranslationUnitDecl
CXXRecordDecl
CXXMethodDecl
AST
AST
if (0xc > l) {
const char* a = "ng";
}
if (0xc > l) {
const char* a = "ng";
}
Stmt
if (0xc > l) {
const char* a = "ng";
}
Stmt Decl
if (0xc > l) {
const char* a = "ng";
}
if (0xc > l) {
const char* a = "ng";
}
libClang
#include <stdio.h>
#include <clang-c/Index.h>
CXChildVisitResult
visit(CXCursor cursor, CXCursor, CXClientData data) {
const CXSourceLocation location = clang_getCursorLocation(cursor);
if (!clang_Location_isFromMainFile(location)) {
return CXChildVisit_Continue;
}
return CXChildVisit_Recurse;
}
def walk(cursor):
print(cursor.spelling)
for child in cursor.get_children():
walk(child)
libTooling
Clang Tidy
./clang-tidy -checks="*,my-check" file.cpp
Clang Tidy
./clang-tidy -checks="*,my-check" file.cpp
Clang Plugin
./clang++ -Xclang load -Xclang my-check.so \
-Xclang -add-plugin -Xclang my-check file.cpp
Clang Tidy
./clang-tidy -checks="*,my-check" file.cpp
Clang Plugin
./clang++ -Xclang load -Xclang my-check.so \
-Xclang -add-plugin -Xclang my-check file.cpp
Clang Tool
./my-check file.cpp
I eli.thegreenplace.net
I clang.llvm.org/docs/InternalsManual.html
I llvm.org/docs/ProgrammersManual.html
I goldsborough.me & github.com/goldsborough
I Source Code!
I eli.thegreenplace.net
I clang.llvm.org/docs/InternalsManual.html
I llvm.org/docs/ProgrammersManual.html
I goldsborough.me & github.com/goldsborough
I Source Code!
github.com/peter-can-talk/cppnow-2017