The Structure of the GNAT Compiler. A target-independent Ada95 front-end for GCC Ada components C components SyntaxSemExpandgigiGCC AST Annotated AST.

Slides:



Advertisements
Similar presentations
Chapter 2-2 A Simple One-Pass Compiler
Advertisements

Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
Compilers and Language Translation
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
Semantic analysis Parsing only verifies that the program consists of tokens arranged in a syntactically-valid combination, we now move on to semantic analysis,
Honors Compilers Semantic Analysis and Attribute Grammars Mar 5th 2002.
1 Semantic Processing. 2 Contents Introduction Introduction A Simple Compiler A Simple Compiler Scanning – Theory and Practice Scanning – Theory and Practice.
Semantic analysis Enforce context-dependent language rules that are not reflected in the BNF, e.g.a function must have a return statement. Decorate AST.
Semantic analysis Enforce context-dependent language rules that are not reflected in the BNF, e.g.a function must have a return statement. Decorate AST.
Chapter 2 A Simple Compiler
Compiler Summary Mooly Sagiv html://
Chapter 2 A Simple Compiler
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Invitation to Computer Science 5th Edition
September 7, September 7, 2015September 7, 2015September 7, 2015 Azusa, CA Sheldon X. Liang Ph. D. Computer Science at Azusa Pacific University.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
1 Abstract Syntax Tree--motivation The parse tree –contains too much detail e.g. unnecessary terminals such as parentheses –depends heavily on the structure.
Semantic Analysis Legality checks –Check that program obey all rules of the language that are not described by a context-free grammar Disambiguation –Name.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
COP4020 Programming Languages
Parser-Driven Games Tool programming © Allan C. Milne Abertay University v
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Topic #2: Infix to Postfix EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
1 Chapter 1 Introduction. 2 Outlines 1.1 Overview and History 1.2 What Do Compilers Do? 1.3 The Structure of a Compiler 1.4 The Syntax and Semantics of.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Introduction to Compiling
Muhammad Idrees, Lecturer University of Lahore 1 Top-Down Parsing Top down parsing can be viewed as an attempt to find a leftmost derivation for an input.
Introduction CPSC 388 Ellen Walker Hiram College.
Chapter 1 Introduction Major Data Structures in Compiler
Chapter 1: Introduction 1 Compiler Designs and Constructions Chapter 1: Introduction Objectives: Course Objectives Introduction Dr. Mohsen Chitsaz.
Compilers I CNS History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language.
Overview of Previous Lesson(s) Over View  Syntax-directed translation is done by attaching rules or program fragments to productions in a grammar. 
The Model of Compilation Natawut Nupairoj, Ph.D. Department of Computer Engineering Chulalongkorn University.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
Chapter 2 Scanning. Dr.Manal AbdulazizCS463 Ch22 The Scanning Process Lexical analysis or scanning has the task of reading the source program as a file.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
CSC 4181 Compiler Construction
©SoftMoore ConsultingSlide 1 Structure of Compilers.
CSC 8505 Compiler Construction
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Objective of the course Understanding the fundamentals of the compilation technique Assist you in writing you own compiler (or any part of compiler)
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
LECTURE 10 Semantic Analysis. REVIEW So far, we’ve covered the following: Compilation methods: compilation vs. interpretation. The overall compilation.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Chapter 1 Introduction.
A Simple Syntax-Directed Translator
Compiler Construction (CS-636)
Introduction.
Chapter 1 Introduction.
Compiler Lecture 1 CS510.
Lecture 2: General Structure of a Compiler
High-Level Programming Language
Chapter 10: Compilers and Language Translation
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Faculty of Computer Science and Information System
Presentation transcript:

The Structure of the GNAT Compiler

A target-independent Ada95 front-end for GCC Ada components C components SyntaxSemExpandgigiGCC AST Annotated AST GCC tree Your Project!

Lexical Scanner Hand-written for speed Must handle different encodings for extended character sets (ISO642). Input file is read in full to minimize I/O Data structure: global name table Scanner is subroutine for parser, delivers tokens on demand Preprocessor may be integrated with scanner (but Ada has no defined preprocessor).

Parser Hand-written for speed and error recovery Organized according to chapters of the language reference (ARM): par-ch3 handles declarations, par-ch9 handles tasking, par-ch12 handles generics, etc. Recursive-descent with lookahead Follows exactly ARM grammar (ambiguous!) Builds AST: main data structure for front-end Symbol table is integrated into AST.

Semantic Analysis Legality rules (1436 error and warning messages) Tree annotations: add structure to AST to localize semantic information Name resolution (which x?) Type and overload resolution (which “+”?) Dispatching and polymorphism Static expression evaluation Simple optimizations: dead code elimination, constant folding, static conditions.

Expansion Replace complex constructs with simpler one (map Ada semantics into C semantics) Aggregates: (1..10 => 42, others => 0) Equality on composite types: if A (x.. y) = B (x..y) then.. Tasking (thread communication) Many others… Expander builds AST fragments, calls semantics to annotate them: process is recursive

Gigi: GNAT to GCC Impractical to use GCC data structures in front- end Gigi traverses GNAT tree fragments and calls tree-building procedures (just like other GCC front-ends) Each tree fragment is immediately translated into Register Transfer Language (RTL) Gigi must reflect Ada semantics (syntax and semantic information packages) and must interface to GCC generators: written in C.

Other components Library management: program is assembled from compilation of multiple files. Need tools to insure coherence (like make) gather object files, record dependencies between units. gnatbind, gnatlink Runtime management: Input/Output, numeric libraries, tasking, real time, distributed computing.

The data structures of the AST Nodes are variant records of fixed size. Each variant corresponds to one non-terminal A node has at most 4 syntactic descendants A descendant is either a node or a list Terminal nodes are identifiers and literals Node kind is discriminant: determines meaning of descendants for each node 220 kinds: Compilation_unit, package_declaration…loop_statement… Syntactic structure described in sinfo.ads

Semantic annotations Each tree node carries semantic information Node-specific: expressions have types procedures have scope array types have index and component types Literals have a value Full description in einfo.ads

Symbol table is integrated into AST Identifiers in declarations are special: defining_occurrence accumulates semantic information for an entity References to an identifier are pointers to corresponding defining_occurrence: Entity. Symbol table is set of defining_occurrences. Identifiers point to names table Symbol table contains no strings