Topic S Program Analysis and Transformation SEG 4110: Advanced Software Design and Reengineering.

Slides:



Advertisements
Similar presentations
Automated creation of verification models for C-programs Yury Yusupov Saint-Petersburg State Polytechnic University The Second Spring Young Researchers.
Advertisements

CPSC Compiler Tutorial 9 Review of Compiler.
Object-Oriented Analysis and Design
Irina Rychkova. 9/20061 Systemic approach towards model definition Model transformation semantics.
7M701 1 Software Engineering Object-oriented Design Sommerville, Ian (2001) Software Engineering, 6 th edition: Chapter 12 )
1 SWE Introduction to Software Engineering Lecture 23 – Architectural Design (Chapter 13)
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Building An Interpreter After having done all of the analysis, it’s possible to run the program directly rather than compile it … and it may be worth it.
Overview of program analysis Mooly Sagiv html://
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CH1 – A 1 st Program Using C#. Program Set of instructions which tell a computer what to do. Machine Language Basic language computers use to control.
1 Chapter One A First Program Using C#. 2 Objectives Learn about programming tasks Learn object-oriented programming concepts Learn about the C# programming.
A First Program Using C#
Chapter 17 Programming Tools The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming 1.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 1: A First Program Using C#. Programming Computer program – A set of instructions that tells a computer what to do – Also called software Software.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 10Slide 1 Architectural Design l Establishing the overall structure of a software system.
Compiler course 1. Introduction. Outline Scope of the course Disciplines involved in it Abstract view for a compiler Front-end and back-end tasks Modules.
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
Software Design Deriving a solution which satisfies software requirements.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 13 Introduction to Classes.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Architectural Design Yonsei University 2 nd Semester, 2014 Sanghyun Park.
Summarizing the Content of Large Traces to Facilitate the Understanding of the Behaviour of a Software System Abdelwahab Hamou-Lhadj Timothy Lethbridge.
Programming Fundamentals. Today’s Lecture Why do we need Object Oriented Language C++ and C Basics of a typical C++ Environment Basic Program Construction.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
©Ian Sommerville 2004Software Engineering, 7th edition. Chapter 14 Slide 1 Object-oriented Design.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 1, 08/28/03 Prof. Roy Levow.
CPS 506 Comparative Programming Languages Syntax Specification.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
1. 2 Preface In the time since the 1986 edition of this book, the world of compiler design has changed significantly 3.
Introduction to Compilers. Related Area Programming languages Machine architecture Language theory Algorithms Data structures Operating systems Software.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Object-Oriented Modeling: Static Models. Object-Oriented Modeling Model the system as interacting objects Model the system as interacting objects Match.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
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.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 28Slide 1 CO7206 System Reengineering 4.2 Software Reengineering Most slides are Slides.
Object-Oriented Programming Chapter Chapter
1 Technical & Business Writing (ENG-715) Muhammad Bilal Bashir UIIT, Rawalpindi.
1 Advanced Software Architecture Muhammad Bilal Bashir PhD Scholar (Computer Science) Mohammad Ali Jinnah University.
Chapter 5 System Modeling. What is System modeling? System modeling is the process of developing abstract models of a system, with each model presenting.
Object-Oriented Parsing and Transformation Kenneth Baclawski Northeastern University Scott A. DeLoach Air Force Institute of Technology Mieczyslaw Kokar.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Chapter 1: Introduction to Visual Basic.NET: Background and Perspective Visual Basic.NET Programming: From Problem Analysis to Program Design.
Connecting Architecture Reconstruction Frameworks Ivan Bowman, Michael Godfrey, Ric Holt Software Architecture Group University of Waterloo CoSET ‘99 May.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
The Dagstuhl Middle Model: An Overview Timothy C. Lethbridge SITE, University. of Ottawa
Object Oriented Programming and Data Abstraction Earl Huff Rowan University.
Slide 1 Chapter 8 Architectural Design. Slide 2 Topics covered l System structuring l Control models l Modular decomposition l Domain-specific architectures.
Csontos Péter, Porkoláb Zoltán Eötvös Loránd Tudományegyetem, Budapest ECOOP 2001 On the complexity of exception handling.
Advanced Computer Systems
Compiler Design (40-414) Main Text Book:
PRINCIPLES OF COMPILER DESIGN
Introduction to Compiler Construction
Introduction to Parsing (adapted from CS 164 at Berkeley)
Compiler Construction (CS-636)
SOFTWARE DESIGN AND ARCHITECTURE
CSE401 Introduction to Compiler Construction
Program Analysis and Transformation
Lecture 1 Introduction to Software Construction
Presentation transcript:

