SlideShare a Scribd company logo
llvm-py: Writing Compilers Using Python
                    PyCon India 2010


                    Mahadevan R
                 mdevan@mdevan.org



                  September 25, 2010




Mahadevan R    llvm-py: Writing Compilers Using Python   September 25, 2010   1 / 14
About This Talk

Outline
  Compilers overview, some terminology
      LLVM about the “Low Level Virtual Machine”
    llvm-py Python bindings for LLVM


About me:
    Open source developer
    Day job is as a software architect (medical imaging)
    Started my career in 1999; mostly C, C++, a little Python!
    ..also the author of llvm-py.


      Mahadevan R        llvm-py: Writing Compilers Using Python   September 25, 2010   2 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers
   What is “something else?”




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers
   What is “something else?”
        Assembly language




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers
   What is “something else?”
        Assembly language
        Another well-structured textual representation (e.g. cfront)




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers
   What is “something else?”
        Assembly language
        Another well-structured textual representation (e.g. cfront)
        Intermediate, binary representation (AOT compilers)




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers
   What is “something else?”
        Assembly language
        Another well-structured textual representation (e.g. cfront)
        Intermediate, binary representation (AOT compilers)
        In-memory executable code (JIT compilers)




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    What is a Compiler?


What is a Compiler?


   What is a compiler?
        Something that transforms “source code” into “something else”
   What is “source code”?
        A well-structured, textual representation of a program
        Not: preprocessors, assemblers
   What is “something else?”
        Assembly language
        Another well-structured textual representation (e.g. cfront)
        Intermediate, binary representation (AOT compilers)
        In-memory executable code (JIT compilers)
        Executable images




     Mahadevan R         llvm-py: Writing Compilers Using Python    September 25, 2010   3 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens
    Parser eats tokens, produces AST




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens
    Parser eats tokens, produces AST
    What is an AST? And what is abstract about it?




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens
    Parser eats tokens, produces AST
    What is an AST? And what is abstract about it?
    What next after an AST?




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens
    Parser eats tokens, produces AST
    What is an AST? And what is abstract about it?
    What next after an AST?
    What is an intermediate form (IR)?




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens
    Parser eats tokens, produces AST
    What is an AST? And what is abstract about it?
    What next after an AST?
    What is an intermediate form (IR)?
    example: IRs in gcc: source → GENERIC → GIMPLE → RTL →
    backend




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Inside a Compiler


Inside a Compiler


What does the compiler do with the source code?
    Lexical analysis produces tokens
    Parser eats tokens, produces AST
    What is an AST? And what is abstract about it?
    What next after an AST?
    What is an intermediate form (IR)?
    example: IRs in gcc: source → GENERIC → GIMPLE → RTL →
    backend
    What is Static Single Assignment (SSA) form?




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   4 / 14
Compilers    Passes, Optimization and Code Generation


Passes, Optimization and Code Generation




   What is a “pass”?




     Mahadevan R       llvm-py: Writing Compilers Using Python            September 25, 2010   5 / 14
Compilers    Passes, Optimization and Code Generation


Passes, Optimization and Code Generation




   What is a “pass”?
   What is a “optimization”?




     Mahadevan R       llvm-py: Writing Compilers Using Python            September 25, 2010   5 / 14
Compilers    Passes, Optimization and Code Generation


Passes, Optimization and Code Generation




   What is a “pass”?
   What is a “optimization”?
   What is a “code generator”?




     Mahadevan R       llvm-py: Writing Compilers Using Python            September 25, 2010   5 / 14
Compilers    Passes, Optimization and Code Generation


Passes, Optimization and Code Generation




   What is a “pass”?
   What is a “optimization”?
   What is a “code generator”?
   What is a “code generator generator”?




     Mahadevan R       llvm-py: Writing Compilers Using Python            September 25, 2010   5 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)
   To build a front end in Python:




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)
   To build a front end in Python:
        hand-coded lexer, (rec-desc) parser




     Mahadevan R         llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)
   To build a front end in Python:
        hand-coded lexer, (rec-desc) parser
        Antlr (generates Python)




     Mahadevan R         llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)
   To build a front end in Python:
        hand-coded lexer, (rec-desc) parser
        Antlr (generates Python)
        Yacc, Bison, Lemon (generates C, wrap to Python)




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)
   To build a front end in Python:
        hand-coded lexer, (rec-desc) parser
        Antlr (generates Python)
        Yacc, Bison, Lemon (generates C, wrap to Python)
        Sphinx (C++, wrap to Python)




     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
Compilers    The Frontend and The Backend


