Presentation on theme: "Introduction to FOAM (the intermediate language for Aldor) Laurentiu Dragan UWO/ORCCA Programming Languages Group."— 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
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