SlideShare ist ein Scribd-Unternehmen logo
1 von 32
Downloaden Sie, um offline zu lesen
Clang:
A New Tool for Old Languages
        MORITA Hajime <omo@dodgson.org>
                    http://steps.dodgson.org/
                                  2009/03/21




                                            1
//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//
                                                  Chris Lattner

I. Introduction:

clang: noun
  1. A loud, resonant, metallic sound.
  2. The strident call of a crane or goose.
  3. C-language family front-end toolkit.

                                    http://llvm.org/svn/llvm-project/cfe/trunk/README.txt
• Clang       ?

•         ?




                  3
• Clang       ?

•         ?




                  4
//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//
                                                  Chris Lattner

I. Introduction:

clang: noun
  1. A loud, resonant, metallic sound.
  2. The strident call of a crane or goose.
  3. C-language family front-end toolkit.

                                    http://llvm.org/svn/llvm-project/cfe/trunk/README.txt
//===----------------------------------------------------------------------===//
// C Language Family Front-end
//===----------------------------------------------------------------------===//
                                                  Chris Lattner

I. Introduction:

clang: noun
  1. A loud, resonant, metallic sound.
  2. The strident call of a crane or goose.
  3. C-language family front-end toolkit.

                                    http://llvm.org/svn/llvm-project/cfe/trunk/README.txt
C/C++/Obj-C

• LLVM.org
• 2006
• written in C++
                   6
C/C++/Obj-C


•             LLVM

• Apple
•                    (as LLVM)

•                (as LLVM)
                                 7
LLVM

•
•
•
• JIT
               8
Apple

•
    • gcc    (           )

    • MSVC       (   )

•
                             9
•
    •
    •
    • AST
•
•           10
Frontend
                Lex


                                         Driver
Basic           Parse
                        CodeGen
LLVM/
                Sema                     LLVM
System
                        Analysis

                AST
                                   Rewrite

         Core                      App
                                                  11
Core 1/5:
clang/Basic
•         I/O (+          )

•
•
    •
•       basic      LLVM

                              12
Core 2/5:                                  Token


 clang/Lex                   Preprocessor
                                                    Preprocessor
                                Lexer



• Lexer, Token, Preprocessor, ...
• Lexer:                 Lexer         PTHLexer


  • pull style: Lexer::Lex(Token& result);
  • hand-written
•                                 (:     )

• PTH(Preprocessed-Token-Header)
                                                        13
Core 3/5:
clang/Parse
                                    Token


• Parser, Action, ....
• Parser:            Preprocessor           Parser   Action


 • push-style
 • C/C++/Obj-C               (!)



                                                      14
Core 4/5:
    clang/Sema
                       Parser     Action


•   ParseAST(Preprocessor &PP,               AST
             ASTConsumer *Consumer,        Consumer
             TranslationUnit *TU,
                                  Sema
             bool PrintStats);
                                           Translation

    • Sema : public Action                    Unit


     • callback+Token→AST
                                               15
Core 5/5:
                     Translation      AST
                        Unit         Context



clang/AST                     Type    Decl     Expr




• Decl :
 • VarDecl, FunctionDecl, CXXRecordDecl, ...
• Type :
 • QualType, BuiltinType, ComplexType, ...
• Expr :
 • DeclRefExpr, IntegerLiteral, UnaryOperator, ...
                                               16
Decl
                                            Type

              NamedDecl

                                          QualType
DeclContext    ValueDecl
                              ParmVar
                                Decl
              FunctionDecl
                                Stmt        Expr
                 CXX
              MethodDecl        CXX
                             RecordDecl


                                                     17
App libraries
• Analysis:
 •
• Rewrite:
 •             (Rope, DeltaTree)

 • Obj-C → C
 • HTML
• AST
                                   18
• Clang       ?

•         ?




                  19
•
    (       )

•
    (   )



                20
•
                         OK: Driver/clang.cpp

