OpenModelica Compiler (OMC) Overview

Similar documents
OpenModelica Compiler (OMC) Overview

OpenModelica Environment and Modelica Overview

Modelica Environments and OpenModelica

Technical Overview of OpenModelica and its Development Environment

The OpenModelica Modeling, Simulation, and Development Environment

Technical Overview of OpenModelica and its Development Environment

OpenModelica System Documentation

OpenModelica Development Environment with Eclipse Integration for Browsing, Modeling, and Debugging

Technical Overview of OpenModelica and its Development Environment

INTRODUCTION TO OBJECT-ORIENTED MODELING AND SIMULATION WITH MODELICA USING THE OPENMODELICA ENVIRONMENT

Technical Overview of OpenModelica and its Development Environment

Technical Overview of OpenModelica and its Development Environment

OpenModelica OMShell and OMNotebook Introduction and Exercises

int a; class x { public int a; class x { float b; Asda ad public int a; Asa asad Aac sdscfcc c a

and its Development Environment

Modelica Change Proposal MCP-0019 Flattening (In Development) Proposed Changes to the Modelica Language Specification Version 3.

The Open Source Modelica Project

Towards Run-time Debugging of Equation-based Object-oriented Languages

What follows is a list of the OMC APIs with their syntax and examples.

GENERATING A MODELICA COMPILER FROM NATURAL SEMANTICS SPECIFICATIONS

Towards Modelica 4 Meta-Programming and Language Modeling with MetaModelica 2.0

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

An Eclipse-based Integrated Environment for Developing Executable Structural Operational Semantics Specifications

OMEdit OpenModelica Connection Editor

OMEdit. OpenModelica Connection Editor. User Manual Version April 2011

Interpreting Languages for the Java Platform

Task-Graph-Based Parallelization of Modelica-Simulations. Tutorial on the Usage of the HPCOM-Module

Meta-Programming with Modelica. Model Transformations

Abstract Syntax Can Make the Definition of Modelica Less Abstract

State Machines in OpenModelica

OpenModelica Eclipse Plugin and MetaModelica Exercises

Implementation of F# language support in JetBrains Rider IDE

arxiv:cs/ v1 [cs.ma] 27 Jan 2004

1st Annual OpenModelica Workshop Feb 2, 2009

Modelica Based Parser Generator with Good Error Handling

The NetRexx Interpreter

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Modelica Development Tooling for Eclipse

Formal editing: jedit-mmt. Narrative editing: LaTeX-MMT. Browsing: MMT web server. Building: MMT scripting language. The MMT API: A Generic MKM System

Semantic actions for expressions

Meta-Programming and Language Modeling with MetaModelica 1.0

Introduction Variables Helper commands Control Flow Constructs Basic Plumbing. Bash Scripting. Alessandro Barenghi

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

AUTOMATIC PARALLELIZATION OF OBJECT ORIENTED MODELS ACROSS METHOD AND SYSTEM

CSE 401 Midterm Exam Sample Solution 11/4/11

An OpenModelica Python Interface and its use in PySimulator

A comparison of metacompilation approaches to implementing Modelica

Anatomy of a Compiler. Overview of Semantic Analysis. The Compiler So Far. Why a Separate Semantic Analysis?

Enhanced Class Design -- Introduction

Towards Unified System Modeling with the ModelicaML UML Profile

JavaScript CS 4640 Programming Languages for Web Applications

Automatic Parallelization of Mathematical Models Solved with Inlined Runge-Kutta Solvers

A Modular. OpenModelica. Compiler Backend

Semantic Analysis. Lecture 9. February 7, 2018

Modelica3D. Platform Independent Simulation Visualization. Christoph Höger. Technische Universität Berlin Fraunhofer FIRST

An Evaluation of Domain-Specific Language Technologies for Code Generation

Programming in Visual Basic with Microsoft Visual Studio 2010

The role of semantic analysis in a compiler

PROGRAMMING IN VISUAL BASIC WITH MICROSOFT VISUAL STUDIO Course: 10550A; Duration: 5 Days; Instructor-led

The Environment Model. Nate Foster Spring 2018

COS 320. Compiling Techniques

CSE 504: Compiler Design. Intermediate Representations Symbol Table

Fault Tolerance Analysis using OpenModelica with Figaro Extensions for Modelica

Programming Assignment 5 Interpreter and Static Analysis

About the Authors... iii Introduction... xvii. Chapter 1: System Software... 1

The PEPA Eclipse Plug-in

Updated after review Removed paragraph mentioned java source code.

Programming Project II

Mo E A Communication Service Between Modelica Compilers and Text Editors

Towards a model driven Modelica IDE

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Parsing Scheme (+ (* 2 3) 1) * 1

Integrated Model-Driven Development Environments for Equation-Based Object-Oriented Languages

CS 4201 Compilers 2014/2015 Handout: Lab 1

News in RSA-RTE 10.0 updated for sprint Mattias Mohlin/Anders Ek, June 2016

Programming Assignment IV

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, November 2017

UNIVERSITY OF COLUMBIA ADL++ Architecture Description Language. Alan Khara 5/14/2014

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Modelica Meta-Programming and Symbolic Transformations

Programming Assignment IV Due Monday, November 8 (with an automatic extension until Friday, November 12, noon)

The Compiler So Far. CSC 4181 Compiler Construction. Semantic Analysis. Beyond Syntax. Goals of a Semantic Analyzer.

CSE P 501 Compilers. Static Semantics Hal Perkins Winter /22/ Hal Perkins & UW CSE I-1

CS153: Compilers Lecture 14: Type Checking

News in RSA-RTE 10.1 updated for sprint Mattias Mohlin, January 2018

Noopur Gupta Eclipse JDT/UI Committer IBM India

cmps104a 2002q4 Assignment 3 LALR(1) Parser page 1

We d like to hear your suggestions for improving our indexes. Send to

The Environment Model

CSCE 314 Programming Languages. Type System

MWorks: a Modern IDE for Modeling and Simulation of Multidomain Physical Systems Based on Modelica

Integration of OpenModelica in Ptolemy II

LECTURE NOTES ON COMPILER DESIGN P a g e 2

5. Semantic Analysis!

Lecture 12: Conditional Expressions and Local Binding

Semantic actions for declarations and expressions

SYED AMMAL ENGINEERING COLLEGE (An ISO 9001:2008 Certified Institution) Dr. E.M. Abdullah Campus, Ramanathapuram

SUDO(5) File Formats Manual SUDO(5)

The Compiler So Far. Lexical analysis Detects inputs with illegal tokens. Overview of Semantic Analysis

Transcription:

OpenModelica Compiler (OMC) Overview, Adrian Pop, Peter Aronsson OpenModelica Course, 2006 11 06 1

OpenModelica Environment Architecture Eclipse Plugin Editor/Browser Emacs Editor/Browser Interactive session handler Graphical Model Editor/Browser Textual Model Editor DrModelica OMNoteBook Model Editor Execution Modelica Compiler Modelica Debugger 2

OpenModelica Compiler/Interpreter Version (1.4.2) released September, 2006 Currently implemented in 110 000 lines of MetaModelica Includes code generation, BLT-transformation, index reduction, connection to DASSL, etc. Most of the Modelica language including classes, functions, inheritance, modifications, import, etc. Hybrid/Discrete event support 3

The Translation Process Modelica Graphical Editor Modelica Textual Editor Modelica Model Modelica Source code Modelica Model Translator Analyzer Optimizer Code generator C Compiler Simulation Flat model Sorted equations Optimized sorted equations C Code Executable 4

Invoking OMC two Methods Calling OMC from the command line Calling OMC as a server via the Corba interface 5

Command Line Invokation of OMC omc file.mo Return flat Modelica by code flattening of the class in the file file.mo which is a the top of the instance hierarchy (toplevel class) omc file.mof Put the flat Modelica produced by flattening of the toplevel class within file.mo in the file named file.mof. omc file.mos Run the Modelica script file called file.mos. 6

Some General OMC Flags omc +s file.mo/.mof Generate simulation code for the model last in file.mo or file.mof. The following files are generated: modelname.cpp, modelname.h, modelname_init.txt, modelname.makefile. omc +q Quietly run the compiler, no output to stdout. omc +d=blt Perform BLT transformation of the equations. omc +d=interactivecorba Run the compiler in interactive mode with Corba communication. This is the standard communication that is used for the interactive mode omc +d=interactive Run the compiler in interactive mode with Socket communication. This functionality is somewhat depreciated and is replaced by the newer Corba communication module, except for debug usage. This flag currently only works under Linux and Cygwin. omc +d=failtrace The most useful debugging flag. Turns on error output from fail catch-all cases present at the end of many functions in omc. 7

OpenModelica Client-Server Architecture OMC Server Including Compiler, Interpreter, etc. Parse Corba Client: Graphic Model Editor Client: OMShell Interactive Session Handler SCode Interactive Untyped API Client: Eclipse Plugin MDT Inst Ceval system Typed Checked Command API plot etc. 8

OMC Corba Client-Server API Simple text-based (string) communication in Modelica Syntax API supporting model structure query and update Example Calls: Calls fulfill the normal Modelica function call syntax.: savemodel("myresistorfile.mo",myresistor) will save the model MyResistor into the file MyResistorFile.mo. For creating new models it is most practical to send a model, e.g.: model Foo end Foo; or, e.g., connector Port end Port; 9

Some of the Corba API functions 10 savemodel(a1<string>,a2<cref>) loadfile(a1<string>) loadmodel(a1<cref>) deleteclass(a1<cref>) addcomponent(a1<ident>,a2<cref>, A3<cref>,annotate=<expr>) deletecomponent(a1<ident>, A2<cref>) updatecomponent(a1<ident>, A2<cref>, A3<cref>,annotate=<expr>) addclassannotation(a1<cref>, annotate=<expr>) getcomponents(a1<cref>) getcomponentannotations(a1<cref>) getcomponentcount(a1<cref>) getnthcomponent(a1<cref>,a2<int>) getnthcomponentannotation( A1<cref>,A2<int>) getnthcomponentmodification( A1<cref>,A2<int>)?? getinheritancecount(a1<cref>) getnthinheritedclass(a1<cref>, Saves the model (A2) in a file given by a string (A1). This call is also in typed API. Loads all models in the file. Also in typed API. Returns list of names of top level classes in the loaded files. Loads the model (A1) by looking up the correct file to load in $MODELICAPATH. Loads all models in that file into the symbol table. Deletes the class from the symbol table. Adds a component with name (A1), type (A2), and class (A3) as arguments. Optional annotations are given with the named argument annotate. Deletes a component (A1) within a class (A2). Updates an already existing component with name (A1), type (A2), and class (A3) as arguments. Optional annotations are given with the named argument annotate. Adds annotation given by A2( in the form annotate= classmod(...)) to the model definition referenced by A1. Should be used to add Icon Diagram and Documentation annotations. Returns a list of the component declarations within class A1: {{Atype,varidA, commenta },{Btype,varidB, commentb }, {...}} Returns a list {...} of all annotations of all components in A1, in the same order as the components, one annotation per component. Returns the number (as a string) of components in a class, e.g return 2 if there are 2 components. Returns the belonging class, component name and type name of the nth component of a class, e.g. A.B.C,R2,Resistor, where the first component is numbered 1. Returns the flattened annotation record of the nth component (A2) (the first is has no 1) within class/component A1. Consists of a comma separated string of 15 values, see Annotations in Section 2.4.4 below, e.g false,10,30,... Returns the modification of the nth component (A2) where the first has no 1) of class/component A1. Returns the number (as a string) of inherited classes of a class. Returns the type name of the nth inherited class of a class. The first class has number 1.

Detailed Architecture of OMC (OpenModelica Compiler).mo Parse Data Type Modules: Absyn Types Main ClassLoader SCode DAE Absyn Prefix.Prefix ClassInf.Event Prefix SCode /explode ClassInf SCode Exp.Exp (Env, name) Mod Lookup SCode.Class (Env, name) SCode.Exp Inst Static Ceval (Exp.Exp, Types.Type) Connect Types.Mod SCode.Mod Exp.Componentref Exp.Ident ClassInf.State DAE DAE: Equations Algorithms Values.Value Exp.Exp DAE: Functions DAE Derive CodeGen Dump DAEEXT Exp.Exp Utility Modules: Dump DAELow VarTransform DAE DAELow.DAELow SimCodeGen Debug Flat Modelica C code DAE, substlist Algorithm Exp Builtin Util ModUtil Print System RTOpts 11

Three Kinds of Modules in OMC Function modules that perform a specified function, e.g. Lookup, code instantiation, etc. Data type modules that contain declarations of certain data types, e.g. Absyn that declares the abstract syntax. Utility modules that contain certain utility functions that can be called from any module, e.g. the Util module with list processing funtions. Note: Some modules perform more than one kind of function 12

Approximate Description The Main program calls a number of modules, including the parser (Parse), SCode, etc. The parser generates abstract syntax (Absyn) which is converted to the simplified (SCode) intermediate form. The model flattering module (Inst) is the most complex module, and calls many other modules. It calls Lookup to find a name in an environment, calls Prefix for analyzing prefixes in qualified variable designators (components), calls Mod for modifier analysis and Connect for connect equation analys. It also generates the DAE equation representation which is simplified by DAELow and fed to the SimCodeGen and CodeGen code generators The Ceval module performs compile-time or interactive expression evaluation and returns values. The Static module performs static semantics and type checking. The DAELow module performs BLT sorting and index reduction. The DAE module internally uses Exp.Exp, Types.Type and Algorithm.Algorithm; the SCode module internally uses Absyn The Vartransform module called from DAELow performs variable substitution during the symbolic transformation phase (BLT and index reduction). 13

Short Overview of OMC Modules (A-D) Absyn Abstract Syntax Algorithm Data Types and Functions for Algorithm Sections Builtin Builtin Types and Variables Ceval Evaluation/interpretation of Expressions. ClassInf Inference and check of class restrictions for restricted classes. ClassLoader Loading of Classes from $MODELICAPATH Codegen Generate C Code from functions in DAE representation. Connect Connection Set Management Corba Modelica Compiler Corba Communication Module 14

Short Overview of OMC Modules (D-G) DAE DAE Equation Management and Output DAEEXT External Utility Functions for DAE Management DAELow Lower Level DAE Using Sparse Matrises for BLT Debug Trace Printing Used for Debugging Derive Differentiation of Equations from DAELow Dump Abstract Syntax Unparsing/Printing DumpGraphviz Dump Info for Graph visualization of AST Env Environment Management Exp Typed Expressions after Static Analysis /*updated) Graphviz Graph Visualization from Textual Representation 15

Short Overview of OMC Modules (I-P) Inst Flattening of Modelica Models Interactive Model management and expression evaluation Keeps interactive symbol tables. Contains High performance API, etc. Lookup Lookup of Classes, Variables, etc. Main The Main Program. Calls Interactive, the Parser, the Compiler, etc. Mod Modification Handling ModSim /*Depreciated, not used). Previously communication for Simulation, Plotting, etc. ModUtil Modelica Related Utility Functions Parse Parse Modelica or Commands into Abstract Syntax Prefix Handling Prefixes in Variable Names Print Buffered Printing to Files and Error Message Printing 16

Short Overview of OMC Modules (R-V) SCode Simple Lower Level Intermediate Code Representation. SimCodegen Generate simulation code for solver from equations and algorithm sections in DAE. Socket (Partly Depreciated) OpenModelica Socket Communication Static Static Semantic Analysis of Expressions System System Calls and Utility Functions TaskGraph Building Task Graphs from Expressions and Systems of Equations. Optional module. TaskGraphExt External Representation of Task Graphs. Optional module. Types Representation of Types and Type System Info Util General Utility Functions Values Representation of Evaluated Expression Values VarTransform Binary Tree Representation of Variable Transformations 17