Post-compilation assembly (gcc)

Similar documents
CSCI 3136 Principles of Programming Languages

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Compiler Construction

03 - Lexical Analysis

Language Processing Systems

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Compiler Construction

Programming Languages CIS 443

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

Programming Languages

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Lecture 9. Semantic Analysis Scoping and Symbol Table

Programming Language Pragmatics

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Semantic Analysis: Types and Type Checking

CA Compiler Construction

Compiler I: Syntax Analysis Human Thought

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

C Compiler Targeting the Java Virtual Machine

Programming Assignment II Due Date: See online CISC 672 schedule Individual Assignment

The programming language C. sws1 1

Semester Review. CSC 301, Fall 2015

Syntaktická analýza. Ján Šturc. Zima 208

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Sources: On the Web: Slides will be available on:

Object-Oriented Software Specification in Programming Language Design and Implementation

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Glossary of Object Oriented Terms

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

2) Write in detail the issues in the design of code generator.

Technical paper review. Program visualization and explanation for novice C programmers by Matthew Heinsen Egan and Chris McDonald.

Programming Languages

Compilers Lexical Analysis

Optimizing compilers. CS Modern Compilers: Theory and Practise. Optimization. Compiler structure. Overview of different optimizations

1/20/2016 INTRODUCTION

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

International Journal of Scientific & Engineering Research, Volume 4, Issue 11, November ISSN

Algorithm & Flowchart & Pseudo code. Staff Incharge: S.Sasirekha

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

[Refer Slide Time: 05:10]

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Chapter 3. Input and output. 3.1 The System class

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Textual Modeling Languages

Module: Software Instruction Scheduling Part I

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

Lab Experience 17. Programming Language Translation

Programming Languages

The C Programming Language course syllabus associate level

Programming Project 1: Lexical Analyzer (Scanner)

How To Trace

Flex/Bison Tutorial. Aaron Myles Landwehr CAPSL 2/17/2012

WESTMORELAND COUNTY PUBLIC SCHOOLS Integrated Instructional Pacing Guide and Checklist Computer Math

GENERIC and GIMPLE: A New Tree Representation for Entire Functions

Static Analyzers. Context. Learning Objectives

Natural Language to Relational Query by Using Parsing Compiler

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

If-Then-Else Problem (a motivating example for LR grammars)

2 SYSTEM DESCRIPTION TECHNIQUES

Symbol Tables. Introduction

Design Patterns in Parsing

Obfuscation: know your enemy

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

Moving from CS 61A Scheme to CS 61B Java

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, School of Informatics University of Edinburgh als@inf.ed.ac.

5HFDOO &RPSLOHU 6WUXFWXUH

Intel Assembler. Project administration. Non-standard project. Project administration: Repository

Embedded Software Development with MPS

ALLIED PAPER : DISCRETE MATHEMATICS (for B.Sc. Computer Technology & B.Sc. Multimedia and Web Technology)

Static Taint-Analysis on Binary Executables

Lesson 4 Web Service Interface Definition (Part I)

Variable Base Interface

Introduction to formal semantics -

Performa Porting to the JVM

Regression Verification: Status Report

EKT150 Introduction to Computer Programming. Wk1-Introduction to Computer and Computer Program

Introduction to Automata Theory. Reading: Chapter 1

RCC A user-extensible systems implementation language

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Static Analysis. Find the Bug! : Analysis of Software Artifacts. Jonathan Aldrich. disable interrupts. ERROR: returning with interrupts disabled

Introducing Formal Methods. Software Engineering and Formal Methods

IT UNIVERSITY OF COPENHAGEN. Abstract. Department of Software Development and Technology (SDT) Master s Thesis. Generic deobfuscator for Java

AUTOMATED TEST GENERATION FOR SOFTWARE COMPONENTS

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Compiler Design July 2004


Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

ML for the Working Programmer

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Briki: a Flexible Java Compiler

Tachyon: a Meta-circular Optimizing JavaScript Virtual Machine

Context free grammars and predictive parsing

Chapter 6: Programming Languages

2. Advance Certificate Course in Information Technology

Transcription:

Library routines and linking (Fortran) The compilation of source code counts on the existence of a library of subroutines invoked by the program 1 Post-compilation assembly (gcc) Source code is first compiled to assembly code, and then the assembler translates it to machine code To facilitate debugging (assembly code is easier to read) To isolate the compiler from changes in the format of machine language files (only the commonly shared assembler must be changed) 2 1