Topic S Program Analysis and Transformation SEG 4110: Advanced Software Design and Reengineering

SEG Topic S - Program Analysis2 Copyright Note These slides are derived from work by Bil Tzerpos a faculty member at York UniversityBil Tzerpos

SEG Topic S - Program Analysis3 Program Analysis Extracting information, in order to present abstractions of, or answer questions about, a software system Static Analysis Examines the source code Dynamic Analysis Examines the system as it is executing

SEG Topic S - Program Analysis4 What are we looking for when performing program analysis? Depends on our goals and the system In almost any language, we can find out information about variable usage In an OO environment, we can find out which classes use other classes, what is the inheritance structure, etc. We can also find potential blocks of code that can never be executed in running the program (dead code) Typically, the information extracted is in terms of entities and relationships —Can be metamodelled in a class diagram

SEG Topic S - Program Analysis5 Entities Entities are individuals that live in the system, and attributes associated with them. Some examples: Classes, along with information about their superclass, their scope, and ‘where’ in the code they exist. Methods/functions and what their return type or parameter list is, etc. Variables and what their types are, and whether or not they are static, etc.

SEG Topic S - Program Analysis6 Relationships Relationships are interactions between the entities in the system Relationships include Classes inheriting from one another. Methods in one class calling the methods of another class, and methods within the same class calling one another. A method referencing an attribute.

SEG Topic S - Program Analysis7 Information format for data extracted during program analysis Many different formats in use Simple but effective: RSF (Rigi Standard Format) inherit TRIANGLE SHAPE TA (Tuple Attribute) is an extension of RSF that includes a schema $INSTANCE SHAPE Class GXL is a XML-based extension of TA —Blow-up factor of 10 or more makes it rather cumbersome New formats based on YAML being developed

SEG Topic S - Program Analysis8 Representation of extracted information A fundamental issue in re-engineering Provides —means to generate abstractions —input to a computational model for analyzing and reasoning about programs —means for translation and normalization of programs

SEG Topic S - Program Analysis9 Key questions regarding representations of extracted information What are the strengths and weaknesses of each representations of programs? What levels of abstraction are useful?

SEG Topic S - Program Analysis10 Abstract Syntax Trees A translation of the source text in terms of operands and operators Omits superficial details, such as comments, whitespace All necessary information to generate further abstractions is maintained

SEG Topic S - Program Analysis11 AST production Four necessary elements to produce an AST: Lexical analyzer (turn input strings into tokens) Grammar (turn tokens into a parse tree) Domain Model (defines the nodes and arcs allowable in the AST) Linker (annotates the AST with global information, e.g. data types, scoping etc.)

SEG Topic S - Program Analysis12 AST example Input string: 1 + /* two */ 2 Parse Tree: AST (without global info) 21 + int Add 12 arg1arg2

SEG Topic S - Program Analysis13 Static Analysis Involves parsing the source code Usually creates an Abstract Syntax Tree Borrows heavily from compiler technology but stops before code generation Requires a grammar for the programming language Can be very difficult to get right

SEG Topic S - Program Analysis14 CppETS CppETS is a benchmark for C++ extractors A collection of C++ programs that pose various problems commonly found in parsing and reverse engineering Static analysis research tools typically get about 60% of the problems right

