Targeting Parrot Léon Brocard Fotango Ltd.

Slides:



Advertisements
Similar presentations
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Advertisements

1 Scheme and Functional Programming Aaron Bloomfield CS 415 Fall 2005.
Intermediate Code Generation
Course Outline Traditional Static Program Analysis Software Testing
The University of Adelaide, School of Computer Science
Chapter 9 Code optimization Section 0 overview 1.Position of code optimizer 2.Purpose of code optimizer to get better efficiency –Run faster –Take less.
Intermediate Representation III. 2 PAs PA2 deadline is
1 Chapter 8: Code Generation. 2 Generating Instructions from Three-address Code Example: D = (A*B)+C =* A B T1 =+ T1 C T2 = T2 D.
Chapter 8 ICS 412. Code Generation Final phase of a compiler construction. It generates executable code for a target machine. A compiler may instead generate.
Course Outline Traditional Static Program Analysis –Theory Compiler Optimizations; Control Flow Graphs Data-flow Analysis – today’s class –Classic analyses.
Chapter 10 Code Optimization. A main goal is to achieve a better performance Front End Code Gen Intermediate Code source Code target Code user Machine-
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages – It’s elegant, minimal, can.
The University of Adelaide, School of Computer Science
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Compiler Construction by Muhammad Bilal Zafar (AP)
Procedures and Control Flow CS351 – Programming Paradigms.
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages It’s elegant, minimal, can be.
Interpreter for ZOOM-I Andrew Deren Initial Presentation - SE690 5/30/03
Intermediate code generation. Code Generation Create linear representation of program Result can be machine code, assembly code, code for an abstract.
1 Storage Registers vs. memory Access to registers is much faster than access to memory Goal: store as much data as possible in registers Limitations/considerations:
Register Allocation Mooly Sagiv html://
1 Handling nested procedures Method 1 : static (access) links –Reference to the frame of the lexically enclosing procedure –Static chains of such links.
Generational Stack Collection And Profile driven Pretenuring Perry Cheng Robert Harper Peter Lee Presented By Moti Alperovitch
Code Generation Simple Register Allocation Mooly Sagiv html:// Chapter
Tentative Schedule 20/12 Interpreter+ Code Generation 27/12 Code Generation for Control Flow 3/1 Activation Records 10/1 Program Analysis 17/1 Register.
Run time vs. Compile time
Code Generation Mooly Sagiv html:// Chapter 4.
Compiler Construction Recap Rina Zviel-Girshin and Ohad Shacham School of Computer Science Tel-Aviv University.
Microprocessors Frame Pointers and the use of the –fomit-frame-pointer switch Feb 25th, 2002.
Register Allocation Recap Mooly Sagiv html:// Special Office Hours Wednesday 12-14, Thursday 12-14, Schriber.
Register Allocation Mooly Sagiv html://
Tail Recursion. Problems with Recursion Recursion is generally favored over iteration in Scheme and many other languages – It’s elegant, minimal, can.
A Portable Virtual Machine for Program Debugging and Directing Camil Demetrescu University of Rome “La Sapienza” Irene Finocchi University of Rome “Tor.
Introduction For some compiler, the intermediate code is a pseudo code of a virtual machine. Interpreter of the virtual machine is invoked to execute the.
13/02/2009CA&O Lecture 04 by Engr. Umbreen Sabir Computer Architecture & Organization Instructions: Language of Computer Engr. Umbreen Sabir Computer Engineering.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 10, 10/30/2003 Prof. Roy Levow.
ITEC 352 Lecture 18 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Exam –Average 76 Methods for functions in assembly.
CSC 3210 Computer Organization and Programming Chapter 1 THE COMPUTER D.M. Rasanjalee Himali.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Chapter 7 Object Code Generation. Chapter 7 -- Object Code Generation2  Statements in 3AC are simple enough that it is usually no great problem to map.
Intermediate Code Representations
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 11: Functions and stack frames.
1 CS308 Compiler Theory. 2 Course Information Instructor : –Prof. Minyi Guo –Yao Shen Course.
Introduction to Language Programming Hierarchy of programming lang. Based on machine independences: 1. Machine language 2. Assembly language 3. Higher.
Procedures and Functions Procedures and Functions – subprograms – are named fragments of program they can be called from numerous places  within a main.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Prologue Sung-Dong Kim, Dept. of Computer Engineering, Hansung University.
RealTimeSystems Lab Jong-Koo, Lim
ICS51 Introductory Computer Organization Accessing parameters from the stack and calling functions.
Lecture 9 Symbol Table and Attributed Grammars
CS 404 Introduction to Compiler Design
Computer Architecture & Operations I
Compiler Design (40-414) Main Text Book:
Tail Recursion.
Mooly Sagiv html://
Constructing Precedence Table
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
143A: Principles of Operating Systems Lecture 4: Calling conventions
CISC 7120X Programming Languages and Compilers
CS416 Compiler Design lec00-outline September 19, 2018
Chapter 9 :: Subroutines and Control Abstraction
Unit IV Code Generation
CSc 453 Interpreters & Interpretation
Multi-modules programming
8 Code Generation Topics A simple code generator algorithm
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
CISC 7120X Programming Languages and Compilers
Intermediate Code Generation
Compiler Construction
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Presentation transcript:

