Bootstrapping a Modelica Compiler Martin Sjölund, Peter Fritzson, Adrian Pop Linköping University 2011-03-22 8 th International Modelica Conference Dresden,

Slides:



Advertisements
Similar presentations
Sml2java a source to source translator Justin Koser, Haakon Larsen, Jeffrey Vaughan PLI 2003 DP-COOL.
Advertisements

Debugging Natural Semantics Specifications Adrian Pop and Peter Fritzson Programming Environment Laboratory Department of Computer and Information Science.
Peter Fritzson 1 MetaModelica for Meta-Modeling and Model Transformations Peter Fritzson, Adrian Pop, Peter Aronsson OpenModelica Course at INRIA, 2006.
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
Garbage Collection  records not reachable  reclaim to allow reuse  performed by runtime system (support programs linked with the compiled code) (support.
Programming in Visual Basic
Chapter 8 Runtime Support. How program structures are implemented in a computer memory? The evolution of programming language design has led to the creation.
SableCC SableCC is developed by professors and graduate students at McGill University and is open source (licensed under the Apache License, Version 2.0)‏
Visual Web Information Extraction With Lixto Robert Baumgartner Sergio Flesca Georg Gottlob.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
An Eclipse-based Integrated Environment for Developing Executable Structural Operational Semantics Specifications Adrian Pop and Peter Fritzson Programming.
A Portable Debugger for Algorithmic Modelica Code Adrian Pop, Peter Fritzson Programming Environments Laboratory (PELAB) Department of Computer and Information.
T-diagrams “Mommy, where do compilers come from?” Adapted from:
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Environments and Evaluation
Common Lisp! John Paxton Montana State University Summer 2003.
OpenModelica Development Environment with Eclipse Integration Adrian Pop, Peter Fritzson, Andreas Remar, Elmir Jagudin, David Akhvlediani Programming Environment.
C++ for Java Programmers Chapter 1 Basic Philosophical Differences.
Comparison of OO Programming Languages © Jason Voegele, 2003.
C++ Programming. Table of Contents History What is C++? Development of C++ Standardized C++ What are the features of C++? What is Object Orientation?
Media and Fluid Draft Adrian Pop & Martin Sjölund
Towards a Text Generation Template Language for Modelica Peter Fritzson *, Pavol Privitzer +, Martin Sjölund *, Adrian Pop * + Institute of Pathological.
Performance Enhancements analysis and proposals Draft Adrian Pop
© 2008, Renesas Technology America, Inc., All Rights Reserved 1 Purpose  This training module provides an overview of optimization techniques used in.
Lecture 10 : Introduction to Java Virtual Machine
Sigma Lisp Σλ Sam Davis Nick Alexander. What is Sigma Lisp? ● New dialect of Lisp ● Designed to be as expressive as possible.
Programming Lifecycle
Algorithm Programming Bar-Ilan University תשס"ח by Moshe Fresko.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
Performance Enhancements analysis and proposals Draft Adrian Pop, Peter Aronsson, Jan Brugård
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
CS 460/660 Compiler Construction. Class 01 2 Why Study Compilers? Compilers are important – –Responsible for many aspects of system performance Compilers.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
CS535 Programming Languages Chapter - 10 Functional Programming With Lists.
Planning a compiler Source Language –A subset of C Target Language –Assembler Performance Criteria –Compiler speed –Code quality –Error diagnostics –Portability.
Object Oriented Software Development 4. C# data types, objects and references.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Visual Programming Borland Delphi. Developing Applications Borland Delphi is an object-oriented, visual programming environment to develop 32-bit applications.
Quiz 1 A sample quiz 1 is linked to the grading page on the course web site. Everything up to and including this Friday’s lecture except that conditionals.
CMake: Experience in ALICE P. Hristov 19/06/12. History I Recursive makefiles (F.Carminati): – Problems in dependencies – Slow "Recursive Makefiles.
Chapter 1 Introduction Samuel College of Computer Science & Technology Harbin Engineering University.
Functional Programming
Object Oriented Programming in
CSC 222: Object-Oriented Programming
Component 1.6.
CSC 222: Computer Programming II
Before You Begin Nahla Abuel-ola /WIT.
Basic 1960s It was designed to emphasize ease of use. Became widespread on microcomputers It is relatively simple. Will make it easier for people with.
Introduction to Compiler Construction
Component 1.6.
COSC 1306 COMPUTER SCIENCE AND PROGRAMMING
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 5, 09/25/2003 Prof. Roy Levow.
Compiler Construction (CS-636)
Dynamic Memory Allocation
CS 363 – Chapter 1 What is a programming language? Kinds of languages
CSC 222: Object-Oriented Programming
CMPE 152: Compiler Design December 5 Class Meeting
Mini Language Interpreter Programming Languages (CS 550)
Lesson Objectives Aims Key Words Compiler, interpreter, assembler
CS 153: Concepts of Compiler Design October 30 Class Meeting
.Net Framework Details Imran Rashid CTO at ManiWeber Technologies.
CO4301 – Advanced Games Development Week 3 Parsing Continued
ICOM 4029 Fall 2003 Lecture 2 (Adapted from Prof. Necula UCB CS 164)
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
SPL – PS1 Introduction to C++.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
Presentation transcript:

Bootstrapping a Modelica Compiler Martin Sjölund, Peter Fritzson, Adrian Pop Linköping University th International Modelica Conference Dresden, Germany

Vision Build a modular and extensible Modelica compiler Compiler functionality resides in Modelica libraries Build toolchains with a Modelica editor using the components in the compiler libraries

Bootstrapping How to compile a compiler for language A, written in a subset of the same language (Cross-)Compile using an existing A-compiler Use an existing A-interpreter Write an A-compiler in language B Circular dependency Important not to break the compiler Cannot use language features until you implement them yourself

MetaModelica To realize our vision, we need our compiler to understand the language that the libraries are written in The libraries should be written in some dialect of Modelica MetaModelica 1.0 Extended subset of Modelica OpenModelica is written in this language and compiled using MMC

Why Bootstrapping? MMC, the old MetaModelica Compiler Written in RML+SML Hard to maintain Hard to extend OMC, the Modelica+MetaModelica Compiler We get language features for free Easy to extend Easy to port MetaModelica extensions to Modelica Debugging, Profiling, Testing

MetaModelica MetaModelica 1.0 is created as an extended Modelica subset Implementation of a MetaModelica compiler using a translation to RML Automatic translation of OpenModelica source code (written in RML) to MetaModelica Implemention of MetaModelica extensions in OpenModelica Code generation, runtime, and garbage collection MetaModelica 2.0 is the result of implementing MetaModelica 1.0 in OpenModelica

MetaModelica 2.0+ Extensions Features we cannot use due to RML/MMC being hard to extend if-statement, if-expressions Builtin support for list mapping, filtering, folding Shorter syntax for polymorphic functions More powerful patterns when pattern-matching, including guard-expressions A richer package structure (RML/MMC is flat) Inheritance, modifications, redeclare Default bindings of local variables

Structure of a Modelica Compiler ParserTranslator Symbolic Math Interpreter AnalyzerOptimizerCodeGen

What is missing in Modelica? Implementing a Parser or Symbolic Math Library in Modelica ”Impossible” Modelica only has flat data structures Expressions are recursive data structures (trees)

Introducing the Union Type uniontype Expression record REAL "A real constant" Real r; end REAL; record ADD "lhs + rhs" Expression lhs, rhs; end ADD; record SUB "lhs - rhs" Expression lhs, rhs; end SUB; end Expression; AD D RE AL 1.5 SU B AD D RE AL (( ) - 2.5)

Lists No parametric union types Defining a new uniontype for each kind of list is not desirable The list is a common data type So we introduce a List type array(1,2,...,n) CALL array IN T 1 IN T 2... IN T n

Options, Tuples Option : a new type similar to null in Java NONE() SOME(value) Tuples : Anonymous records (1,1.5,"abc",true)

Accessing Data Structures Accessor functions j := if not listEmpty(lst) then 2*listGet(lst, 1) else 3; Introducing pattern-matching in Modelica j := match lst local Integer i; case (i :: _) then 2*i; else 3; end match;

Polymorphism Reusable functions Works for any type Boxed data types No need to extend functions and redeclare types function listFirst input List lst; output A first; algorithm first :: _ := lst; end listFirst;

The Bootstrapped Compiler First version, Nov-Dec x slower than MMC Slow compilation speed (hours) Most tests failed due to lack of memory Jan-Feb 2011 Speed similar to MMC Faster compilation than MMC Most tests succeed despite lack of garbage collection

Garbage collection (I) First version, March 2011 GC is currently slower than MMC GC (~50 times) Details Based on mark-and-sweep garbage collection Live data is marked starting from roots (variables on the stack and local variables) Everything that is not marked becomes free memory in the sweep phases (which also removes the marking on live data)

Garbage collection (II)

Optimizations PEXPipe.mo before and after optimizations

Compiler Performance

Outlook Spring 2011 Optimizations in the garbage collector Testing the implementation on all platforms (Linux, OMDEV, OSX and Visual Studio) Fall 2011 Replacing MMC with OMC Rewriting compiler sources using new language extensions Add more optimizations

Thanks for listening! Visit us at

Compilation of OpenModelica