SEG Topic S - Program Analysis15 Example program #include class Hello { public: Hello(); ~Hello(); }; Hello::Hello() { cout << "Hello, world.\n"; } Hello::~Hello() { cout << "Goodbye, cruel world.\n"; } main() { Hello h; return 0; }

SEG Topic S - Program Analysis16 Example Q&A How many member methods are in the Hello class? Where are these member methods used? Answer: Two, the constructor (Hello::Hello()) and destructor (Hello::~Hello()) Answer: The constructor is called implicitly when an instance of the class is created. The destructor is called implicitly when the execution leaves the scope of the instance.

SEG Topic S - Program Analysis17 Static analysis in IDEs High-level languages lend themselves better to static analysis needs Rational Software Modeler does this with UML and Java Unfortunately, most legacy systems are not written in either of these languages

SEG Topic S - Program Analysis18 Static analysis pipeline Source code Parser Abstract Syntax Tree Fact base Fact extractor Applications Metrics tool Visualizer

SEG Topic S - Program Analysis19 Dynamic Analysis Provides information about the run-time behaviour of software systems, e.g. Component interactions Event traces Concurrent behaviour Code coverage Memory management Can be done with a debugger

SEG Topic S - Program Analysis20 Instrumentation Augments the subject program with code that transmits events to a monitoring application or writes relevant information to an output file A profiler tool can be used to examine the output file and extract relevant facts from it Instrumentation affects the execution speed and storage space requirements of the system

SEG Topic S - Program Analysis21 Instrumentation process Source code Annotator Annotated program Instrumented executable Compiler Annotation script

SEG Topic S - Program Analysis22 Dynamic analysis pipeline Instrumented executable CPU Dynamic analysis data Fact base Profiler Applications Metrics tool Visualizer

SEG Topic S - Program Analysis23 Non-instrumented approach One can also use debugger log files to obtain dynamic information Disadvantage: Limited amount of information provided Advantages: Less intrusive, more accurate performance measurements

SEG Topic S - Program Analysis24 Dynamic analysis issues Ensuring good code coverage is a key concern A comprehensive test suite is required to ensure that all paths in the code will be exercised Results may not generalize to future executions The size of run-time information is extraordinary large

SEG Topic S - Program Analysis25 Summary: Static vs. Dynamic Analysis Static Analysis Reasons over all possible behaviours (general results) Conservative and sound Challenge: Choose good abstractions Dynamic Analysis Observes a small number of behaviours (specific results) Precise and fast Challenge: Select representative test cases

SEG Topic S - Program Analysis26 Program Transformation The act of changing one program into another from a source language to a target language This is possible because of a program’s well-defined structure But for validity, we have to be aware of the semantics of each structure Used in many areas of software engineering: Compiler construction Software visualization Documentation generation Automatic software renovation

SEG Topic S - Program Analysis27 Program transformation application examples Converting to a new language dialect Migrating from a procedural language to an object-oriented one, e.g. C to C++ Adding code comments Requirement upgrading e.g. using 4 digits for years instead of 2 (Y2K) Structural improvements e.g. changing GOTOs to control structures Pretty printing

SEG Topic S - Program Analysis28 Simple program transformation Modify all arithmetic expressions to reduce the number of parentheses using the formula: (a+b)*c = a*c + b*c x := (2+5)*3 becomes x := 2*3 + 5*3

SEG Topic S - Program Analysis29 Two types of transformations Translation Source and target language are different Semantics remain the same Rephrasing Source and target language are the same Goal is to improve some aspect of the program such as its understandability or performance Semantics might change

SEG Topic S - Program Analysis30 Transformation tools There are many transformation tools Program-Transformation.org lists 90 of them TXL is one of the best Most are based on ‘term rewriting’ Other solutions use functional programming, lambda calculus, etc.