•
    • ASTConsumer
    • DiagnosticClient
•
                                                21
:   main()
               :
- #include-s
-




                            22
#include-s:
              #include   <vector>
              #include   <string>
              #include   <iosfwd>
              #include   <llvm/Support/raw_ostream.h>
              #include   <clang/Frontend/CompileOptions.h>
              #include   <clang/Frontend/PathDiagnosticClients.h>
              #include   <clang/Frontend/InitHeaderSearch.h>
              #include   <clang/Frontend/TextDiagnosticBuffer.h>
              #include   <clang/Frontend/TextDiagnosticPrinter.h>
              #include   <clang/Analysis/PathDiagnostic.h>
              #include   <clang/AST/Decl.h>
              #include   <clang/AST/DeclCXX.h>
              #include   <clang/AST/TranslationUnit.h>
              #include   <clang/CodeGen/ModuleBuilder.h>
              #include   <clang/Sema/ParseAST.h>
              #include   <clang/Sema/SemaDiagnostic.h>
              #include   <clang/AST/ASTConsumer.h>
              #include   <clang/Parse/Parser.h>
              #include   <clang/Lex/HeaderSearch.h>
              #include   <clang/Lex/LexDiagnostic.h>
              #include   <clang/Basic/FileManager.h>



•
              #include   <clang/Basic/SourceManager.h>
              #include   <clang/Basic/TargetInfo.h>
              #include   <clang/Basic/Diagnostic.h>
              #include   <llvm/ADT/OwningPtr.h>
              #include   <llvm/ADT/SmallPtrSet.h>
              #include   <llvm/ADT/StringExtras.h>
              #include   <llvm/Config/config.h>
              #include   <llvm/Support/CommandLine.h>
              #include   <llvm/Support/ManagedStatic.h>
              #include   <llvm/Support/MemoryBuffer.h>
              #include   <llvm/Support/PluginLoader.h>
              #include   <llvm/Support/PrettyStackTrace.h>
              #include   <llvm/Support/Timer.h>
              #include   <llvm/System/Host.h>
              #include   <llvm/System/Path.h>
              #include   <llvm/System/Signals.h>
              #include   <iostream>




                                                         23
: ASTConsumer

• Driver/ASTConsumers.cpp
  • ASTDumper:
  • DeclContextPrinter: ( )
•                     :
  ↑

                               24
class DeclContextPrinter : public ASTConsumer {
  llvm::raw_ostream& Out;
public:
  DeclContextPrinter() : Out(llvm::errs()) {}

  void HandleTranslationUnit(TranslationUnit& TU) {
    TranslationUnitDecl* TUD =
       TU.getContext().getTranslationUnitDecl();
    PrintDeclContext(TUD, 4);
  }

  void PrintDeclContext(const DeclContext* DC, unsigned Indentation)
};




                                                        25
