ROSE Tutorial: A Tool for Building Source-to-Source ...
392 pages
English

ROSE Tutorial: A Tool for Building Source-to-Source ...

Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
392 pages
English
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres

Description

ROSE Tutorial:
A Tool for Building
Source-to-Source Translators
Draft Tutorial
(version 0.9.5a)
Daniel Quinlan, Markus Schordan, Richard Vuduc, Qing Yi
Thomas Panas, Chunhua Liao, and Jeremiah J. Willcock
Lawrence Livermore National Laboratory
Livermore, CA 94550
925-423-2668 (office)
925-422-6278 (fax)
{dquinlan,panas2,liao6}@llnl.gov
markus@complang.tuwien.ac.at
qingyi@cs.utsa.edu
richie@cc.gatech.edu
jewillco@osl.iu.edu
Project Web Page: www.rosecompiler.org
UCRL Number for ROSE User Manual: UCRL-SM-210137-DRAFT
UCRL Number for ROSE Tutorial: UCRL-SM-210032-DRAFT Number for ROSE Source Code: UCRL-CODE-155962
ROSE User Manual (pdf)
ROSE Tutorial (pdf)
ROSE HTML Reference (html only)
May 2, 2011 ii
May 2, 2011 Contents
1 Introduction 1
1.1 What is ROSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Why you should be interested in ROSE . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Problems that ROSE can address . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Examples in this ROSE Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.5 ROSE Documentation and Where To Find It . . . . . . . . . . . . . . . . . . . . 10
1.6 Using the Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.7 Required Makefile for Tutorial Examples . . . . . . . . . . . . . . . . . . . . . . . 11
I Working with the ROSE AST 13
2 Identity Translator 15
3 Simple AST Graph Generator 19
4 AST Whole Graph 23
5 ...

Sujets

Informations

Publié par
Nombre de lectures 219
Langue English
Poids de l'ouvrage 3 Mo

Extrait

