logo资料库

compiler design virtual machines.pdf

第1页 / 共201页
第2页 / 共201页
第3页 / 共201页
第4页 / 共201页
第5页 / 共201页
第6页 / 共201页
第7页 / 共201页
第8页 / 共201页
资料共201页,剩余部分请下载后查看
Cover
Compiler Design
Preface
Acknowledgments
Contents
1 Introduction
1.1 High-Level Programming Languages
1.2 Implementation of Programming Languages
1.2.1 Interpreters
1.2.2 Compilers
1.2.3 Real and Virtual Machines
1.2.4 Combined Compilation and Interpretation
1.3 General References
2 Imperative Programming Languages
2.1 Language Concepts and Their Compilation
2.2 The Architecture of the C-Machine
2.3 Simple Expressions and Assignments
2.4 Statements and Statement Sequences
2.5 Conditional and Iterative Statements
2.6 Memory Allocation for Variables of Basic Types
2.7 Memory Allocation for Arrays and Structures
2.8 Pointers and Dynamic Memory Allocation
2.9 Functions
2.9.1 Memory Organization of the C-Machine
2.9.2 Dealing with Local Variables
2.9.3 Function Call and Return
2.10 Translation of Programs
2.11 Exercises
2.12 List of CMa Registers
2.13 List of Code Functions of the CMa
2.14 List of CMa Instructions
2.15 References
3 Functional Programming Languages
3.1 Basic Concepts and Introductory Examples
3.2 A Simple Functional Programming Language
3.3 The Architecture of the MaMa
3.4 Translation of Simple Expressions
3.5 Access to Variables
3.6 let Expressions
3.7 Function Definitions
3.8 Function Application
3.9 Under- and Oversupply with Arguments
3.10 Recursive Variable Definitions
3.11 Closures and Their Evaluation
3.12 Optimization I: Global Variables
3.13 Optimization II: Closures
3.14 Translating Program Expressions
3.15 Structured Data
3.15.1 Tuples
3.15.2 Lists
3.15.3 Closures for Tuples and Lists
3.16 Optimization III: Last Calls
3.17 Exercises
3.18 List of MaMa Registers
3.19 List of Code Functions of the MaMa
3.20 List of MaMa Instructions
3.21 References
4 Logic Programming Languages
4.1 The Language ProL
4.2 The Architecture of the WiM
4.3 Allocation of Terms in the Heap
4.4 The Translation of Literals
4.5 Unification
4.6 Clauses
4.7 The Translation of Predicates
4.7.1 Backtracking
4.7.2 Putting It All Together
4.8 The Finalization of Clauses
4.9 Queries and Programs
4.10 Optimization I: Last Goals
4.11 Optimization II: Trimming of Stack Frames
4.12 Optimization III: Clause Indexing
4.13 Extension: The Cut Operator
4.14 Digression: Garbage Collection
4.15 Exercises
4.16 List of WiM Registers
4.17 List of Code Functions of the WiM
4.18 List of WiM Instructions
4.19 References
5 Object-Oriented Programming Languages
5.1 Concepts of Object-Oriented Languages
5.1.1 Objects
5.1.2 Object Classes
5.1.3 Inheritance
5.1.4 Genericity
5.1.5 Information Encapsulation
5.1.6 Summary
5.2 An Object-Oriented Extension of C
5.3 The Memory Organization for Objects
5.4 Method Calls
5.5 The Definition of Methods
5.6 The Use of Constructors
5.7 The Definition of Constructors
5.8 Perspective: Multiple Inheritance
5.9 Exercises
5.10 List of Additional Registers
5.11 CMa Instructions for Objects
5.12 References
References
Index
Compiler Design
Reinhard Wilhelm · Helmut Seidl Compiler Design Virtual Machines 123
Prof. Dr. Reinhard Wilhelm Universit¨at des Saarlandes FB Informatik Postfach 15 11 50 66041 Saarbr¨ucken Saarland Germany wilhelm@cs.uni-sb.de Prof. Dr. Helmut Seidl TU M¨unchen Fak. Informatik Boltzmannstr. 3 85748 Garching Germany seidl@in.tum.de ISBN 978-3-642-14908-5 DOI 10.1007/978-3-642-14909-2 Springer Heidelberg Dordrecht London New York e-ISBN 978-3-642-14909-2 ACM Codes: D.1, D.3, D.2 c Springer-Verlag Berlin Heidelberg 2010 This work is subject to copyright. All rights are reserved, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilm or in any other way, and storage in data banks. Duplication of this publication or parts thereof is permitted only under the provisions of the German Copyright Law of September 9, 1965, in its current version, and permission for use must always be obtained from Springer. Violations are liable to prosecution under the German Copyright Law. The use of general descriptive names, registered names, trademarks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use. Cover design: KuenkelLopka GmbH Printed on acid-free paper Springer is part of Springer Science+Business Media (www.springer.com)
For Margret, Hannah, Eva, Barbara R.W. For Kerstin and Anna H.S.
Preface Compilers for high-level programming languages are software systems which are both large and complex. Nonetheless, they have particular characteristics that differ- entiate them from the majority of other software systems. Their functionality is (almost) completely well-defined. Ideally, there exist com- pletely formal, or at least rather precise, specifications of the source and target lan- guages. Often additional specifications of the interfaces to the operating system, to programming environments, and to other compilers and libraries are available. The compilation task can be naturally divided into subtasks. This subdivision results in a modular structure, which, by the way, also leads to a canonical structure of the common compiler design books. Already in the Fifties it was recognized that the implementation of application systems directly in machine language is both difficult and error-prone, leading to programs that become obsolete as quickly as the computers they were developed for. With the development of higher level machine independent programming lan- guages came the need to offer compilers that are able to translate programs of such programming languages into machine language. Given this basic challenge, the different subtasks of compilation have been the subject of intensive research since the Fifties. For the subtask of syntactic analysis of programs, concepts from formal language and automata theory, such as regular languages, finite automata, context-free grammars, and pushdown automata were borrowed and were further developed in view of the particular use. The theoretical foundation of the problem was so well-developed that the realization of the compo- nents required for syntax analysis could be (almost) completely automated: instead of being implemented by hand these components are mainly generated from speci- fications, in this case context-free grammars. Such automatic generation is also the aim for other components of compilers, although is has not always been achieved yet. This book is not intended to be a cookbook for compilers. Thus, one will not find recipes like: “To build a compiler of source language X into machine language Y, take ... “. Our presentation instead reflects the special characteristics of compiler design, specially the existence of precise specifications of the subtasks. We invest
分享到:
收藏