Aspect-Oriented Programming with the e Verifi cation Language A Pragmatic Guide for Testbench Developers David Robinson AMSTERDAM (cid:129) BOSTON (cid:129) HEIDELBERG (cid:129) LONDON NEW YORK (cid:129) OXFORD (cid:129) PARIS (cid:129) SAN DIEGO SAN FRANCISCO (cid:129) SINGAPORE (cid:129) SYDNEY (cid:129) TOKYO Morgan Kaufmann is an imprint of Elsevier PPrreelliimmss--PP337744221100..iinndddd ii 77//1122//0077 66::0066::3399 PPMM Publishing Director: Joanne Tracy Senior Acquisitions Editor: Chuck Glaser Publishing Services Manager: George Morrison Project Manager: Mónica González de Mendoza Assistant Editor: Michele Cronin Production Assistant: Lianne Hong Composition: Charon Tec Ltd (A Macmillan Company) Interior printer: Maple-Vail Book Manufacturing Group Cover printer: Phoenix Color Corporation Morgan Kaufmann Publishers is an imprint of Elsevier. 30 Corporate Drive, Suite 400, Burlington, MA 01803, USA This book is printed on acid-free paper. © 2007 by Elsevier, Inc. All rights reserved. Designations used by companies to distinguish their products are often claimed as trademarks or registered trademarks. In all instances in which Morgan Kaufmann Publishers is aware of a claim, the product names appear in initial capital or all capital letters. Readers, however, should contact the appropriate companies for more complete information regarding trademarks and registration. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means — electronic, mechanical, photocopying, scanning, or otherwise — without prior written permission of the publisher. Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford, UK: phone: ((cid:2)44) 1865 843830, fax: ((cid:2)44) 1865 853333, E-mail: [email protected]. You may also complete your request online via the Elsevier homepage (http://elsevier.com), by selecting “Support & Contact” then “Copyright and Permission” and then “Obtaining Permissions.” Library of Congress Cataloging-in-Publication Data Robinson, David. Aspect-oriented programming with the e verifi cation language : a pragmatic guide for testbench developers / David Robinson. p. cm. Includes bibliographical references and index. ISBN-13: 978-0-12-374210-0 (pbk. : alk. paper) 1. Object-oriented programming (Computer science) I. Title. QA76.64.R629 2007 005.1(cid:3)17 — dc22 2007019636 ISBN: 978-0-12-374210-0 For information on all Morgan Kaufmann publications, visit our Web site at www.mkp.com or www.books.elsevier.com 07 08 09 10 11 12 10 9 8 7 6 5 4 3 2 1 Printed in the United States of America PPrreelliimmss--PP337744221100..iinndddd iiii 77//1122//0077 66::0066::4411 PPMM Acknowledgments I’d like to thank Ken Gray for making the innocuous com- ment that started the whole thing going in the fi rst place. I’m fairly sure he meant it, but I sometimes can’t help but feel that I’ve fallen for a large practical joke. Keeping with the theme of innocuous comments for a moment, I’d like to thank Tommy Kelly for his very detailed review comments. During a phone conversation about some of these he just happened to mention that he had no idea what I was talking about by the end of the Introduction. That throw away line started one of the biggest rewrites the book ever had. I’d like to thank Jason Sprott for stress testing my OOP arguments. As something of an OOP, Vera, SystemVerilog, testbench, and verifi cation guru, having him admit that there might be a slight possibility that maybe AOP had some kind of an advantage over OOP on its own was a defi ning moment. I also have to thank Jason and Tommy for creating Verilab and inviting me in to play. That leads me on nicely to thanking all the people (past and present) in Verilab for making it such a great place to work. The technical knowledge fl oating around in there is noth- ing short of amazing, and everyone has contributed to the making of this book. In particular, I’d like to thank Robert Fairlie, J.L. Gray, and Gordon McGregor for their detailed reviews. Outside of Verilab, Suzanne Peggie, Claudia Blank, Mike Stellfox, Ernst Zwingenberger, Bernhard Klein, Robert Richter, PPrreelliimmss--PP337744221100..iinndddd iiiiii 77//1122//0077 66::0066::4411 PPMM iv Acknowledgments Christian Beckmann, John MacBeth, Gery Osowiecki, Andrew Piziali, and Thorsten Lutscher all deserve a special mention for helping make the book what it is — whether they realized it or not. Finally, I’d like to thank Chuck Glaser, Monica Mendoza, Michele Cronin, and Dennis Schaefer at Morgan Kaufmann, and all the good folks at Charon Tec Ltd for actually making the book. PPrreelliimmss--PP337744221100..iinndddd iivv 77//1122//0077 66::0066::4411 PPMM Table of Contents Foreword ix Preface xi About Verilab xix 1. Introduction to Aspect Oriented Programming (AOP) 1 1.1. What are aspects? — Part I 2 1.2. Why do I need aspects? What’s wrong with crosscutting concerns? 9 1.3. Surely OOP doesn’t have any problems? 11 1.4. Why does AOP help? 18 1.5. Theory vs real life — What else is AOP good for? 22 1.6. What are aspects? — Part II 27 2. AOP in e 31 2.1. How do I extend a class? 36 2.2. How do I extend a class for multiple values of a determinant? 41 2.3. How do I extend a type? 42 2.4. How do I introduce a new noncoverage member to a class? 43 2.5. How do I introduce a coverage group to a class? 44 2.6. How do I extend a coverage group? 46 2.7. H ow do I change the behavior of a method? 50 2.8. How do I limit the scope of my extensions? 53 2.9. Using return in method advice 59 2.10. Controlling the order of method extension calls 65 PPrreelliimmss--PP337744221100..iinndddd vv 77//1122//0077 66::0066::4422 PPMM vi Table of Contents 3. Using AOP to Organize Your Code 67 3.1. A word about style 69 3.2. What aspects do I want to use? 70 3.3. Mapping aspects to fi les 75 4. Creating Flexible Code 93 5. Creating Pluggable Code 113 5.1. The extendable case statement 120 5.2. The factory pattern 132 6. Improving Your Productivity 145 6.1. Shifting the power 146 6.2. Dealing with broken code 147 6.3. Handling workarounds 149 6.4. Reducing and deferring class complexity 150 6.5. Adding problem-specifi c functionality 153 6.6. Reducing the OOP-induced overhead 155 7. AOP in Action 163 7.1. Creating a class with a selectable algorithm 164 7.2. Creating a confi guration interface for an eVC 173 7.3. Using aspects to create a layered verifi cation environment 180 7.4. Creating reusable layered sequences 188 7.5. Testing your verifi cation environment 196 7.6. Debugging using AOP 204 7.7. Encapsulating tests 210 8. Analysing e Code 215 8.1. The e toolkit 217 8.2. Finding class declarations and extensions 221 8.3. Finding the class inheritance hierarchy 224 8.4. Finding the determinants used by a class 224 PPrreelliimmss--PP337744221100..iinndddd vvii 77//1122//0077 66::0066::4422 PPMM Table of Contents vii 8.5. Finding method declarations and extensions 225 8.6. Finding fi eld declarations 226 8.7. Finding event declarations 227 8.8. Finding enumerated type declarations and extensions 227 8.9. How do I fi nd where a value is added to a type? 228 8.10. Finding cover group declarations and extensions 229 8.11. Finding the source of a message in the log fi le 230 8.12. Finding aspects 231 Bibliography 239 Epilogue 241 Index 243 PPrreelliimmss--PP337744221100..iinndddd vviiii 77//1122//0077 66::0066::4422 PPMM This page intentionally left blank Foreword David Robinson has made a valuable contribution to the verifi cation community with this book about Aspect- Oriented Programming (AOP) using e. Coverage-driven veri- fi cation has entered the mainstream as a critical and central component of an effective verifi cation methodology, and this has driven engineers to seek out the best practices for devel- oping automated verifi cation environments. There are many compelling reasons why people choose Specman Elite and the e language to tackle their verifi cation problems — the declarative nature of the language which makes it easy to express stimulus constraints, temporal assertions, and func- tional coverage; the large library of predefi ned routines which make it easy to create sophisticated checkers and other test- bench components; the fl exibility provided by the extensibil- ity of the language; or simply the fact that they fi nd it to be an incredibly effi cient way to get their job done. I have spent the last 8 years working with design and verifi cation engineers to help them create constrained-random, coverage-driven veri- fi cation environments using the e verifi cation language. They don’t usually start out saying, “I could really use an AOP lan- guage to make my verifi cation work a lot easier…” In fact, most Specman experts and beginners who leverage the power of AOP in their everyday work to create and use e verifi ca- tion environments do so without much thought of exactly what AOP is all about. I, and other verifi cation experts, have tried for many years to convey in simple terms the power of e as an AOP language to signifi cantly simplify and accelerate the development of reusable, automated verifi cation envi- ronments, but we have not succeeded in a way that matches PPrreelliimmss--PP337744221100..iinndddd iixx 77//1122//0077 66::0066::4422 PPMM
Description: