Introduction to FOAM (the intermediate language for Aldor) Laurentiu Dragan UWO/ORCCA Programming Languages Group.

Slides:



Advertisements
Similar presentations
Overview of programming in C C is a fast, efficient, flexible programming language Paradigm: C is procedural (like Fortran, Pascal), not object oriented.
Advertisements

Introduction to Programming G51PRG University of Nottingham Revision 1
Synopsys University Courseware Copyright © 2012 Synopsys, Inc. All rights reserved. Compiler Optimization and Code Generation Lecture - 3 Developed By:
Intermediate Code Generation
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.
Semantic Analysis Chapter 6. Two Flavors  Static (done during compile time) –C –Ada  Dynamic (done during run time) –LISP –Smalltalk  Optimization.
Code optimization: –A transformation to a program to make it run faster and/or take up less space –Optimization should be safe, preserve the meaning of.
8. Code Generation. Generate executable code for a target machine that is a faithful representation of the semantics of the source code Depends not only.
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-
1 Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
1 Compiler Construction Intermediate Code Generation.
Introduction to Advanced Topics Chapter 1 Mooly Sagiv Schrierber
Compiler Construction
CPSC Compiler Tutorial 8 Code Generator (unoptimized)
Denotational Semantics Syntax-directed approach, generalization of attribute grammars: –Define context-free abstract syntax –Specify syntactic categories.
CS 536 Spring Intermediate Code. Local Optimizations. Lecture 22.
Intermediate Code. Local Optimizations
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
Basic Elements of C++ Chapter 2.
Optimizing Compilers Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.
Topic #10: Optimization EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
CIS Computer Programming Logic
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
Programming Language C++ Xulong Peng CSC415 Programming Languages.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
CIS-165 C++ Programming I CIS-165 C++ Programming I Bergen Community College Prof. Faisal Aljamal.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
1 Code optimization “Code optimization refers to the techniques used by the compiler to improve the execution efficiency of the generated object code”
Compiler Principles Fall Compiler Principles Lecture 0: Local Optimizations Roman Manevich Ben-Gurion University.
Language Translation A programming language processor is any system that manipulates programs expressed in a PL A source program in some source language.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
Programming Languages
12/9/20151 Programming Languages and Compilers (CS 421) Elsa L Gunter 2112 SC, UIUC Based in part on slides by Mattox.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
CPS120: Introduction to Computer Science Variables and Constants.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Review A program is… a set of instructions that tell a computer what to do. Programs can also be called… software. Hardware refers to… the physical components.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
Java Programming: Guided Learning with Early Objects Chapter 1 Basic Elements of Java.
Code Optimization Code produced by compilation algorithms can often be improved (ideally optimized) in terms of run-time speed and the amount of memory.
Code Optimization.
Chapter Topics The Basics of a C++ Program Data Types
The Machine Model Memory
Introduction to Advanced Topics Chapter 1 Text Book: Advanced compiler Design implementation By Steven S Muchnick (Elsevier)
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Basic Elements of C++.
Dept of Computer Science
Chapter 3 Assignment Statement
Basic Elements of C++ Chapter 2.
null, true, and false are also reserved.
Lecture 8.
Introduction to Java Programming
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
An overview of Java, Data types and variables
The Metacircular Evaluator
C Programming Getting started Variables Basic C operators Conditionals
Optimization 薛智文 (textbook ch# 9) 薛智文 96 Spring.
Intermediate Code Generation
Presentation transcript:

Introduction to FOAM (the intermediate language for Aldor) Laurentiu Dragan UWO/ORCCA Programming Languages Group

Overview ● What is FOAM ● Short example ● FOAM instructions – Grammar ● Calling Protocols ● Built-in operations ● Semantics of FOAM ● Runtime support ● Optimizations

What is FOAM ● First Order Abstract Machine (FOAM) ● Intermediate languages – LIR, MIR, HIR ● FOAM – HIR ● Developed at IBM by Dr. Stephen Watt

FOAM Goals ● Platform independence, well-defined semantics – Optimizations done at FOAM level are platform independent ● Efficient mapping to ANSI C and Common Lisp ● Has a structure that allows easy manipulation – FOAM-to-FOAM transformations to optimize the code at FOAM level.

Structure ● FOAM unit – compilation unit (source file) ● Each unit: – List of declarations – List of definitions ● Declarations – Special slots: globals, constants ● Definitions: programs, initialization

Simple Example ● simple2.as #include "aldor" #include "aldorio" import from Integer; 1; ● simple2.fm ● simple3.c

High-level overview of FOAM FOAM.as.fm Built-ins C LISP FORTRAN FOAM Domains (Run- time) PCal l BCal l Import/expo rt

FOAM Grammar

Unit ● [Unit ] ● ::= [DEnv... ] ● ::= [DFluid... ]

Declarations ● ::= [DFmt... ] ● ::= [DDecl... : Decl>] ● ::= [Decl ] ● ::= [GDecl ]

Definitions ● ::= [DDef... ] ● ::= [Def ]

Commands ● ::= | | one of ● [Seq... ] ● [Goto ] ● [If ] ● [Select... ] ● [Return ]

Commands (Contd) ● [Set ] ● [Lose ] ● [PushEnv ] ● [PopEnv ] ● [Protect ] ● [Throw ] ● [Halt ]

Expressions ● ::= | one of ● [BVal ] ● [Label ] ● [Cast ] ● [ANew ] ● [RNew ] ● [TRNew ] ● [RCopy ]

Expressions (Contd) ● [BCall... ] ● [CCall... ] ● [OCall... ] ● [PCall... ] ● [MFmt ] ● [Values... ] ● [Catch ]

Values ● ::= |

References ● ::= one of ● [AElt ] ● [RElt ] ● [IRElt ] ● [TRElt ] ● [EElt ] ● [Const ] ● [Glo ]

References (Contd) ● [Fluid ] ● [Par ] ● [Loc ] ● [Lex ] ● [Env ] ● [EEnv ] ● [CEnv ] ● [CProg ] ● [EInfo ] ● [PRef ]

Data and Types ● ::= Nil | Char | Bool | Byte | HInt | SInt | HInt | SInt | BInt | SFlo | DFlo | Arr | Rec | Prog | Clos | Ptr ● ::= Nil | Char | Bool | Byte | HInt | SInt | BInt | SFlo | DFlo | Arr | Rec | Env | Prog | Clos | Ptr | Word | Arb | NOp

FOAM Types ● Primitive Types – Boolean: Bool – Numeric ● Floating Point: SFlo, DFlo ● Integral: Char, Byte, SInt, HInt ● Reference Types – Ptr, Clos, Env, BInt – Arr, Rec, Prog, NOp

Programs ● [Prog... ] ● t – the return type ● f – the format of the return type, if t is NOp ● b – contains different flags: generator, side-effects, optimization info ● size – the size of prog including the programs called ● time – estimated running time ● loc - local varibles ● Lex – an array of formats of lexical levels ● C0... c n – commands performed in sequence

Protocols ● Describe the interface used for accessing objects ● FOAM_Proto_Foam – natural mapping for FOAM objects ● FOAM_Proto_Other – natural mapping for objects in the hosting system ● FOAM_Proto_Init – initializer of a unit ● FOAM_Proto_C – objects are coming from C ● FOAM_Proto_Lisp – objects are coming from Lisp ● FOAM_Proto_Fortran – objects are coming from FORTRAN

Built-in Operations ● Operations on Bool – contains only values true and false – And, Or evaluate both arguments – Examples: true, false, Not, And, Or, EQ, NE ● Operations on Char – can be mapped to native set (EBCDIC, ASCII) – Space, newline, isDigit, EQ, lower, ord, num,...

Built-in Operations (Contd) ● Operations on SFlo, DFlo ● Operations on Byte, HInt, SInt, BInt ● Operations on Ptr ● Text Operations: FormatXXX, ScanXXX ● Conversion Operations

Semantics of FOAM Programs ● A FOAM program is a set of Units ● One unit is considered to be the starting unit ● The execution starts with the first program of the starting unit ● Only Globals are shared among units ● The order of evaluation of arguments of a call is undefined ● For PCall the order is defined according to the protocol used

Runtime Support ● Written in Aldor ● Most of it offers support for domains and categories ● Support for debugging

Optimizations ● Aldor compiler uses aggressive optimization to obtain performace close to C code ● Optimizations like: dead variable elimination, procedure integration, constant folding, copy propagation, peephole optimizations, common subexpression elimination. ● As a result of these optimizations the resulted code can be 10s or 100s times faster than unoptimized code