Advances in Compilers

Similar documents
What is a compiler? Xiaokang Qiu Purdue University. August 21, 2017 ECE 573

Compiling Regular Expressions COMP360

What is a compiler? var a var b mov 3 a mov 4 r1 cmpi a r1 jge l_e mov 2 b jmp l_d l_e: mov 3 b l_d: ;done

An introduction to Flex

Yacc: A Syntactic Analysers Generator

(F)lex & Bison/Yacc. Language Tools for C/C++ CS 550 Programming Languages. Alexander Gutierrez

Compilers and Interpreters

The structure of a compiler

COP 3402 Systems Software. Lecture 4: Compilers. Interpreters

Lex & Yacc (GNU distribution - flex & bison) Jeonghwan Park

Introduction. CS 2210 Compiler Design Wonsun Ahn

Introduction to Compiler Design

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

CST-402(T): Language Processors

Edited by Himanshu Mittal. Lexical Analysis Phase

Module 8 - Lexical Analyzer Generator. 8.1 Need for a Tool. 8.2 Lexical Analyzer Generator Tool

Figure 2.1: Role of Lexical Analyzer

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

New Advances in Micro-Processors and computer architectures

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

Compiler Design (40-414)

Introduction to Lex & Yacc. (flex & bison)

Group B Assignment 9. Code generation using DAG. Title of Assignment: Problem Definition: Code generation using DAG / labeled tree.

Working of the Compilers

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

Flex and lexical analysis

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

What do Compilers Produce?

CSE302: Compiler Design

C Compilation Model. Comp-206 : Introduction to Software Systems Lecture 9. Alexandre Denault Computer Science McGill University Fall 2006

Formats of Translated Programs

Automatic Scanning and Parsing using LEX and YACC

An Overview to Compiler Design. 2008/2/14 \course\cpeg421-08s\topic-1a.ppt 1

Using Lex or Flex. Prof. James L. Frankel Harvard University

Outline. Lecture 17: Putting it all together. Example (input program) How to make the computer understand? Example (Output assembly code) Fall 2002

Preparing for the ACW Languages & Compilers

Compiler I: Syntax Analysis

Flex and lexical analysis. October 25, 2016

COMPILERS AND INTERPRETERS Lesson 4 TDDD16

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Big Picture: Compilation Process. CSCI: 4500/6500 Programming Languages. Big Picture: Compilation Process. Big Picture: Compilation Process.

An Introduction to LEX and YACC. SYSC Programming Languages

Parsing and Pattern Recognition

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

CS 415 Midterm Exam Spring 2002

TDDD55 - Compilers and Interpreters Lesson 3

Theory and Compiling COMP360

Compiler Front-End. Compiler Back-End. Specific Examples

Compiler Construction


Lex & Yacc. by H. Altay Güvenir. A compiler or an interpreter performs its task in 3 stages:

TDDD55- Compilers and Interpreters Lesson 3

Language Translation. Compilation vs. interpretation. Compilation diagram. Step 1: compile. Step 2: run. compiler. Compiled program. program.

COMPILER DESIGN UNIT I LEXICAL ANALYSIS. Translator: It is a program that translates one language to another Language.

Appendix A The DL Language

PRACTICAL CLASS: Flex & Bison

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Lexical Scanning COMP360

Unix System Architecture, File System, and Shell Commands

Question 1. Notes on the Exam. Today. Comp 104: Operating Systems Concepts 11/05/2015. Revision Lectures

COMPILER CONSTRUCTION Seminar 02 TDDB44

CS 110 Computer Architecture. Lecture 2: Introduction to C, Part I. Instructor: Sören Schwertfeger.

Introduction to Programming Languages and Compilers. CS164 11:00-12:30 TT 10 Evans. UPRM ICOM 4029 (Adapted from: Prof. Necula UCB CS 164)

Introduction to Compilers

A program that performs lexical analysis may be termed a lexer, tokenizer, or scanner, though scanner is also a term for the first stage of a lexer.

Pioneering Compiler Design

Lex & Yacc. By H. Altay Güvenir. A compiler or an interpreter performs its task in 3 stages:

! Readings! ! Room-level, on-chip! vs.!

Notes on the Exam. Question 1. Today. Comp 104:Operating Systems Concepts 11/05/2015. Revision Lectures (separate questions and answers)

Lecture Outline. COMP-421 Compiler Design. What is Lex? Lex Specification. ! Lexical Analyzer Lex. ! Lex Examples. Presented by Dr Ioanna Dionysiou

COMPILER CONSTRUCTION (Evaluation Orders for SDD s)

Compiler Construction

Lex (Lesk & Schmidt[Lesk75]) was developed in the early to mid- 70 s.

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Compiler Lab. Introduction to tools Lex and Yacc

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 2: Lexical Analysis 23 Jan 08

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

Big Picture: Compilation Process. CSCI: 4500/6500 Programming Languages. Big Picture: Compilation Process. Big Picture: Compilation Process

