Introduction to FOAM the intermediate language for Aldor

  • Slides: 27
Download presentation
Introduction to FOAM (the intermediate language for Aldor) Laurentiu Dragan UWO/ORCCA Programming Languages Group

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

Overview ● What is FOAM ● Short example ● FOAM instructions – Grammar ●

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,

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

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: ● –

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 ● simple 2. as #include "aldor" #include "aldorio" import from Integer; 1;

Simple Example ● simple 2. as #include "aldor" #include "aldorio" import from Integer; 1; ● simple 2. fm ● simple 3. c

High-level overview of FOAM BCal l PCal l Import/expo rt

High-level overview of FOAM BCal l PCal l Import/expo rt

FOAM Grammar

FOAM Grammar

Unit ● [Unit <DFmt> <DDef>] ● <DEnv> : : = [DEnv <e 0: Int>.

Unit ● [Unit <DFmt> <DDef>] ● <DEnv> : : = [DEnv <e 0: Int>. . . <en-1: Int>] ● <DFluid> : : = [DFluid <i 0: Int>. . . <fi-1: Int>]

Declarations ● ● <DFmt> : : = [DFmt <f 0: DDecl>. . . <fn-1:

Declarations ● ● <DFmt> : : = [DFmt <f 0: DDecl>. . . <fn-1: DDecl>] <DDecl> : : = [DDecl <u: Byte> <d 0: Decl>. . . <dn-1>: Decl>] <Decl> : : = [Decl <t: Type> <s: String> <p: Byte> <r 0: Byte> <r 1: Byte>] <GDecl> : : = [GDecl <t: Type> <s: String> <r 0: Byte> <r 1: Byte> <dir: Byte> <p: Byte>]

Definitions ● <DDef> : : = [DDef <v 0: Def>. . . <vn-1: Def>]

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

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

Commands ● <Cmd> : : = <Def> | <Expr> | one of ● [Seq <c 0: Cmd> <c 1: Cmd>. . . <cn: Cmd>] ● [Goto <l: Label>] ● [If <e: Expr> <l: Label>] ● ● [Select <e: Expr> <l 0: Label>. . . <ln-1: Label>] [Return <e: Expr>]

Commands (Contd) ● [Set <r: Reference> <e: Expr>] ● [Lose <r: Reference>] ● [Push.

Commands (Contd) ● [Set <r: Reference> <e: Expr>] ● [Lose <r: Reference>] ● [Push. Env <f: Int> <e: Reference>] ● [Pop. Env ] ● [Protect <e: Expr> <p: Reference>] ● [Throw <to: Expr> <e: Expr>] ● [Halt ]

Expressions ● <Expr> : : = <Value> | one of ● [BVal <n: Int>]

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>]

Expressions (Contd) ● ● [BCall <o: Int> <e 0: Expr>. . . <en-1: Expr>]

Expressions (Contd) ● ● [BCall <o: Int> <e 0: Expr>. . . <en-1: Expr>] [CCall <t: Type> <c: Expr> <e 0: Expr>. . . <en -1: Expr>] [OCall <t: Type> <f: Expr> <e: Reference> <e 0: Expr>. . . <en-1: Expr>] [PCall <p: Int> <t: Type> <f: Expr> <e: Reference> <e 0: Expr>. . . <en-1: Expr>] ● [MFmt <f: Int> <c: Expr>] ● [Values <e 0: Expr>. . . <en: Expr>] ● [Catch <t: Name> <e: Expr>]

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

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

References ● <Reference> : : = one of ● [AElt <t: Type> <n: Expr>

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 <f 0: Int> <f 1: Int> <r: Expr> <i: Expr> <n: Int>] [EElt <l: Int> <n: Int> <f: Int> <e: Reference>] ● [Const <n: Int>] ● [Glo <n: Int>]

References (Contd) ● [Fluid <n: Int>] ● [Par <n: Int>] ● [Loc <n: Int>]

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>]

Data and Types ● <Data> : : = Nil | Char | Bool |

Data and Types ● <Data> : : = Nil | Char | Bool | Byte | 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

FOAM Types ● ● Primitive Types – Boolean: Bool – Numeric ● Floating Point:

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 <n: Int> <m: Int> <t: Type> <f: Int> <b: Int> <size:

Programs ● [Prog <n: Int> <m: Int> <t: Type> <f: Int> <b: Int> <size: Int> <time: Int> <par: DDecl> <loc: DDecl> <lex: DEnv> <fluid: DFluid> <c 0: Cmd> <c 1: 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 ● C 0 . . . cn – commands performed in sequence

Protocols ● ● ● Describe the interface used for accessing objects FOAM_Proto_Foam – natural

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

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, is. Digit, EQ, lower, ord, num, . . .

Built-in Operations (Contd) ● Operations on SFlo, DFlo ● Operations on Byte, HInt, SInt,

Built-in Operations (Contd) ● Operations on SFlo, DFlo ● Operations on Byte, HInt, SInt, BInt ● Operations on Ptr ● Text Operations: Format. XXX , Scan. XXX ● Conversion Operations

Semantics of FOAM Programs ● A FOAM program is a set of Units ●

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

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

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 10 s or 100 s times faster than unoptimized code