Targeting Parrot Léon Brocard Fotango Ltd.

Outline What is Parrot? Why target Parrot? Targeting Modifying Parrot

Targeting? public class Fib { static void Main() { int n = 24, a = 1, b = 1, f = 1, i = 3; while(i <= n) { puti(i); puts("\n"); f = a + b; a = b; b = f; i++; } set I0, 24 set I2, 1 set I3, 1 set I4, 1 set I5, 3 LBL1: gt I5, I0, LBL2 print I5 print "\n" add I4, I2, I3 set I2, I3 set I3, I4 set I1, I5 inc I5 branch LBL1 LBL2: end

Parrot is… Virtual machine for dynamic languages Register-based (I, N, S, P) Portable (bytecode-based) High-level Fast Moving target

Targeting consists of: Parsing the source language (Doing some data structure munging) Outputting assembler / machine code

Java Virtual Machine Two stage ( javac, java ) int x, y, z; x = 1; y = 1; z = x + y; iconst_1 istore_1 iconst_1 istore_2 iload_1 iload_2 iadd istore_3

Targeting Expression by expression Parrot does not have for, while Use branch instead

Parrot Virtual Machine Two stage ( assemble.pl, parrot ) a c c d c6c f 6f77 6c a c print “Hello world!\n” end

Parrot Virtual Machine (2) Two stage ( assemble.pl, parrot ) %./assemble.pl hello.pasm -o hello.pbc %./parrot hello.pbc Hello world! %

Main methods of targeting Output Parrot source code (.pasm) Output Parrot bytecode Output interpreter (BASIC) Output code (cola, jako) Hybrid

Parrot is dynamic Not only for dynamic languages, but also fairly dynamic itself Modify Parrot for your own use: Modify the virtual machine Modify the opcodes Modify the PMCs

Targeting Want to run your language under Parrot? Got an existing parser? Simply retarget your language at Parrot

Parrot is a register machine Mostly for speed: add I0, I1, I2 Also a stack machine, so if targeting a stack language, use the stack for ease of translation: restore I1 restore I2 add I0, I1, I2 save I0

Adding ops What was that about a stack machine? op iadd() { INTVAL x; INTVAL y; stack_pop(interpreter, interpreter->user_stack, &x, STACK_ENTRY_INT); stack_pop(interpreter, interpreter->user_stack, &y, STACK_ENTRY_INT); x = x + y; stack_push(interpreter, interpreter->user_stack, &x, STACK_ENTRY_INT, STACK_CLEANUP_NULL); goto NEXT(); }

Register allocation Use registers for speed Use graph colouring, du-chains for lexicals and symbolic temporaries Register spilling: use spill weights “Compilers: Principles, Techniques and Tools” by Alfred V. Aho, Ravi Sethi, and Jeffrey D. Ullman

Register allocation: imcc imcc: intermediate compiler for Parrot by Melvin Smith and Angel Faus handles register allocation and spillage (infinite number of typed temporaries or named lexicals) in the future: constant folding, expression evaluation, instruction selection, other optimisations…

Register allocation: imcc _MAIN: save "" set I0, 4 add I0, I0, 1 set I0, I0 print I0 print "\n" end ret.sub _MAIN.arg "".local int out $I0 = 4 $I1 = $I0 + 1 out = $I1 print out print "\n" end ret

Adding PMCs A little more involved (docs/vtables.pod) SchemePair PMC car, cdr and all that jazz Add ops which use the PMCs Caveat: tricky, underdocumented atm.

Calling Conventions PDD03: Parrot Calling Conventions Caller-save Important for exposing public subroutines Mostly ignoreable

Garbage collection Parrot has a GC system

Debugging Parrot debugger pdb Trace with the -t flag … or print statements

TODO ;-) Wait for Parrot to have more features, target some more languages at it and then finish these slides Ship parrot with your language? Type conversions / stack manipulations / PMC / control / subroutines / exceptions /

If you remember one thing… Computer languages can easily be targeted at Parrot

Thank you