Comp 204: Computer Systems and Their Implementation. Lecture 25a: Revision Lectures (separate questions and answers)

Lexical and Syntax Analysis

CSc 520 Principles of Programming Languages

Lecture 03 Bits, Bytes and Data Types

Undergraduate Compilers in a Day

SLIDE 2. At the beginning of the lecture, we answer question: On what platform the system will work when discussing this subject?


Chapter 13 Reduced Instruction Set Computers

TDDD55- Compilers and Interpreters Lesson 2

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

CSc 453. Compilers and Systems Software. 18 : Interpreters. Department of Computer Science University of Arizona. Kinds of Interpreters

1DL321: Kompilatorteknik I (Compiler Design 1)

Software Project. Lecturers: Ran Caneti, Gideon Dror Teaching assistants: Nathan Manor, Ben Riva

CS143 Handout 04 Summer 2011 June 22, 2011 flex In A Nutshell

T Jarkko Turkulainen, F-Secure Corporation

Group A Assignment 3(2)

1DL321: Kompilatorteknik I (Compiler Design 1) Introduction to Programming Language Design and to Compilation

Chapter 1 INTRODUCTION SYS-ED/ COMPUTER EDUCATION TECHNIQUES, INC.

Concepts. Lexical scanning Regular expressions DFAs and FSAs Lex. Lexical analysis in perspective

LECTURE 6 Scanning Part 2

RISC Processors and Parallel Processing. Section and 3.3.6

Transcription:

Advances in Compilers Prof. (Dr.) K.R. Chowdhary, Director COE Email: kr.chowdhary@jietjodhpur.ac.in webpage: http://www.krchowdhary.com JIET College of Engineering August 4, 2017 kr chowdhary Compilers 1/ 24

Outlines: 1 Compiler basics: revisiting 2 New vs old compilers 3 Parallel language features 4 Parallel compilers 5 Modern Compilers 6 CETUS 7 Compiling 8 Lexical analyser generator 9 Resources for lex kr chowdhary Compilers 2/ 24

Compilation steps Compilers are language processors (input HLL, output LLL). 1 Tokenizing (lexical analysis) 2 Parsing (syntax analysis) 3 Static semantic checking 4 Intermediate code generation 5 optimization 6 final code generation kr chowdhary Compilers 3/ 24

Compiler v/s Interpretation Compiled programs run faster, if they are compiled into the form that is directly executable on the underlying hardware Static compilation can devote arbitrary amount of time for program analysis and optimization Hence JIT (just in time) compiler Interpreted programs are typically smaller Interpreted programs tends to be more portable kr chowdhary Compilers 4/ 24

JIT: Just in time compilers Traditionally there are two approaches to translation: 1 Compilation: translates one language to another (say, C to assembly or C to machine). It can be further improved after compilation. 2 Interpretation: No more improvement possible, and does immediate execution. kr chowdhary Compilers 5/ 24

What practice one should do along with principles? Focus on implementing core parts of a compiler, with building the infrastructure Small language as an implementing target Build from scratch a working interpreter for a small functional language The practical should help in understanding the language Learning compilers provide strong theoretical foundations. kr chowdhary Compilers 6/ 24

Early v/s new compilers Early compilers: Written in low level languages like C or assembly Modern compilers are written in C/C++, C#, F#, Java. Single individuals usually crafted compilers, but modern compilers are typically large In new: there are RISC, CISC machines of past, vector processors, multicore, etc. kr chowdhary Compilers 7/ 24

Advanced Languages: Parallel Programming Number of process are running instructions simultaneously Instruction cycle? Say, fetch time (t f ) = decode time (t d ) = run-time (t r ) = t µ-secs, then parallel processing possible. Then, a program of 100 machine instructions will take 300t µ sec. on that machine. If instruction I i is in execution, I i+1 is in decode cycle, and I i+2 is in fetch cycle. Then, it will take only 100t µ sec.!! kr chowdhary Compilers 8/ 24

Multi-core CPUs Consider the following code: 1. b =a+c; 2. d =b+e; 3. f =g+d; Running 1. and 2. on two cpus at the same time?(y/n) Running 1. and 3. on two cpus at the same time?(y/n) Running bubble sort on two cpus at the same time?(y/n) Running quick sort on two cpus at the same time?(y/n) kr chowdhary Compilers 9/ 24

Modern compilers Compiler algorithms for parsing, type checking, data-flow analysis, loop transformations are based on - data dependent analysis in graphs, register allocation based on graph coloring, are new techniques. Coding optimization: avoids redundant computations, register allocation, enhancing locality, instruction level parallelism. Optimized compilers produce code having some times peak performance of target machine. identifying some of the frequent bugs (e.g., improper memory allocation, locations, race conditions, buffer over-run). Thus providing better security. kr chowdhary Compilers 10/ 24