Source-to-Source Translation AT&T C++ compiler To translate C++ programs to C programs To facilitate reuse of compilers or language support 3 Bootstrapping Many compilers are self-hosting: They are written in the language they compile Bootstrapping is used to compile the compiler in the first place Pascal->MC compiler, in Pascal Pascal->P-code compiler, in P-code Pascal->MC compiler, in P-code P-code->MC interpreter, in Pascal Manual translation P-code->MC interpreter, in MC Pascal->MC compiler, in MC 4 2

Pascal MC Pascal MC Pascal MC Pascal Pascal P- code P- code P- code MC MC P- code MC 5 Overview of Compilation 6 3

Front end & back end Front end To analyze the source code in order to build an internal representation (IR) of the program It includes: lexical analysis, syntactic analysis, and semantic analysis Back end To gather and analyze program information from IR, to optimize the code, and to generate machine code It includes: optimization and code generation 7 Scanning (Lexical Analysis) Break the program into tokens the smallest meaningful units This can save time, since character-bycharacter processing is slow We can tune the scanner better E.g., remove spaces & comments A scanner uses a Deterministic Finite Automaton (DFA) to recognize tokens 8 4

A running example: Greatest Common Divisor (GCD) int main() { int i = getint(), j = getint(); while (i!= j) { if (i > j) i = i j; else j = j i; } putint(i) } Token sequence: int main ( ) { int i = getint ( ), j = getint ( ) ; while ( i!= j ) { if ( i > j ) i = i - j ; else j = j - i ; } putint ( i ) ; } 9 Parsing Organize tokens into a parse tree that represents higher-level constructs (statements, expressions, subroutines) Each construct is a node in the tree Each construct s constituents are its children 10 5

GCD Parsing Tree 11 Semantic Analysis Determine the meaning of a program A semantic analyzer builds and maintains a symbol table data structure that maps each identifier to the information known about it, such as the identifier s type, internal structure, and scope 12 6

Semantic Analysis With the symbol table, the semantic analyzer can enforce a large variety of rules to check for errors Sample rules: Each identifier is declared before it is used Any function with a non-void return type returns a value explicitly Subroutine calls provide the correct number and types of arguments 13 Semantic Analysis Static semantics Rules that can be checked at compile time Dynamic semantics Rules that must be checked at run time, such as Variables are never used in an expression unless they have been given a value Pointers are never dereferenced unless they refer to a valid object 14 7

Syntax Tree A parse tree is known as a concrete syntax tree It demonstrates concretely, how a particular sequence of tokens can be derived under the rule of the context-free grammar However, much of the information in a concrete syntax tree is irrelevant E.g., ε under some branches 15 Syntax Tree In the process of checking static semantic rules, a semantic analyzer transforms the parse tree into an abstract syntax tree (AST, or syntax tree) by removing unimportant nodes, and annotating remaining nodes with information like pointers from identifiers to their symbol table entries 16 8

GCD Abstract Syntax Tree 17 Intermediate Form (IF) Generated after semantic analysis In many compilers, an AST is passed as IF from the front end to the back end In other compilers, a control flow graph is passed as IF 18 9

Optimization [1] High-level optimization Goal: perform high-level analysis and optimization of programs Input: AST + symbol table Output: low-level program representation, such as 3-address code Tasks: Procedure/method inlining Array/pointer dependence analysis Loop transformations: unrolling, permutation, 19 Optimization [1] Low-level optimization Goal: perform low-level analysis and optimizations Input: low-level representation of programs, such as 3-address code Output: optimized low-level representation, and additional information, such as def-use chains Tasks: Dataflow analysis: live variables, reaching definitions, Scalar optimizations: constant propagation, partial redundancy elimination, 20 10

Code Generator [1] Goal: produce assembly/machine code from optimized low-level representation of programs Tasks: Register allocation Instruction selection 21 Reference [1] Keshav Pingali, Advanced Topics in Compilers, https://www.cs.utexas.edu/ ~pingali/cs380c/2013/lectures/intro.pdf 22 11

Programming Language Syntax In Text: Chapter 2 Outline Basic concepts Programming language, regular expression, context-free grammars Lexical analysis Scanner, Deterministic finite automaton (DFA) Syntactic analysis Parser 24 12

What is a Language? A language is a set of strings of symbols that are constrained by rules A sentence is a string of symbols Syntax (Grammar) To describe the structure of a language Semantics To describe the meaning or sentences, phrases, or words 25 Natural languages are ambiguous I saw a man on a hill with a telescope Programming languages should be precise and unambiguous Both programmers and computers can tell what a program is supposed to do 26 13