ROSE Tutorial: A Tool for Building Source-to-Source Translators Draft Tutorial (version 0.9.5a) Daniel Quinlan, Markus Schordan, Richard Vuduc, Qing Yi Thomas Panas, Chunhua Liao, and Jeremiah J. Willcock Lawrence Livermore National Laboratory Livermore, CA 94550 925-423-2668 (office) 925-422-6278 (fax) {dquinlan,panas2,liao6}@llnl.gov markus@complang.tuwien.ac.at qingyi@cs.utsa.edu richie@cc.gatech.edu jewillco@osl.iu.edu Project Web Page: www.rosecompiler.org UCRL Number for ROSE User Manual: UCRL-SM-210137-DRAFT UCRL Number for ROSE Tutorial: UCRL-SM-210032-DRAFT Number for ROSE Source Code: UCRL-CODE-155962 ROSE User Manual (pdf) ROSE Tutorial (pdf) ROSE HTML Reference (html only) May 2, 2011 ii May 2, 2011 Contents 1 Introduction 1 1.1 What is ROSE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 1.2 Why you should be interested in ROSE . . . . . . . . . . . . . . . . . . . . . . . 2 1.3 Problems that ROSE can address . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 1.4 Examples in this ROSE Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 1.5 ROSE Documentation and Where To Find It . . . . . . . . . . . . . . . . . . . . 10 1.6 Using the Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.7 Required Makefile for Tutorial Examples . . . . . . . . . . . . . . . . . . . . . . . 11 I Working with the ROSE AST 13 2 Identity Translator 15 3 Simple AST Graph Generator 19 4 AST Whole Graph 23 5 Advanced AST Graph Generation 27 6 AST PDF Generator 29 7 Introduction to AST Traversals 33 7.1 Input For Example Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 7.2 Traversals of the AST Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 7.2.1 Classic Object-Oriented Visitor Pattern for the AST . . . . . . . . . . . . 35 7.2.2 Simple Traversal (no attributes) . . . . . . . . . . . . . . . . . . . . . . . 35 7.2.3 Simple Pre- and Postorder Traversal . . . . . . . . . . . . . . . . . . . . . 35 7.2.4 Inherited Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 7.2.5 Synthesized Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 7.2.6 Accumulator Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 7.2.7 Inherited and Synthesized Attributes . . . . . . . . . . . . . . . . . . . . . 46 7.2.8 Persistent Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 7.2.9 Nested Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 7.2.10 Combining all Attributes and Using Primitive Types . . . . . . . . . . . . 54 iii iv CONTENTS 7.2.11 Combined Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 7.2.12 Short-Circuiting Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . 61 7.3 Memory Pool Traversals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 7.3.1 ROSE Memory Pool Visit Traversal . . . . . . . . . . . . . . . . . . . . . 64 7.3.2 Classic Object-Oriented Visitor Pattern for Memory Pool . . . . . . . . . 66 7.3.3 ROSE IR Type Traversal (uses Memory Pools) . . . . . . . . . . . . . . . 68 8 Scopes of Declarations 71 8.1 Input For Examples Showing Scope Information . . . . . . . . . . . . . . . . . . 71 8.2 Generating the code representing any IR node . . . . . . . . . . . . . . . . . . . . 72 9 AST Query 75 9.1 Simple Queries on the AST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 9.2 Nested Query . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 10 AST File I/O 81 10.1 Source Code for File I/O. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 10.2 Input to Demonstrate File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 10.3 Output from File I/O . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 10.4 Final Code After Passing Through File I/O . . . . . . . . . . . . . . . . . . . . . 81 11 Debugging Techniques 85 11.1 Input For Examples Showing Debugging Techniques . . . . . . . . . . . . . . . . 85 11.2 Generating the code from any IR node . . . . . . . . . . . . . . . . . . . . . . . . 86 11.3 Displaying the source code position of any IR node . . . . . . . . . . . . . . . . . 86 II Complex Types 89 12 Type and Declaration Modifiers 91 12.1 Input For Example Showing use of Volatile type modifier . . . . . . . . . . . . . 91 12.2 Generating the code representing the seeded bug . . . . . . . . . . . . . . . . . . 92 13 Function Parameter Types 95 14 Resolving Overloaded Functions 99 15 Template Parameter Extraction 103 16 Template Support 105 16.1 Example Template Code #1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 16.2 Example T Code #2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105 III Program Analyses 107 17 Recognizing Loops 109 CONTENTS v 18 Virtual CFG 113 18.1 CFGNode Index values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 18.2 Important functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 18.2.1 Node methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 18.2.2 Edge methods. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 18.3 Drawing a graph of the CFG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115 18.4 Robustness to AST changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 18.5 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 18.5.1 Fortran support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 18.5.2 Exception handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 18.5.3 Interprocedural control flow analysis . . . . . . . . . . . . . . . . . . . . . 122 18.6 Node filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 18.6.1 “Interesting” node filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 18.6.2 Arbitrary filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 18.7 Static CFG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 18.7.1 Class methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 18.7.2 Drawing a graph of the CFG . . . . . . . . . . . . . . . . . . . . . . . . . 124 18.8 Static, Interprocedural CFGs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124 19 Generating Control Flow Graphs 127 20 Dataflow Analysis 131 20.1 Def-Use Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 20.1.1 Def-use Example implementation . . . . . . . . . . . . . . . . . . . . . . . 131 20.1.2 Accessing the Def-Use Results . . . . . . . . . . . . . . . . . . . . . . . . 133 20.2 Liveness Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 20.2.1 Access live variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 21 Generating the Call Graph (CG) 141 22 Generating the Class Hierarchy Graph 145 23 Database Support 147 23.1 ROSE DB Support for Persistent Analysis . . . . . . . . . . . . . . . . . . . . . . 147 23.2 Call Graph for Multi-file Application . . . . . . . . . . . . . . . . . . . . . . . . . 147 23.3 Class Hierarchy Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147 24 Building Custom Graphs 153 IV Program Transformations and Optimizations 155 25 Generating Unique Names for Declarations 157 25.1 Example Code Showing Generation of Unique Names . . . . . . . . . . . . . . . . 158 25.2 Input For Examples Showing Unique Name Generation for Variables . . . . . . . 158 25.3 Example Output Showing Unique Variable Names . . . . . . . . . . . . . . . . . 159 25.4 Input For Examples Showing Unique Name Generation for Functions . . . . . . . 159 vi CONTENTS 25.5 Example Output Showing Unique Function Names . . . . . . . . . . . . . . . . . 159 26 Command-line Processing Within Translators 165 26.1 Commandline Selection of Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 27 Tailoring The Code Generation Format 169 27.1 Source Code for Example that Tailors the Code Generation . . . . . . . . . . . . 169 27.2 Input to Demonstrate Tailoring the Code Generation . . . . . . . . . . . . . . . . 169 27.3 Final Code After Tailoring the Code Generation . . . . . . . . . . . . . . . . . . 169 28 AST Construction 173 28.1 Variable Declarations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173 28.2 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177 28.3 Assignment Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179 28.4 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181 28.5 F Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186 28.6 Creating a ’struct’ for Global Variables . . . . . . . . . . . . . . . . . . . . . . . . 186 29 HandlingComments, PreprocessorDirectives, AndAddingArbitraryTextto Generated Code 199 29.1 How to Access Comments and Preprocessor Directives . . . . . . . . . . . . . . . 199 29.1.1 Source Code Showing How to Access Comments and Preprocessor Directives200 29.1.2 Input to example showing how to access comments and CPP directives . 200 29.1.3 Comments and CPP Directives collected from source file (skipping headers)200 29.1.4 Comments and CPP Directives collected from source file and all header files200 29.2 Collecting #define C Preprocessor Directives . . . . . . . . . . . . . . . . . . . . 200 29.2.1 Source Code Showing How to Collect #define Directives . . . . . . . . . . 200 29.2.2 Input to example showing how to access comments and CPP directives . 202 29.2.3 Comments and CPP Directives collected from source file and all header files202 29.3 Automated Generation of Comments . . . . . . . . . . .
  • Univers Univers
  • Ebooks Ebooks
  • Livres audio Livres audio
  • Presse Presse
  • Podcasts Podcasts
  • BD BD
  • Documents Documents