void DeclContextPrinter::PrintDeclContext(const DeclContext* DC,
                                          unsigned Indentation) {
  // Print DeclContext name.
  switch (DC->getDeclKind()) {
  case Decl::TranslationUnit:
    Out << quot;[translation unit] quot; << DC;
    break;
  case Decl::Namespace: {
    Out << quot;[namespace] quot;;
    const NamespaceDecl* ND = cast<NamespaceDecl>(DC);
    Out << ND->getNameAsString();
    break;
  }
  ...
  case Decl::CXXRecord: {
    const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC);
    if (RD->isDefinition())
      Out << quot;[class] quot;;
    else
      Out << quot;<class> quot;;
    Out << RD->getNameAsString() << quot; quot; << DC;
    break;
  }
  ...

                                                            26
AST
•                 /
    (better doxygen, GLOBAL, LXR, ...)
•
    (better/worse RPC, Serializer, SWIG, ...)
•                        ,
AST
•   AOP (                ,           , ....)


•
        http://people.imendio.com/richard/gtk-rewriter/

                                                     27
•                (   FS)

•       (                   )

•       (Lexer       )

• C++
• ...
                           28
5       C/Objc-C/C++

    •
    •             +

    •                       ?

    •                 (ry

                                29
Clang

• C++   C++                         !!!

•                       !!!

•        Apple!!!

  •                           !!!

                                    30
For more:
•   http://clang.llvm.org/get_started.html


•   http://llvm.org/devmtg/2008-08/Naroff_Clang.pdf


•   trunk/Driver/
    clang


•   http://www.flickr.com/photos/darrenhunter/2918246464/




                                                           31

Weitere ähnliche Inhalte

Was ist angesagt?

Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Mr. Vengineer
 
Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations DVClub
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4Linaro
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageablecorehard_by
 
Работа с реляционными базами данных в C++
Работа с реляционными базами данных в C++Работа с реляционными базами данных в C++
Работа с реляционными базами данных в C++corehard_by
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about CYi-Hsiu Hsu
 
Hands on clang-format
Hands on clang-formatHands on clang-format
Hands on clang-formatKai Wolf
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtoolingDouglas Chen
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesAndrey Karpov
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Mr. Vengineer
 
Let's talks about string operations in C++17
Let's talks about string operations in C++17Let's talks about string operations in C++17
Let's talks about string operations in C++17Bartlomiej Filipek
 
Fuzzing: The New Unit Testing
Fuzzing: The New Unit TestingFuzzing: The New Unit Testing
Fuzzing: The New Unit TestingDmitry Vyukov
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerAndrey Karpov
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaWei-Bo Chen
 
Bug fix sharing : where does bug come from
Bug fix sharing : where does bug come fromBug fix sharing : where does bug come from
Bug fix sharing : where does bug come from宇 申
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - OverviewBartlomiej Filipek
 

Was ist angesagt? (20)

Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)Bridge TensorFlow to run on Intel nGraph backends (v0.4)
Bridge TensorFlow to run on Intel nGraph backends (v0.4)
 
TVM VTA (TSIM)
TVM VTA (TSIM) TVM VTA (TSIM)
TVM VTA (TSIM)
 
Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations Architecture for Massively Parallel HDL Simulations
Architecture for Massively Parallel HDL Simulations
 
HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4HKG15-211: Advanced Toolchain Usage Part 4
HKG15-211: Advanced Toolchain Usage Part 4
 
How to make a large C++-code base manageable
How to make a large C++-code base manageableHow to make a large C++-code base manageable
How to make a large C++-code base manageable
 
GCC RTL and Machine Description
GCC RTL and Machine DescriptionGCC RTL and Machine Description
GCC RTL and Machine Description
 
Работа с реляционными базами данных в C++
Работа с реляционными базами данных в C++Работа с реляционными базами данных в C++
Работа с реляционными базами данных в C++
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
Hands on clang-format
Hands on clang-formatHands on clang-format
Hands on clang-format
 
[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling[COSCUP 2020] How to use llvm frontend library-libtooling
[COSCUP 2020] How to use llvm frontend library-libtooling
 
Best Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' MistakesBest Bugs from Games: Fellow Programmers' Mistakes
Best Bugs from Games: Fellow Programmers' Mistakes
 
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)Bridge TensorFlow to run on Intel nGraph backends (v0.5)
Bridge TensorFlow to run on Intel nGraph backends (v0.5)
 
TensorFlow XLA RPC
TensorFlow XLA RPCTensorFlow XLA RPC
TensorFlow XLA RPC
 
Let's talks about string operations in C++17
Let's talks about string operations in C++17Let's talks about string operations in C++17
Let's talks about string operations in C++17
 
Fuzzing: The New Unit Testing
Fuzzing: The New Unit TestingFuzzing: The New Unit Testing
Fuzzing: The New Unit Testing
 
Vocabulary Types in C++17
Vocabulary Types in C++17Vocabulary Types in C++17
Vocabulary Types in C++17
 
C++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical ReviewerC++ Code as Seen by a Hypercritical Reviewer
C++ Code as Seen by a Hypercritical Reviewer
 
Triton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON ChinaTriton and Symbolic execution on GDB@DEF CON China
Triton and Symbolic execution on GDB@DEF CON China
 
Bug fix sharing : where does bug come from
Bug fix sharing : where does bug come fromBug fix sharing : where does bug come from
Bug fix sharing : where does bug come from
 
C++17 std::filesystem - Overview
C++17 std::filesystem - OverviewC++17 std::filesystem - Overview
C++17 std::filesystem - Overview
 

Ähnlich wie clang-intro

Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angelibergonio11339481
 
TAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS - The Language Data Network
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAsGokhan Atil
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Community
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Ary Borenszweig
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Ary Borenszweig
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)Crystal Language
 
