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

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

Apr 01, 2015

Download

Documents

Tayler Popp
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introduction to FOAM (the intermediate language for Aldor) Laurentiu Dragan UWO/ORCCA Programming Languages Group.

Introduction to FOAM (the intermediate language for Aldor)

Laurentiu DraganUWO/ORCCA Programming Languages Group

Page 2: 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

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

What is FOAM

● First Order Abstract Machine (FOAM)● Intermediate languages

– LIR, MIR, HIR

● FOAM – HIR● Developed at IBM by Dr. Stephen Watt

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

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.

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

Structure

● FOAM unit – compilation unit (source file)● Each unit:

– List of declarations– List of definitions

● Declarations– Special slots: globals, constants

● Definitions: programs, initialization

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

Simple Example

● simple2.as#include "aldor"#include "aldorio"

import from Integer;

1;

● simple2.fm● simple3.c

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

High-level overview of FOAM

FOAM.as .fm

Built-ins

CLISP

FORTRANFOAM

Domains(Run-time)

PCall

BCall

Import/export

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

FOAM Grammar

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

Unit

● [Unit <DFmt> <DDef>]

● <DEnv> ::= [DEnv <e0: Int> ... <en-1: Int>]

● <DFluid> ::= [DFluid <i0: Int> ... <fi-1: Int>]

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

Declarations

● <DFmt> ::= [DFmt <f0: DDecl> ... <fn-1: DDecl>]

● <DDecl> ::= [DDecl <u: Byte> <d0: Decl> ... <dn-1>: Decl>]

● <Decl> ::= [Decl <t: Type> <s: String> <p: Byte> <r0: Byte> <r1: Byte>]

● <GDecl> ::= [GDecl <t: Type> <s: String> <r0: Byte> <r1: Byte> <dir: Byte> <p: Byte>]

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

Definitions

● <DDef> ::= [DDef <v0: Def> ... <vn-1: Def>]● <Def> ::= [Def <r: Reference> <v: Value>]

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

Commands● <Cmd> ::= <Def> | <Expr> | one of

● [Seq <c0: Cmd> <c1: Cmd> ... <cn: Cmd>]● [Goto <l: Label>]● [If <e: Expr> <l: Label>]

● [Select <e: Expr> <l0: Label> ... <ln-1: Label>]

● [Return <e: Expr>]

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

Commands (Contd)

● [Set <r: Reference> <e: Expr>]● [Lose <r: Reference>]● [PushEnv <f: Int> <e: Reference>]● [PopEnv ]● [Protect <e: Expr> <p:Reference>]● [Throw <to: Expr> <e: Expr>]● [Halt ]

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

Expressions

● <Expr> ::= <Value> | one of● [BVal <n: Int>]● [Label <n: Int>]● [Cast <t: Type> <e: Expr>]● [ANew <t: Type> <e: Expr>]● [RNew <f: Int>]● [TRNew <f: Int>]● [RCopy <f: Int> <e: Expr>]

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

Expressions (Contd)

● [BCall <o: Int> <e0: Expr> ... <en-1: Expr>]

● [CCall <t: Type> <c: Expr> <e0: Expr> ... <en-1: Expr>]

● [OCall <t: Type> <f: Expr> <e: Reference> <e0: Expr> ... <en-1: Expr>]

● [PCall <p: Int> <t: Type> <f: Expr> <e: Reference> <e0: Expr> ... <en-1: Expr>]

● [MFmt <f: Int> <c: Expr>]

● [Values <e0: Expr> ... <en: Expr>]● [Catch <t: Name> <e: Expr>]

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

Values

● <Value> ::= <Reference> | <Data>

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

References

● <Reference> ::= one of● [AElt <t: Type> <n: Expr> <a: Expr>]● [RElt <f: Int> <r: Expr> <n: Int>]● [IRElt <f: Int> <r: Expr> <n: Int>]

● [TRElt <f0: Int> <f1: Int> <r: Expr> <i: Expr> <n: Int>]

● [EElt <l: Int> <n: Int> <f: Int> <e: Reference>]

● [Const <n: Int>]● [Glo <n: Int>]

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

References (Contd)

● [Fluid <n: Int>]● [Par <n: Int>]● [Loc <n: Int>]● [Lex <l: Int> <n: Int>]● [Env <l: Int>]● [EEnv <l: Int> <e: Reference>]● [CEnv <c: Expr>]● [CProg <c: Expr>]● [EInfo <e: Expr>]● [PRef <r: Int> <p: Expr>]

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

Data and Types● <Data> ::=

Nil | Char | Bool | Byte | HInt | SInt | HInt | SInt | BInt | SFlo | DFlo | Arr | Rec | Prog | Clos | Ptr

● <Type> ::= Nil | Char | Bool | Byte | HInt | SInt | BInt | SFlo | DFlo | Arr | Rec | Env | Prog | Clos | Ptr | Word | Arb | NOp

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

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

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

Programs

● [Prog <n: Int> <m: Int> <t: Type> <f: Int> <b: Int> <size: Int> <time: Int> <par: DDecl> <loc: DDecl> <lex: DEnv> <fluid: DFluid> <c0: Cmd> <c1: Cmd> ... <cn-1: Cmd>]

● 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

... cn – commands performed in sequence

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

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

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

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, ...

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

Built-in Operations (Contd)

● Operations on SFlo, DFlo● Operations on Byte, HInt, SInt, BInt● Operations on Ptr● Text Operations: FormatXXX , ScanXXX● Conversion Operations

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

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

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

Runtime Support

● Written in Aldor● Most of it offers support for domains and

categories● Support for debugging

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

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