Compiler challenges in multicore processors Single core: Multicore: Memory Memory Cache Cache L2 Cache L1 Cache L1 CPU CPU1 CPU1 kr chowdhary Compilers 11/ 24

Parallel Compilers In the era of multicore processors: From now on, clock frequencies will rise slowly, if at all, but the number of cores on processor is likely to double every couple of years by 2020 microprocessors are likely to have number of cores hundreds of even thousands, with heterogeneous functionalities Exploiting large -scale parallel will be essential for improving an applications performance This is to do without undue programmer effort kr chowdhary Compilers 12/ 24

Compiler challenges and agenda for future The full potential can be achieved only if parallel compilers exist. Agenda for the Compiler Community: Open compiler architectures, Open benchmarks for performance evaluation, Make parallel program main-stream Write compilers capable of self improvement Develop algorithms for optimization of parallel code Develop software as reliable as airplane Enable system software that is secure at all levels Expand compiler courses with new problem domains (such as security) kr chowdhary Compilers 13/ 24

Compiler challenges and agenda for future... Make parallel programming as mainstream As on today the parallel programming exists only in databases, and server-side applications How to parallel this?: i=999 i=0 a i It is normally done as: fetch instruction, fetch data, decode, execute (cycle repeated 1000 times) For parallelism fetch opcode once only, decode once only, fetch data 1000 times, run parallel with fetch!! kr chowdhary Compilers 14/ 24

Compiler challenges and agenda for future... Enable system software that is secure at all levels: sophisticated program analysis, prevention of software vulnerabilities, like buffer over-flow and dangling pointers arising from coding defects. Automatic verification of complete software stack: Instead of debugging a program, prove that it meets its specifications, and this proof should be checked by a computer program - John McCarthy. kr chowdhary Compilers 15/ 24

CETUS: A source-to-source compiler infrastructure for multicores After the name of a constellation Automatic parallelization Input C program, output for 64 bit machines CETUS symbolic expression tools: 1+2 a+4 a 5+a (folding) a (b+c) a b+a c (distribution) (a 2)/(8 c) a/(4 c) (division) (1 a)<(b+2) (1+a+b)>0 (normalization) a && 0 && b 0 (short-circuit evaluation) kr chowdhary Compilers 16/ 24

CETUS: A source-to-source compiler infrastructure for multicores Cetus does automatic parallelization: by using data dependence analysis by array and scalar privatization by reduction variable recognition by induction variable substitution kr chowdhary Compilers 17/ 24

gnu C compiler commands #include<stdio.h> int main(void) { printf("\n Hello World\n"); return 0; } $ gcc main.c $ gcc main.c -o main # The output of preprocessing stage $ gcc -E main.c > main.i # Assembly level output $gcc -S main.c > main.s kr chowdhary Compilers 18/ 24

gnu C compiler commands #compiled code (without any linking) $gcc -C main.c #all the intermediate files using -save-temps function $ gcc -save-temps main.c $ ls a.out main.c main.i main.o main.s # Print all the executed commands using -V option $ gcc -Wall -v main.c -o main Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.6/lto-wra Target: i686-linux-gnu Configured with:../src/con... Thread model: posix gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) kr chowdhary Compilers 19/ 24

lexical analyser generator $ gedit test.lex /* just like Unix wc */ %{ int chars = 0; int words = 0; int lines = 0; %} %% [a-za-z]+ { words++; chars += strlen(yytext); } \n { chars++; lines++; }. { chars++; } %% int main(){ yylex(); printf("%d %d %d\n", lines, words, chars); return 0; } kr chowdhary Compilers 20/ 24

lexical analyser generator... $ flex test.lex $ ls $ gcc lex.yy.c -lfl ; link to flex library $./a.out kr chowdhary Compilers 21/ 24

lexical analyser generator... Specs of a scanner - stdin - *.lex lex.yy.c Flex C Compiler lex.yy.c a.out Input stream a.out sequence of tokens FLEX (Fast LEXical analyzer generator) is a tool for generating scanners. First, FLEX reads a specification of a scanner either from an input file *.lex, or from standard input, and it generates as output a C source file lex.yy.c. Then, lex.yy.c is compiled and linked with the -lfl library kr chowdhary Compilers 22/ 24

lexical analyser generator... *.lex is in the form of pairs of regular expressions and C code. lex.yy.c defines a routine yylex() that uses the specification to recognize tokens; a.out is actually the scanner! Command Sequence: flex sample*.lex gcc lex.yy.c -lfl./a.out Input file Format: definitions %% rules %% user code The definitions section: "name definition" The rules section: "pattern action" The user code section: "yylex() routine" kr chowdhary Compilers 23/ 24

lexical analyser generator... links: http://epaperpress.com/lexandyacc/ http://dinosaur.compilertools.net/ http://dinosaur.compilertools.net/lex/ http://en.wikipedia.org/wiki/history of compiler construction http://www.drdobbs.com/database/lex-and-yacc/184409830 kr chowdhary Compilers 24/ 24