Mining Version Archives for Co-changed Lines
Mining Version Archives for Co-changed LinesMining Version Archives for Co-changed Lines
Mining Version Archives for Co-changed LinesThomas Zimmermann
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会Ippei Ogiwara
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart PointersCarlo Pescio
 
Владимир Перепелица "Модули"
Владимир Перепелица "Модули"Владимир Перепелица "Модули"
Владимир Перепелица "Модули"Media Gorod
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsOWASP Kyiv
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersKirk Kimmel
 

Ähnlich wie clang-intro (20)

Fundamentals of programming angeli
Fundamentals of programming angeliFundamentals of programming angeli
Fundamentals of programming angeli
 
Os Wilhelm
Os WilhelmOs Wilhelm
Os Wilhelm
 
Osol Pgsql
Osol PgsqlOsol Pgsql
Osol Pgsql
 
TAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memoriesTAUS USER CONFERENCE 2009, Normalization of translation memories
TAUS USER CONFERENCE 2009, Normalization of translation memories
 
Essential Linux Commands for DBAs
Essential Linux Commands for DBAsEssential Linux Commands for DBAs
Essential Linux Commands for DBAs
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Ui disk & terminal drivers
Ui disk & terminal driversUi disk & terminal drivers
Ui disk & terminal drivers
 
Mining Version Archives for Co-changed Lines
Mining Version Archives for Co-changed LinesMining Version Archives for Co-changed Lines
Mining Version Archives for Co-changed Lines
 
Debugging TV Frame 0x13
Debugging TV Frame 0x13Debugging TV Frame 0x13
Debugging TV Frame 0x13
 
第1回PHP拡張勉強会
第1回PHP拡張勉強会第1回PHP拡張勉強会
第1回PHP拡張勉強会
 
A Life of breakpoint
A Life of breakpointA Life of breakpoint
A Life of breakpoint
 