The Frontend and The Backend


   Everything before the first IR is usually called the frontend
   And everything after as the backend
   LLVM and llvm-py deal only with backends
   Frontends tend to be simpler
   Many frontends for a backend is common (Scala, Groovy, Clojure:
   Java; C#, IronPython, etc: .NET)
   To build a front end in Python:
        hand-coded lexer, (rec-desc) parser
        Antlr (generates Python)
        Yacc, Bison, Lemon (generates C, wrap to Python)
        Sphinx (C++, wrap to Python)
        various Python parser generators



     Mahadevan R        llvm-py: Writing Compilers Using Python             September 25, 2010   6 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:
        IR data structure, with text and binary representations




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:
        IR data structure, with text and binary representations
        wide range of optimizations




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:
        IR data structure, with text and binary representations
        wide range of optimizations
        code generator (partly description-based) for many platforms




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:
        IR data structure, with text and binary representations
        wide range of optimizations
        code generator (partly description-based) for many platforms
        JIT-compile-execute from IR




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:
        IR data structure, with text and binary representations
        wide range of optimizations
        code generator (partly description-based) for many platforms
        JIT-compile-execute from IR
        link-time optimization (LTO)




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      What is LLVM?


What is LLVM?



   Primarily a set of libraries..
   ..with which you can make a compiler backend..
   ..or a VM with JIT support (but hard to get this right)
   It provides:
        IR data structure, with text and binary representations
        wide range of optimizations
        code generator (partly description-based) for many platforms
        JIT-compile-execute from IR
        link-time optimization (LTO)
        support for accurate garbage collection




     Mahadevan R         llvm-py: Writing Compilers Using Python   September 25, 2010   7 / 14
LLVM      LLVM Highlights


LLVM Highlights



   Written in readable C++




     Mahadevan R     llvm-py: Writing Compilers Using Python   September 25, 2010   8 / 14
LLVM      LLVM Highlights


LLVM Highlights



   Written in readable C++
   Reasonable documentation, helpful and mature community




     Mahadevan R     llvm-py: Writing Compilers Using Python   September 25, 2010   8 / 14
LLVM      LLVM Highlights


LLVM Highlights



   Written in readable C++
   Reasonable documentation, helpful and mature community
   clang is a now-famous subproject of LLVM




     Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   8 / 14
LLVM      LLVM Highlights


LLVM Highlights



   Written in readable C++
   Reasonable documentation, helpful and mature community
   clang is a now-famous subproject of LLVM
   llvm-gcc is gcc frontend (C, C++, Java, Ada, Fortran, ObjC) +
   LLVM backend




     Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   8 / 14
LLVM      LLVM Highlights


LLVM Highlights



   Written in readable C++
   Reasonable documentation, helpful and mature community
   clang is a now-famous subproject of LLVM
   llvm-gcc is gcc frontend (C, C++, Java, Ada, Fortran, ObjC) +
   LLVM backend
   Many users: Unladen Swallow, Iced Tea, Rubinus, llvm-lua, GHC,
   LDC




     Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   8 / 14
LLVM      The LLVM IR


The LLVM IR

The IR looks like this (textual representation):

“Hello world” in LLVM Assembly
@msg = private constant [15 x i8 ] c " Hello , world !0 A 00"

declare i32 @puts ( i8 *)

define i32 @main ( i32 % argc , i8 ** % argv ) {
entry :
  %0 = getelementptr [15 x i8 ]* @msg , i64 0 , i64 0
  %1 = tail call i32 @puts ( i8 * %0)
  ret i32 undef
}



       Mahadevan R        llvm-py: Writing Compilers Using Python   September 25, 2010   9 / 14
LLVM      A Word About clang


A Word About clang



   A sub-project of the LLVM team




    Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   10 / 14
LLVM      A Word About clang


A Word About clang



   A sub-project of the LLVM team
   clang is a C, Objective C and C++ frontend




    Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   10 / 14
LLVM      A Word About clang


A Word About clang



   A sub-project of the LLVM team
   clang is a C, Objective C and C++ frontend
   works with the LLVM backend (obviously!)




    Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   10 / 14
LLVM      A Word About clang


A Word About clang



   A sub-project of the LLVM team
   clang is a C, Objective C and C++ frontend
   works with the LLVM backend (obviously!)

   It can convert C/ObjC/C++ code to LLVM IR




    Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   10 / 14
LLVM      A Word About clang


A Word About clang



   A sub-project of the LLVM team
   clang is a C, Objective C and C++ frontend
   works with the LLVM backend (obviously!)

   It can convert C/ObjC/C++ code to LLVM IR
   which can be played around with using llvm-py




    Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   10 / 14
LLVM      A Word About clang


A Word About clang



   A sub-project of the LLVM team
   clang is a C, Objective C and C++ frontend
   works with the LLVM backend (obviously!)

   It can convert C/ObjC/C++ code to LLVM IR
   which can be played around with using llvm-py
   and then compiled “normally”




    Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   10 / 14
llvm-py    What is llvm-py?


What is llvm-py?




   Python bindings for LLVM




     Mahadevan R     llvm-py: Writing Compilers Using Python   September 25, 2010   11 / 14
llvm-py    What is llvm-py?


What is llvm-py?




   Python bindings for LLVM
   Including JIT




     Mahadevan R     llvm-py: Writing Compilers Using Python   September 25, 2010   11 / 14
llvm-py    What is llvm-py?


What is llvm-py?




   Python bindings for LLVM
   Including JIT
   Excellent for experimenting and prototyping




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   11 / 14
llvm-py    What is llvm-py?


What is llvm-py?




   Python bindings for LLVM
   Including JIT
   Excellent for experimenting and prototyping
   Available in Ubuntu, Debian, MacPorts (but may be out of date)




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   11 / 14
llvm-py    What is llvm-py?


What is llvm-py?




   Python bindings for LLVM
   Including JIT
   Excellent for experimenting and prototyping
   Available in Ubuntu, Debian, MacPorts (but may be out of date)
   Current version (0.6) works with LLVM 2.7




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   11 / 14
llvm-py    More on llvm-py


More on llvm-py




   Covers most of the LLVM APIs, esp. IR




     Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   12 / 14
llvm-py    More on llvm-py


More on llvm-py




   Covers most of the LLVM APIs, esp. IR
   See examples to get started




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   12 / 14
llvm-py    More on llvm-py


More on llvm-py




   Covers most of the LLVM APIs, esp. IR
   See examples to get started
   User guide at http://www.mdevan.org/userguide.html




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   12 / 14
llvm-py    More on llvm-py


More on llvm-py




   Covers most of the LLVM APIs, esp. IR
   See examples to get started
   User guide at http://www.mdevan.org/userguide.html
   Some LLVM knowledge required: Modules, IR instructions, ...




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   12 / 14
llvm-py    More on llvm-py


More on llvm-py




   Covers most of the LLVM APIs, esp. IR
   See examples to get started
   User guide at http://www.mdevan.org/userguide.html
   Some LLVM knowledge required: Modules, IR instructions, ...
   Learning curve of LLVM is steep, llvm-py/Python helps!




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   12 / 14
llvm-py    More on llvm-py


More on llvm-py




   Covers most of the LLVM APIs, esp. IR
   See examples to get started
   User guide at http://www.mdevan.org/userguide.html
   Some LLVM knowledge required: Modules, IR instructions, ...
   Learning curve of LLVM is steep, llvm-py/Python helps!
   Users group: http://groups.google.com/group/llvm-py




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   12 / 14
llvm-py    llvm-py Internals


llvm-py Internals




    Wraps LLVM’s C API as a Python extension module




     Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   13 / 14
llvm-py    llvm-py Internals


llvm-py Internals




    Wraps LLVM’s C API as a Python extension module
    Extends LLVM C API as it is incomplete




     Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   13 / 14
llvm-py    llvm-py Internals


llvm-py Internals




    Wraps LLVM’s C API as a Python extension module
    Extends LLVM C API as it is incomplete
    Does not use binding generators (Boost.Python, swig etc)




      Mahadevan R      llvm-py: Writing Compilers Using Python   September 25, 2010   13 / 14
llvm-py    llvm-py Internals


llvm-py Internals




    Wraps LLVM’s C API as a Python extension module
    Extends LLVM C API as it is incomplete
    Does not use binding generators (Boost.Python, swig etc)
    Public APIs are in Python, use extension module internally




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   13 / 14
llvm-py    llvm-py Internals


llvm-py Internals




    Wraps LLVM’s C API as a Python extension module
    Extends LLVM C API as it is incomplete
    Does not use binding generators (Boost.Python, swig etc)
    Public APIs are in Python, use extension module internally
    Mostly straightforward Python, a little metaclass magic




      Mahadevan R       llvm-py: Writing Compilers Using Python   September 25, 2010   13 / 14
Thanks     References and Thanks


Thanks!




                       Thanks for listening!

   Must read: Steven S. Muchnick. Advanced Compiler Design &
   Implementation.
   Me: Mahadevan R, mdevan@mdevan.org, http://www.mdevan.org/




    Mahadevan R      llvm-py: Writing Compilers Using Python      September 25, 2010   14 / 14

More Related Content

What's hot

Towards easy program migration using language virtualization
 Towards easy program migration using language virtualization Towards easy program migration using language virtualization
Towards easy program migration using language virtualization
ESUG
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
BBDITM LUCKNOW
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler design
hari2010
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
Nico Ludwig
 
C++ to java
C++ to javaC++ to java
C++ to java
Ajmal Ak
 
Different phases of a compiler
Different phases of a compilerDifferent phases of a compiler
Different phases of a compiler
Sumit Sinha
 
C Sharp Jn
C Sharp JnC Sharp Jn
C Sharp Jn
guest58c84c
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
sonalikharade3
 
.Net platform an understanding
.Net platform an understanding.Net platform an understanding
.Net platform an understanding
Binu Bhasuran
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
Iffat Anjum
 
C++vs java
C++vs javaC++vs java
C++vs java
Pradeep wolf king
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
Mahesh Kumar Chelimilla
 
An Introduction to PC-Lint
An Introduction to PC-LintAn Introduction to PC-Lint
An Introduction to PC-Lint
Ralf Holly
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
lennartkats
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Charlie Gracie
 
Java vs .net
Java vs .netJava vs .net
Java vs .net
Tech_MX
 
Open arkcompiler
Open arkcompilerOpen arkcompiler
Open arkcompiler
yiwei yang
 
Tail Call Elimination in Open Smalltalk
Tail Call Elimination in Open SmalltalkTail Call Elimination in Open Smalltalk
Tail Call Elimination in Open Smalltalk
ESUG
 
CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorial
Remedy IT
 

What's hot (19)

Towards easy program migration using language virtualization
 Towards easy program migration using language virtualization Towards easy program migration using language virtualization
Towards easy program migration using language virtualization
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Cs6660 compiler design
Cs6660 compiler designCs6660 compiler design
Cs6660 compiler design
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
C++ to java
C++ to javaC++ to java
C++ to java
 
Different phases of a compiler
Different phases of a compilerDifferent phases of a compiler
Different phases of a compiler
 
C Sharp Jn
C Sharp JnC Sharp Jn
C Sharp Jn
 
COMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONSCOMPILER DESIGN OPTIONS
COMPILER DESIGN OPTIONS
 
.Net platform an understanding
.Net platform an understanding.Net platform an understanding
.Net platform an understanding
 
Lecture 01 introduction to compiler
Lecture 01 introduction to compilerLecture 01 introduction to compiler
Lecture 01 introduction to compiler
 
C++vs java
C++vs javaC++vs java
C++vs java
 
Lecture1 introduction compilers
Lecture1 introduction compilersLecture1 introduction compilers
Lecture1 introduction compilers
 
An Introduction to PC-Lint
An Introduction to PC-LintAn Introduction to PC-Lint
An Introduction to PC-Lint
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
 
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot RuntimesJfokus 2016 - A JVMs Journey into Polyglot Runtimes
Jfokus 2016 - A JVMs Journey into Polyglot Runtimes
 
Java vs .net
Java vs .netJava vs .net
Java vs .net
 
Open arkcompiler
Open arkcompilerOpen arkcompiler
Open arkcompiler
 
Tail Call Elimination in Open Smalltalk
Tail Call Elimination in Open SmalltalkTail Call Elimination in Open Smalltalk
Tail Call Elimination in Open Smalltalk
 
CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorial
 

Viewers also liked

Pnomics-2015-FINAL-kbs
Pnomics-2015-FINAL-kbsPnomics-2015-FINAL-kbs
Pnomics-2015-FINAL-kbs
Katherine Schuetz
 
Sequence learning under incidental conditions [poster]
Sequence learning under incidental conditions [poster]Sequence learning under incidental conditions [poster]
Sequence learning under incidental conditions [poster]
Fayme Yeates
 
CogSci2014-kbs-2
CogSci2014-kbs-2CogSci2014-kbs-2
CogSci2014-kbs-2
Katherine Schuetz
 
Writing Parsers and Compilers with PLY
Writing Parsers and Compilers with PLYWriting Parsers and Compilers with PLY
Writing Parsers and Compilers with PLY
David Beazley (Dabeaz LLC)
 
Cognitive Science in Virtual Worlds
Cognitive Science in Virtual WorldsCognitive Science in Virtual Worlds
Cognitive Science in Virtual Worlds
bangor
 
Quoc Le, Software Engineer, Google at MLconf SF
Quoc Le, Software Engineer, Google at MLconf SFQuoc Le, Software Engineer, Google at MLconf SF
Quoc Le, Software Engineer, Google at MLconf SF
MLconf
 
Deep Recurrent Neural Networks for Sequence Learning in Spark by Yves Mabiala
Deep Recurrent Neural Networks for Sequence Learning in Spark by Yves MabialaDeep Recurrent Neural Networks for Sequence Learning in Spark by Yves Mabiala
Deep Recurrent Neural Networks for Sequence Learning in Spark by Yves Mabiala
Spark Summit
 

Viewers also liked (7)

Pnomics-2015-FINAL-kbs
Pnomics-2015-FINAL-kbsPnomics-2015-FINAL-kbs
Pnomics-2015-FINAL-kbs
 
Sequence learning under incidental conditions [poster]
Sequence learning under incidental conditions [poster]Sequence learning under incidental conditions [poster]
Sequence learning under incidental conditions [poster]
 
CogSci2014-kbs-2
CogSci2014-kbs-2CogSci2014-kbs-2
CogSci2014-kbs-2
 
Writing Parsers and Compilers with PLY
Writing Parsers and Compilers with PLYWriting Parsers and Compilers with PLY
Writing Parsers and Compilers with PLY
 
Cognitive Science in Virtual Worlds
Cognitive Science in Virtual WorldsCognitive Science in Virtual Worlds
Cognitive Science in Virtual Worlds
 
Quoc Le, Software Engineer, Google at MLconf SF
Quoc Le, Software Engineer, Google at MLconf SFQuoc Le, Software Engineer, Google at MLconf SF
Quoc Le, Software Engineer, Google at MLconf SF
 
Deep Recurrent Neural Networks for Sequence Learning in Spark by Yves Mabiala
Deep Recurrent Neural Networks for Sequence Learning in Spark by Yves MabialaDeep Recurrent Neural Networks for Sequence Learning in Spark by Yves Mabiala
Deep Recurrent Neural Networks for Sequence Learning in Spark by Yves Mabiala
 

Similar to llvm-py: Writing Compilers In Python

Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
Biswajeet Dasmajumdar
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP code
Gabriele Santini
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
Mattupallipardhu
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
Laxman Puri
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
ZENUS INFOTECH INDIA PVT. LTD.
 
F# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformF# Type Provider for R Statistical Platform
F# Type Provider for R Statistical Platform
Howard Mansell
 
Py Con 2009 Pumping Iron Into Python
Py Con 2009   Pumping Iron Into PythonPy Con 2009   Pumping Iron Into Python
Py Con 2009 Pumping Iron Into Python
Sarah Dutkiewicz
 
Source-to-Source Compiler
Source-to-Source CompilerSource-to-Source Compiler
Source-to-Source Compiler
Mintoo Jakhmola
 
Chapter One
Chapter OneChapter One
Chapter One
bolovv
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
Ranjith kumar
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
Swarit Wadhe
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
abdulbaki3
 
Chapter - 1.pptx
Chapter - 1.pptxChapter - 1.pptx
Chapter - 1.pptx
MikialeTesfamariam
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For Managers
Atul Shridhar
 
Ch1
Ch1Ch1
Intro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdfIntro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdf
ssuser543728
 
Python Programming
Python ProgrammingPython Programming
Python Programming
sameer patil
 
Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Language
anaveenkumar4
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docx
Manohar k
 
Introduction python
Introduction pythonIntroduction python
Introduction python
Jumbo Techno e_Learning
 

Similar to llvm-py: Writing Compilers In Python (20)

Introduction To Python
Introduction To PythonIntroduction To Python
Introduction To Python
 
Listen and look at your PHP code
Listen and look at your PHP codeListen and look at your PHP code
Listen and look at your PHP code
 
Pyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdfPyhton-1a-Basics.pdf
Pyhton-1a-Basics.pdf
 
Python Programming Language
Python Programming LanguagePython Programming Language
Python Programming Language
 
Introduction of Python
Introduction of PythonIntroduction of Python
Introduction of Python
 
F# Type Provider for R Statistical Platform
F# Type Provider for R Statistical PlatformF# Type Provider for R Statistical Platform
F# Type Provider for R Statistical Platform
 
Py Con 2009 Pumping Iron Into Python
Py Con 2009   Pumping Iron Into PythonPy Con 2009   Pumping Iron Into Python
Py Con 2009 Pumping Iron Into Python
 
Source-to-Source Compiler
Source-to-Source CompilerSource-to-Source Compiler
Source-to-Source Compiler
 
Chapter One
Chapter OneChapter One
Chapter One
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python - An Introduction
Python - An IntroductionPython - An Introduction
Python - An Introduction
 
Chapter#01 cc
Chapter#01 ccChapter#01 cc
Chapter#01 cc
 
Chapter - 1.pptx
Chapter - 1.pptxChapter - 1.pptx
Chapter - 1.pptx
 
Python Intro For Managers
Python Intro For ManagersPython Intro For Managers
Python Intro For Managers
 
Ch1
Ch1Ch1
Ch1
 
Intro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdfIntro-to-Python-Part-1-first-part-edition.pdf
Intro-to-Python-Part-1-first-part-edition.pdf
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Python Tutorial | Python Programming Language
Python Tutorial | Python Programming LanguagePython Tutorial | Python Programming Language
Python Tutorial | Python Programming Language
 
Python Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docxPython Programming and ApplicationsUnit-1.docx
Python Programming and ApplicationsUnit-1.docx
 
Introduction python
Introduction pythonIntroduction python
Introduction python
 

Recently uploaded

High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
Vadym Kazulkin
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
DanBrown980551
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
christinelarrosa
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
Miro Wengner
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
ScyllaDB
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
christinelarrosa
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
Jason Yip
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
Javier Junquera
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
ScyllaDB
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
UiPathCommunity
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
c5vrf27qcz
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
Alex Pruden
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
Fwdays
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
Fwdays
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
Enterprise Knowledge
 

Recently uploaded (20)

High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024High performance Serverless Java on AWS- GoTo Amsterdam 2024
High performance Serverless Java on AWS- GoTo Amsterdam 2024
 
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
LF Energy Webinar: Carbon Data Specifications: Mechanisms to Improve Data Acc...
 
Christine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptxChristine's Product Research Presentation.pptx
Christine's Product Research Presentation.pptx
 
JavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green MasterplanJavaLand 2024: Application Development Green Masterplan
JavaLand 2024: Application Development Green Masterplan
 
A Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's ArchitectureA Deep Dive into ScyllaDB's Architecture
A Deep Dive into ScyllaDB's Architecture
 
Christine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptxChristine's Supplier Sourcing Presentaion.pptx
Christine's Supplier Sourcing Presentaion.pptx
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance PanelsNorthern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
Northern Engraving | Modern Metal Trim, Nameplates and Appliance Panels
 
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
[OReilly Superstream] Occupy the Space: A grassroots guide to engineering (an...
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 
GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)GNSS spoofing via SDR (Criptored Talks 2024)
GNSS spoofing via SDR (Criptored Talks 2024)
 
ScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking ReplicationScyllaDB Tablets: Rethinking Replication
ScyllaDB Tablets: Rethinking Replication
 
Session 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdfSession 1 - Intro to Robotic Process Automation.pdf
Session 1 - Intro to Robotic Process Automation.pdf
 
The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
Y-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PPY-Combinator seed pitch deck template PP
Y-Combinator seed pitch deck template PP
 
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
zkStudyClub - LatticeFold: A Lattice-based Folding Scheme and its Application...
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba"NATO Hackathon Winner: AI-Powered Drug Search",  Taras Kloba
"NATO Hackathon Winner: AI-Powered Drug Search", Taras Kloba
 
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
"Scaling RAG Applications to serve millions of users",  Kevin Goedecke"Scaling RAG Applications to serve millions of users",  Kevin Goedecke
"Scaling RAG Applications to serve millions of users", Kevin Goedecke
 
Demystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through StorytellingDemystifying Knowledge Management through Storytelling
Demystifying Knowledge Management through Storytelling
 

llvm-py: Writing Compilers In Python

  • 1. llvm-py: Writing Compilers Using Python PyCon India 2010 Mahadevan R mdevan@mdevan.org September 25, 2010 Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 1 / 14
  • 2. About This Talk Outline Compilers overview, some terminology LLVM about the “Low Level Virtual Machine” llvm-py Python bindings for LLVM About me: Open source developer Day job is as a software architect (medical imaging) Started my career in 1999; mostly C, C++, a little Python! ..also the author of llvm-py. Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 2 / 14
  • 3. Compilers What is a Compiler? What is a Compiler? What is a compiler? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 4. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 5. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 6. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 7. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 8. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers What is “something else?” Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 9. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers What is “something else?” Assembly language Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 10. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers What is “something else?” Assembly language Another well-structured textual representation (e.g. cfront) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 11. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers What is “something else?” Assembly language Another well-structured textual representation (e.g. cfront) Intermediate, binary representation (AOT compilers) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 12. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers What is “something else?” Assembly language Another well-structured textual representation (e.g. cfront) Intermediate, binary representation (AOT compilers) In-memory executable code (JIT compilers) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 13. Compilers What is a Compiler? What is a Compiler? What is a compiler? Something that transforms “source code” into “something else” What is “source code”? A well-structured, textual representation of a program Not: preprocessors, assemblers What is “something else?” Assembly language Another well-structured textual representation (e.g. cfront) Intermediate, binary representation (AOT compilers) In-memory executable code (JIT compilers) Executable images Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 3 / 14
  • 14. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 15. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Parser eats tokens, produces AST Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 16. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Parser eats tokens, produces AST What is an AST? And what is abstract about it? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 17. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Parser eats tokens, produces AST What is an AST? And what is abstract about it? What next after an AST? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 18. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Parser eats tokens, produces AST What is an AST? And what is abstract about it? What next after an AST? What is an intermediate form (IR)? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 19. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Parser eats tokens, produces AST What is an AST? And what is abstract about it? What next after an AST? What is an intermediate form (IR)? example: IRs in gcc: source → GENERIC → GIMPLE → RTL → backend Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 20. Compilers Inside a Compiler Inside a Compiler What does the compiler do with the source code? Lexical analysis produces tokens Parser eats tokens, produces AST What is an AST? And what is abstract about it? What next after an AST? What is an intermediate form (IR)? example: IRs in gcc: source → GENERIC → GIMPLE → RTL → backend What is Static Single Assignment (SSA) form? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 4 / 14
  • 21. Compilers Passes, Optimization and Code Generation Passes, Optimization and Code Generation What is a “pass”? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 5 / 14
  • 22. Compilers Passes, Optimization and Code Generation Passes, Optimization and Code Generation What is a “pass”? What is a “optimization”? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 5 / 14
  • 23. Compilers Passes, Optimization and Code Generation Passes, Optimization and Code Generation What is a “pass”? What is a “optimization”? What is a “code generator”? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 5 / 14
  • 24. Compilers Passes, Optimization and Code Generation Passes, Optimization and Code Generation What is a “pass”? What is a “optimization”? What is a “code generator”? What is a “code generator generator”? Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 5 / 14
  • 25. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 26. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 27. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 28. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 29. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 30. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) To build a front end in Python: Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 31. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) To build a front end in Python: hand-coded lexer, (rec-desc) parser Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 32. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) To build a front end in Python: hand-coded lexer, (rec-desc) parser Antlr (generates Python) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 33. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) To build a front end in Python: hand-coded lexer, (rec-desc) parser Antlr (generates Python) Yacc, Bison, Lemon (generates C, wrap to Python) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 34. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) To build a front end in Python: hand-coded lexer, (rec-desc) parser Antlr (generates Python) Yacc, Bison, Lemon (generates C, wrap to Python) Sphinx (C++, wrap to Python) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 35. Compilers The Frontend and The Backend The Frontend and The Backend Everything before the first IR is usually called the frontend And everything after as the backend LLVM and llvm-py deal only with backends Frontends tend to be simpler Many frontends for a backend is common (Scala, Groovy, Clojure: Java; C#, IronPython, etc: .NET) To build a front end in Python: hand-coded lexer, (rec-desc) parser Antlr (generates Python) Yacc, Bison, Lemon (generates C, wrap to Python) Sphinx (C++, wrap to Python) various Python parser generators Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 6 / 14
  • 36. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 37. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 38. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 39. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 40. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: IR data structure, with text and binary representations Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 41. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: IR data structure, with text and binary representations wide range of optimizations Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 42. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: IR data structure, with text and binary representations wide range of optimizations code generator (partly description-based) for many platforms Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 43. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: IR data structure, with text and binary representations wide range of optimizations code generator (partly description-based) for many platforms JIT-compile-execute from IR Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 44. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: IR data structure, with text and binary representations wide range of optimizations code generator (partly description-based) for many platforms JIT-compile-execute from IR link-time optimization (LTO) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 45. LLVM What is LLVM? What is LLVM? Primarily a set of libraries.. ..with which you can make a compiler backend.. ..or a VM with JIT support (but hard to get this right) It provides: IR data structure, with text and binary representations wide range of optimizations code generator (partly description-based) for many platforms JIT-compile-execute from IR link-time optimization (LTO) support for accurate garbage collection Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 7 / 14
  • 46. LLVM LLVM Highlights LLVM Highlights Written in readable C++ Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 8 / 14
  • 47. LLVM LLVM Highlights LLVM Highlights Written in readable C++ Reasonable documentation, helpful and mature community Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 8 / 14
  • 48. LLVM LLVM Highlights LLVM Highlights Written in readable C++ Reasonable documentation, helpful and mature community clang is a now-famous subproject of LLVM Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 8 / 14
  • 49. LLVM LLVM Highlights LLVM Highlights Written in readable C++ Reasonable documentation, helpful and mature community clang is a now-famous subproject of LLVM llvm-gcc is gcc frontend (C, C++, Java, Ada, Fortran, ObjC) + LLVM backend Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 8 / 14
  • 50. LLVM LLVM Highlights LLVM Highlights Written in readable C++ Reasonable documentation, helpful and mature community clang is a now-famous subproject of LLVM llvm-gcc is gcc frontend (C, C++, Java, Ada, Fortran, ObjC) + LLVM backend Many users: Unladen Swallow, Iced Tea, Rubinus, llvm-lua, GHC, LDC Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 8 / 14
  • 51. LLVM The LLVM IR The LLVM IR The IR looks like this (textual representation): “Hello world” in LLVM Assembly @msg = private constant [15 x i8 ] c " Hello , world !0 A 00" declare i32 @puts ( i8 *) define i32 @main ( i32 % argc , i8 ** % argv ) { entry : %0 = getelementptr [15 x i8 ]* @msg , i64 0 , i64 0 %1 = tail call i32 @puts ( i8 * %0) ret i32 undef } Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 9 / 14
  • 52. LLVM A Word About clang A Word About clang A sub-project of the LLVM team Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 10 / 14
  • 53. LLVM A Word About clang A Word About clang A sub-project of the LLVM team clang is a C, Objective C and C++ frontend Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 10 / 14
  • 54. LLVM A Word About clang A Word About clang A sub-project of the LLVM team clang is a C, Objective C and C++ frontend works with the LLVM backend (obviously!) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 10 / 14
  • 55. LLVM A Word About clang A Word About clang A sub-project of the LLVM team clang is a C, Objective C and C++ frontend works with the LLVM backend (obviously!) It can convert C/ObjC/C++ code to LLVM IR Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 10 / 14
  • 56. LLVM A Word About clang A Word About clang A sub-project of the LLVM team clang is a C, Objective C and C++ frontend works with the LLVM backend (obviously!) It can convert C/ObjC/C++ code to LLVM IR which can be played around with using llvm-py Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 10 / 14
  • 57. LLVM A Word About clang A Word About clang A sub-project of the LLVM team clang is a C, Objective C and C++ frontend works with the LLVM backend (obviously!) It can convert C/ObjC/C++ code to LLVM IR which can be played around with using llvm-py and then compiled “normally” Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 10 / 14
  • 58. llvm-py What is llvm-py? What is llvm-py? Python bindings for LLVM Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 11 / 14
  • 59. llvm-py What is llvm-py? What is llvm-py? Python bindings for LLVM Including JIT Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 11 / 14
  • 60. llvm-py What is llvm-py? What is llvm-py? Python bindings for LLVM Including JIT Excellent for experimenting and prototyping Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 11 / 14
  • 61. llvm-py What is llvm-py? What is llvm-py? Python bindings for LLVM Including JIT Excellent for experimenting and prototyping Available in Ubuntu, Debian, MacPorts (but may be out of date) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 11 / 14
  • 62. llvm-py What is llvm-py? What is llvm-py? Python bindings for LLVM Including JIT Excellent for experimenting and prototyping Available in Ubuntu, Debian, MacPorts (but may be out of date) Current version (0.6) works with LLVM 2.7 Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 11 / 14
  • 63. llvm-py More on llvm-py More on llvm-py Covers most of the LLVM APIs, esp. IR Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 12 / 14
  • 64. llvm-py More on llvm-py More on llvm-py Covers most of the LLVM APIs, esp. IR See examples to get started Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 12 / 14
  • 65. llvm-py More on llvm-py More on llvm-py Covers most of the LLVM APIs, esp. IR See examples to get started User guide at http://www.mdevan.org/userguide.html Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 12 / 14
  • 66. llvm-py More on llvm-py More on llvm-py Covers most of the LLVM APIs, esp. IR See examples to get started User guide at http://www.mdevan.org/userguide.html Some LLVM knowledge required: Modules, IR instructions, ... Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 12 / 14
  • 67. llvm-py More on llvm-py More on llvm-py Covers most of the LLVM APIs, esp. IR See examples to get started User guide at http://www.mdevan.org/userguide.html Some LLVM knowledge required: Modules, IR instructions, ... Learning curve of LLVM is steep, llvm-py/Python helps! Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 12 / 14
  • 68. llvm-py More on llvm-py More on llvm-py Covers most of the LLVM APIs, esp. IR See examples to get started User guide at http://www.mdevan.org/userguide.html Some LLVM knowledge required: Modules, IR instructions, ... Learning curve of LLVM is steep, llvm-py/Python helps! Users group: http://groups.google.com/group/llvm-py Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 12 / 14
  • 69. llvm-py llvm-py Internals llvm-py Internals Wraps LLVM’s C API as a Python extension module Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 13 / 14
  • 70. llvm-py llvm-py Internals llvm-py Internals Wraps LLVM’s C API as a Python extension module Extends LLVM C API as it is incomplete Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 13 / 14
  • 71. llvm-py llvm-py Internals llvm-py Internals Wraps LLVM’s C API as a Python extension module Extends LLVM C API as it is incomplete Does not use binding generators (Boost.Python, swig etc) Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 13 / 14
  • 72. llvm-py llvm-py Internals llvm-py Internals Wraps LLVM’s C API as a Python extension module Extends LLVM C API as it is incomplete Does not use binding generators (Boost.Python, swig etc) Public APIs are in Python, use extension module internally Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 13 / 14
  • 73. llvm-py llvm-py Internals llvm-py Internals Wraps LLVM’s C API as a Python extension module Extends LLVM C API as it is incomplete Does not use binding generators (Boost.Python, swig etc) Public APIs are in Python, use extension module internally Mostly straightforward Python, a little metaclass magic Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 13 / 14
  • 74. Thanks References and Thanks Thanks! Thanks for listening! Must read: Steven S. Muchnick. Advanced Compiler Design & Implementation. Me: Mahadevan R, mdevan@mdevan.org, http://www.mdevan.org/ Mahadevan R llvm-py: Writing Compilers Using Python September 25, 2010 14 / 14