(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers(Slightly) Smarter Smart Pointers
(Slightly) Smarter Smart Pointers
 
Meta Object Protocols
Meta Object ProtocolsMeta Object Protocols
Meta Object Protocols
 
Bioinformatica p4-io
Bioinformatica p4-ioBioinformatica p4-io
Bioinformatica p4-io
 
Владимир Перепелица "Модули"
Владимир Перепелица "Модули"Владимир Перепелица "Модули"
Владимир Перепелица "Модули"
 
Andriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tipsAndriy Shalaenko - GO security tips
Andriy Shalaenko - GO security tips
 
Perl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one linersPerl - laziness, impatience, hubris, and one liners
Perl - laziness, impatience, hubris, and one liners
 

Mehr von Hajime Morrita

How I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHow I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHajime Morrita
 
Binaries Are Not Only Output
Binaries Are Not Only OutputBinaries Are Not Only Output
Binaries Are Not Only OutputHajime Morrita
 

Mehr von Hajime Morrita (6)

On Web Browsers
On Web BrowsersOn Web Browsers
On Web Browsers
 
How I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTreeHow I stopped worrying about and loved DumpRenderTree
How I stopped worrying about and loved DumpRenderTree
 
Binaries Are Not Only Output
Binaries Are Not Only OutputBinaries Are Not Only Output
Binaries Are Not Only Output
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
devsummit2009js
devsummit2009jsdevsummit2009js
devsummit2009js
 
object-shapes
object-shapesobject-shapes
object-shapes
 

Kürzlich hochgeladen

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 

Kürzlich hochgeladen (20)

SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 

clang-intro

  • 1. Clang: A New Tool for Old Languages MORITA Hajime <omo@dodgson.org> http://steps.dodgson.org/ 2009/03/21 1
  • 2. //===----------------------------------------------------------------------===// // C Language Family Front-end //===----------------------------------------------------------------------===// Chris Lattner I. Introduction: clang: noun 1. A loud, resonant, metallic sound. 2. The strident call of a crane or goose. 3. C-language family front-end toolkit. http://llvm.org/svn/llvm-project/cfe/trunk/README.txt
  • 3. • Clang ? • ? 3
  • 4. • Clang ? • ? 4
  • 5. //===----------------------------------------------------------------------===// // C Language Family Front-end //===----------------------------------------------------------------------===// Chris Lattner I. Introduction: clang: noun 1. A loud, resonant, metallic sound. 2. The strident call of a crane or goose. 3. C-language family front-end toolkit. http://llvm.org/svn/llvm-project/cfe/trunk/README.txt
  • 6. //===----------------------------------------------------------------------===// // C Language Family Front-end //===----------------------------------------------------------------------===// Chris Lattner I. Introduction: clang: noun 1. A loud, resonant, metallic sound. 2. The strident call of a crane or goose. 3. C-language family front-end toolkit. http://llvm.org/svn/llvm-project/cfe/trunk/README.txt
  • 8. C/C++/Obj-C • LLVM • Apple • (as LLVM) • (as LLVM) 7
  • 10. Apple • • gcc ( ) • MSVC ( ) • 9
  • 11. • • • AST • • 10
  • 12. Frontend Lex Driver Basic Parse CodeGen LLVM/ Sema LLVM System Analysis AST Rewrite Core App 11
  • 13. Core 1/5: clang/Basic • I/O (+ ) • • • • basic LLVM 12
  • 14. Core 2/5: Token clang/Lex Preprocessor Preprocessor Lexer • Lexer, Token, Preprocessor, ... • Lexer: Lexer PTHLexer • pull style: Lexer::Lex(Token& result); • hand-written • (: ) • PTH(Preprocessed-Token-Header) 13
  • 15. Core 3/5: clang/Parse Token • Parser, Action, .... • Parser: Preprocessor Parser Action • push-style • C/C++/Obj-C (!) 14
  • 16. Core 4/5: clang/Sema Parser Action • ParseAST(Preprocessor &PP, AST ASTConsumer *Consumer, Consumer TranslationUnit *TU, Sema bool PrintStats); Translation • Sema : public Action Unit • callback+Token→AST 15
  • 17. Core 5/5: Translation AST Unit Context clang/AST Type Decl Expr • Decl : • VarDecl, FunctionDecl, CXXRecordDecl, ... • Type : • QualType, BuiltinType, ComplexType, ... • Expr : • DeclRefExpr, IntegerLiteral, UnaryOperator, ... 16
  • 18. Decl Type NamedDecl QualType DeclContext ValueDecl ParmVar Decl FunctionDecl Stmt Expr CXX MethodDecl CXX RecordDecl 17
  • 19. App libraries • Analysis: • • Rewrite: • (Rope, DeltaTree) • Obj-C → C • HTML • AST 18
  • 20. • Clang ? • ? 19
  • 21. ( ) • ( ) 20
  • 22. OK: Driver/clang.cpp • • ASTConsumer • DiagnosticClient • 21
  • 23. : main() : - #include-s - 22
  • 24. #include-s: #include <vector> #include <string> #include <iosfwd> #include <llvm/Support/raw_ostream.h> #include <clang/Frontend/CompileOptions.h> #include <clang/Frontend/PathDiagnosticClients.h> #include <clang/Frontend/InitHeaderSearch.h> #include <clang/Frontend/TextDiagnosticBuffer.h> #include <clang/Frontend/TextDiagnosticPrinter.h> #include <clang/Analysis/PathDiagnostic.h> #include <clang/AST/Decl.h> #include <clang/AST/DeclCXX.h> #include <clang/AST/TranslationUnit.h> #include <clang/CodeGen/ModuleBuilder.h> #include <clang/Sema/ParseAST.h> #include <clang/Sema/SemaDiagnostic.h> #include <clang/AST/ASTConsumer.h> #include <clang/Parse/Parser.h> #include <clang/Lex/HeaderSearch.h> #include <clang/Lex/LexDiagnostic.h> #include <clang/Basic/FileManager.h> • #include <clang/Basic/SourceManager.h> #include <clang/Basic/TargetInfo.h> #include <clang/Basic/Diagnostic.h> #include <llvm/ADT/OwningPtr.h> #include <llvm/ADT/SmallPtrSet.h> #include <llvm/ADT/StringExtras.h> #include <llvm/Config/config.h> #include <llvm/Support/CommandLine.h> #include <llvm/Support/ManagedStatic.h> #include <llvm/Support/MemoryBuffer.h> #include <llvm/Support/PluginLoader.h> #include <llvm/Support/PrettyStackTrace.h> #include <llvm/Support/Timer.h> #include <llvm/System/Host.h> #include <llvm/System/Path.h> #include <llvm/System/Signals.h> #include <iostream> 23
  • 25. : ASTConsumer • Driver/ASTConsumers.cpp • ASTDumper: • DeclContextPrinter: ( ) • : ↑ 24
  • 26. class DeclContextPrinter : public ASTConsumer { llvm::raw_ostream& Out; public: DeclContextPrinter() : Out(llvm::errs()) {} void HandleTranslationUnit(TranslationUnit& TU) { TranslationUnitDecl* TUD = TU.getContext().getTranslationUnitDecl(); PrintDeclContext(TUD, 4); } void PrintDeclContext(const DeclContext* DC, unsigned Indentation) }; 25
  • 27. void DeclContextPrinter::PrintDeclContext(const DeclContext* DC, unsigned Indentation) { // Print DeclContext name. switch (DC->getDeclKind()) { case Decl::TranslationUnit: Out << quot;[translation unit] quot; << DC; break; case Decl::Namespace: { Out << quot;[namespace] quot;; const NamespaceDecl* ND = cast<NamespaceDecl>(DC); Out << ND->getNameAsString(); break; } ... case Decl::CXXRecord: { const CXXRecordDecl* RD = cast<CXXRecordDecl>(DC); if (RD->isDefinition()) Out << quot;[class] quot;; else Out << quot;<class> quot;; Out << RD->getNameAsString() << quot; quot; << DC; break; } ... 26
  • 28. AST • / (better doxygen, GLOBAL, LXR, ...) • (better/worse RPC, Serializer, SWIG, ...) • , AST • AOP ( , , ....) • http://people.imendio.com/richard/gtk-rewriter/ 27
  • 29. ( FS) • ( ) • (Lexer ) • C++ • ... 28
  • 30. 5 C/Objc-C/C++ • • + • ? • (ry 29
  • 31. Clang • C++ C++ !!! • !!! • Apple!!! • !!! 30
  • 32. For more: • http://clang.llvm.org/get_started.html • http://llvm.org/devmtg/2008-08/Naroff_Clang.pdf • trunk/Driver/ clang • http://www.flickr.com/photos/darrenhunter/2918246464/ 31