sequece library for e

Upload: abdul-thoufiq

Post on 03-Apr-2018

214 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/28/2019 Sequece library for E

    1/304

    e Libraries

    Preliminary

  • 7/28/2019 Sequece library for E

    2/304

    Legal Notice

    Copyright 1998-2002 Verisity Design, Inc. All rights reserved. The contents of this

    document constitute valuable proprietary and confidential property of Verisity Design, Inc.

    Trademarks

    Verisity is a trademark of Verisity Ltd or its subsidiaries (Verisity), registered in the

    United States and other jurisdictions. The Verisity logo, eVC, Invisible Specman, Lintrpt,

    Pure IP, Specman, Specman Elite, Specview, SureCov, SureLint, SureSight, and

    Verification Advisor are trademarks of Verisity Design, Inc. All other trademarks are the

    exclusive property of their respective owners.

    Confidentiality Notice

    No part of this information product may be reproduced, transmitted, or translated in any

    form or by any means, electronic, mechanical, manual, optical, or otherwise without prior

    written permission from Verisity Design, Inc.

    Information in this product is subject to change without notice and does not represent a

    commitment on the part of Verisity. The information contained herein is the proprietary

    and confidential information of Verisity or its licensors, and is supplied subject to, and may

    be used only by Verisitys customers in accordance with, a written agreement between

    Verisity and its customers. Except as may be explicitly set forth in such agreement,

    Verisity does not make, and expressly disclaims, any representations or warranties as to the

    completeness, accuracy, or usefulness of the information contained in this document.

    Verisity does not warrant that use of such information will not infringe any third party

    rights, nor does Verisity assume any liability for damages or costs of any kind that may

    result from use of such information.

    Restricted Rights Legend

    Use, duplication, or disclosure by the Government is subject to restrictions as set forth in

    subparagraphs (c)(1)(ii) of the Rights in Technical Data and Computer Software clause at

    DFARS 252.227-7013.

    Destination Control Statement

    All technical data contained in this product is subject to the export control laws of the

    United States of America. Disclosure to nationals of other countries contrary to United

    States law is prohibited. It is the readers responsibility to determine the applicable

    regulations and to comply with them.

  • 7/28/2019 Sequece library for E

    3/304

    e Libraries Preliminary i

    Table of Contents

    1 About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1

    1.1 Conventions in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

    1.2 Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1-3

    2 Predefined Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1

    2.1 Predefined Methods of sys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-2

    2.1.1 sys.init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-2

    2.1.2 sys.run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-3

    2.2 Predefined Methods of Any Struct . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-4

    2.2.1 copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-5

    2.2.2 do_print() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-6

    2.2.3 init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-7

    2.2.4 print_line() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-8

    2.2.5 quit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-9

    2.2.6 run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-10

    2.3 Predefined Methods for Any Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-11

    2.3.1 hdl_path() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-11

    2.3.2 full_hdl_path() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-14

    2.3.3 e_path() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-15

    2.3.4 get_parent_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-16

    2.4 Unit-Related Predefined Methods for Any Struct . . . . . . . . . . . . . . . . . . 2-172.4.1 get_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-18

    2.4.2 get_enclosing_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-19

    2.4.3 try_enclosing_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2-21

    2.4.4 set_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-23

  • 7/28/2019 Sequece library for E

    4/304

  • 7/28/2019 Sequece library for E

    5/304

    Table of Contents

    e Libraries Preliminary iii

    3.4.9 list.is_a_permutation() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-39

    3.4.10 list.is_empty() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-40

    3.4.11 list.last() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-42

    3.4.12 list.last_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-44

    3.4.13 list.max() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45

    3.4.14 list.max_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47

    3.4.15 list.max_value() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-48

    3.4.16 list.min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-50

    3.4.17 list.min_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-52

    3.4.18 list.min_value() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-53

    3.4.19 list.reverse() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-55

    3.4.20 list.size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-56

    3.4.21 list.sort() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-57

    3.4.22 list.sort_by_field() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-59

    3.4.23 list.split() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-61

    3.4.24 list.top() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-63

    3.4.25 list.top0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-64

    3.4.26 list.unique() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-65

    3.5 Sublist Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-67

    3.5.1 list.all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-67

    3.5.2 list.all_indices() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-70

    3.6 Math and Logic Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-72

    3.6.1 list.and_all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-72

    3.6.2 list.average() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-73

    3.6.3 list.or_all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-75

    3.6.4 list.product() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-76

    3.6.5 list.sum() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-78

    3.7 List CRC Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-79

    3.7.1 list.crc_8() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-80

    3.7.2 list.crc_32() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-81

    3.7.3 list.crc_32_flip() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-84

    3.8 Keyed List Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-853.8.1 list.key() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-86

    3.8.2 list.key_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-87

    3.8.3 list.key_exists() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-89

    3.9 Restrictions on Keyed Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3-90

  • 7/28/2019 Sequece library for E

    6/304

    Table of Contents

    iv Preliminary e Libraries

    4 Predefined Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1

    4.1 Predefined Routines Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-1

    4.2 Deep Copy and Compare Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-2

    4.2.1 deep_copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-24.2.2 deep_compare() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-5

    4.2.3 deep_compare_physical() . . . . . . . . . . . . . . . . . . . . . . . . . . .4-10

    4.3 Arithmetic Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-12

    4.3.1 min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-12

    4.3.2 max() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-14

    4.3.3 abs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-15

    4.3.4 odd() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-16

    4.3.5 even() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17

    4.3.6 ilog2() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-184.3.7 ilog10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-19

    4.3.8 ipow() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-20

    4.3.9 isqrt() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21

    4.3.10 div_round_up() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-22

    4.4 Bitwise Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23

    4.4.1 bitwise_op() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-23

    4.5 Type-Related Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-25

    4.5.1 as_a() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25

    4.5.2 all_values() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-354.6 Unit-Related Predefined Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-36

    4.6.1 get_all_units() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-36

    4.7 Constructs for Packing and Unpacking . . . . . . . . . . . . . . . . . . . . . . . . . .4-37

    4.7.1 pack() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-38

    4.7.2 unpack() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-42

    4.7.3 swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-47

    4.7.4 do_pack() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49

    4.7.5 do_unpack() . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-53

    4.8 String Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-57

    4.8.1 append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59

    4.8.2 appendf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-60

    4.8.3 bin() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-61

    4.8.4 dec() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-62

    4.8.5 hex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-64

  • 7/28/2019 Sequece library for E

    7/304

    Table of Contents

    e Libraries Preliminary v

    4.8.6 quote() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-65

    4.8.7 str_chop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-66

    4.8.8 str_empty() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-67

    4.8.9 str_exactly() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-68

    4.8.10 str_insensitive() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-69

    4.8.11 str_join() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-70

    4.8.12 str_len() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-71

    4.8.13 str_lower() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-72

    4.8.14 str_match() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-73

    4.8.15 str_pad() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-75

    4.8.16 str_replace() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-76

    4.8.17 str_split() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-78

    4.8.18 str_split_all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-79

    4.8.19 str_sub() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-80

    4.8.20 str_upper() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-81

    4.8.21 to_string() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-82

    4.9 Output Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-84

    4.9.1 out() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-84

    4.9.2 outf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-85

    4.9.3 Format String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-88

    4.10 OS Interface Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-88

    4.10.1 spawn() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-89

    4.10.2 spawn_check() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-90

    4.10.3 system() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-91

    4.10.4 output_from() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-92

    4.10.5 output_from_check() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-93

    4.10.6 get_symbol() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-94

    4.10.7 date_time() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-95

    4.11 File Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-96

    4.11.1 File Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-97

    4.11.2 Low-Level File Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-97

    4.11.3 files.add_file_type() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-98

    4.11.4 files.close() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-99

    4.11.5 files.flush() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-101

    4.11.6 files.open() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-102

    4.11.7 files.read() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-104

  • 7/28/2019 Sequece library for E

    8/304

    Table of Contents

    vi Preliminary e Libraries

    4.11.8 files.read_lob() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-106

    4.11.9 files.write() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-107

    4.11.10 files.write_lob() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-109

    4.11.11 General File Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-110

    4.11.12 files.file_age() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-111

    4.11.13 files.file_append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-113

    4.11.14 files.file_copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-114

    4.11.15 files.file_delete() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-115

    4.11.16 files.file_exists() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-116

    4.11.17 files.file_extension() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-118

    4.11.18 files.file_is_dir() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-119

    4.11.19 files.file_is_link() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-121

    4.11.20 files.file_is_readable() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-122

    4.11.21 files.file_is_regular() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-123

    4.11.22 files.file_is_temp() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-125

    4.11.23 files.file_is_text() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-126

    4.11.24 files.file_rename() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-128

    4.11.25 files.file_size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-129

    4.11.26 files.new_temp_file() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-130

    4.11.27 files.write_string_list() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-132

    4.11.28 Reading and Writing Structs . . . . . . . . . . . . . . . . . . . . . . . . . .4-133

    4.11.29 files.read_ascii_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-134

    4.11.30 files.read_binary_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-135

    4.11.31 files.write_ascii_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-137

    4.11.32 files.write_binary_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-139

    4.12 Calling Predefined Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-141

    4.12.1 routine() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-141

    5 Modeling State Machines . . . . . . . . . . . . . . . . . . . . . . . . . 5-1

    5.1 State Machine Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-1

    5.2 State Machine Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-2

    5.2.1 state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-2

    5.2.2 state => state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5

    5.2.3 * => state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6

    5.2.4 state action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-8

    5.3 Sample State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9

  • 7/28/2019 Sequece library for E

    9/304

    Table of Contents

    e Libraries Preliminary vii

    5.4 Using State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-10

    5.4.1 Initializing a State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10

    5.4.2 Terminating a State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . .5-11

    5.4.3 Rules for State Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-125.4.4 Nested State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5-13

    5.4.5 Parallel State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14

    Index

  • 7/28/2019 Sequece library for E

    10/304

    Table of Contents

    viii Preliminary e Libraries

  • 7/28/2019 Sequece library for E

    11/304

    e Libraries Preliminary 1-1

    1 About This BookThe e language is an object-oriented programming language. Although e can be used to

    create any general-purpose software program, it has been designed to facilitate the

    verification of electronic designs. The verification-specific constructs that distinguish efrom other object-oriented languages such as C++ include:

    Constructs to define legal values for data items (constraints)

    Constructs to describe sequences over time (temporal constructs)

    Constructs to support concurrency (multi-threaded execution)

    Constructs to support connectivity (bit-level access)

    The e language also is designed to reduce the effort required to write tests and to make the

    high-level intent of the test readily apparent. In contrast to other object-oriented

    programming languages, es unique extensibility lets you modify multiple data objects in a

    single, separate test file that is layered on top of the base verification environment. This

    extensibility feature allows you to address systemic, test-specific concerns that are not

    localized to a single data objects boundaries in a way that does not sacrifice modularity or

    readability.

    e Libraries provides detailed information on es built-in (predefined) methods androutines.

    For information on the constructs of the e programming language, refer to the e Language

    Reference Manual.

  • 7/28/2019 Sequece library for E

    12/304

    About This Book Conventions in This Book

    1-2 Preliminary e Libraries

    1.1 Conventions in This Book

    This manual uses visual cues to help you locate and interpret information easily. These

    cues are explained in Table 1-1.

    Table 1-1 Document Conventions

    Visual Cue Represents

    courier The Courier font indicates e or HDL code. For example, the

    following line indicates e code:

    keep opcode in [ADD, ADDI];

    bold The bold font indicates keywords in descriptive text. For example,

    the following sentence contains the keyword keep:

    Use the keep construct to guide test generation and

    configuration.

    The bold font is used in syntax descriptions to indicate text that must

    be typed exactly as it appears. For example, in the following

    sentence thekeywords keepandreset_soft, as well as theperiod

    and the parentheses must be typed as they appear:

    keep item.reset_soft()

    italic The italic font represents user-defined variables that you mustprovide. For example, the following line instructs you to type

    keep as it appears, and then specifiy a Boolean expression:

    keep constraint-bool-exp

    [ ] square

    brackets

    Square brackets indicate optional parameters. For example, in the

    following construct the keywords list of are optional:

    var name: [list of] type

    [ ] bold brackets Bold square brackets are required. For example, in the following

    construct you must type the bold square brackets as they appear:

    extend enum-type-name: [name,]

  • 7/28/2019 Sequece library for E

    13/304

    Syntax Notation About This Book

    e Libraries Preliminary 1-3

    1.2 Syntax Notation

    Each construct section starts with the syntax for the construct. The syntax shows the

    construct, any arguments it accepts with their types, and the constructs return type if it has

    one.

    When using the construct, terms in bold in the syntax are to be entered exactly as shown.

    Terms in italics are to be replaced by terms of your own. The argument types and the

    construct return type are for information only and are not entered.

    For example, the syntax notation for the predefined pseudo-method named list.first() onpage 3-33 is

    list.first(exp: bool): list-type

    This is what the notation means:

    The bold .first and the parentheses must be entered exactly.

    The parts in italics, list and exp, must be replaced by a list name and an expression.

    : bool indicates that the expression must be a Boolean expression.

    : list-type means that the pseudo-method returns an item of the list element type.

    An example of a call to the list.first() pseudo-method is shown below, where numbers is

    a list of integer items and my_number is an integer. The pseudo-method returns the first

    integer in the list greater than 5:

    my_number = numbers.first(it > 5)

    construct, An item, followed by a separator (usually a comma or a semicolon)

    and an ellipsis is an abbreviation for a list of elements of thespecified type. For example, the following line means you can type

    a list of zero or more names separated by commas.

    extend enum-type-name: [name,]

    | The | character indicates alternative syntax or parameters. For

    example, the following line indicates that either the bits or bytes

    keyword should be used:

    type scalar-type (bits | bytes: num)

    Table 1-1 Document Conventions (continued)

    Visual Cue Represents

  • 7/28/2019 Sequece library for E

    14/304

    About This Book Syntax Notation

    1-4 Preliminary e Libraries

  • 7/28/2019 Sequece library for E

    15/304

    e Libraries Preliminary 2-1

    2 Predefined MethodsPart of the functionality ofe programs is implemented as set of predefined methods

    defined directly under the sys struct.

    Furthermore, every struct that is already available to you or is defined by you inherits a set

    of predefined methods. Some of these methods can be extended to add functionality, and

    some of them are empty, allowing you to define their function.

    Finally, there are pseudo-methods. Calls to pseudo-methods look like method calls.

    However, they are associated not with struct expressions, but with other kinds of

    expressions.

    The following sections describe the predefined methods:

    Predefined Methods of sys on page 2-2

    Predefined Methods of Any Struct on page 2-4

    Predefined Methods for Any Unit on page 2-11

    Unit-Related Predefined Methods for Any Struct on page 2-17

    Pseudo-Methods on page 2-23

    Semaphore Methods on page 2-31

    See Also

    Chapter 3, List Pseudo-Methods

  • 7/28/2019 Sequece library for E

    16/304

    Predefined Methods Predefined Methods of sys

    2-2 Preliminary e Libraries

    File Routines on page 4-96

    Chapter 4, Predefined Routines

    2.1 Predefined Methods of sysThis section contains descriptions of the extendable methods of sys:

    sys.init() on page 2-2

    sys.run() on page 2-3

    2.1.1 sys.init()

    Purpose

    Perform general preparations for a run

    Category

    Predefined method for sys

    Syntax

    [sys.]init()

    Syntax example:

    extend sys {

    init() is also {

    out("Performing initialization of sys...");

    };

    };

    Parameters

    None

    Description

    You can extend this method to perform general preparations for a run.

  • 7/28/2019 Sequece library for E

    17/304

  • 7/28/2019 Sequece library for E

    18/304

    Predefined Methods Predefined Methods of Any Struct

    2-4 Preliminary e Libraries

    };

    run() is also {

    start monitor();

    };

    };

    '>

    See Also

    run() on page 2-10

    start tcm() on page 6-21 in the e Language Reference Manual

    2.2 Predefined Methods of Any Struct

    The following methods are available for any struct that you define and instantiate. Many ofthese methods do not require parameters, nor do they return values; they simply carry out

    a procedure. The predefined methods for any struct are also available for any user-defined

    unit.

    copy() on page 2-5

    do_pack() on page 4-49

    do_unpack() on page 4-53

    do_print() on page 2-6

    init() on page 2-7

    print_line() on page 2-8

    quit() on page 2-9

    run() on page 2-10

    See Also

    Unit-Related Predefined Methods for Any Struct on page 2-17

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    19/304

    copy() PredefinedMethods

    e Libraries Preliminary 2-5

    2.2.1 copy()

    Purpose

    Make a shallow copy

    Category

    Predefined method of any struct or unit

    Syntax

    exp.copy(): exp-type

    Syntax example:

    var pmv: packet = sys.pmi.copy();

    Parameters

    Description

    Returns a shallow, non-recursive copy of the expression. This means that if the

    expression is a list or a struct that contains other lists or structs, the second-level itemsare not duplicated. Instead, they are copied by reference.

    The following list details how the copy is made, depending on the type of the

    expression:

    exp Any legal e expression.

    scalar The scalar value is simply assigned as in a normal assignment.

    string The whole string is copied.

  • 7/28/2019 Sequece library for E

    20/304

    Predefined Methods do_print()

    2-6 Preliminary e Libraries

    Notes

    Use the deep_copy() method ifyou wanta recursive copyof a structor list that containscompound fields or items.

    See Also

    deep_copy() on page 4-2

    2.2.2 do_print()

    Purpose

    Print struct info

    Category

    Predefined method of any struct or unit

    Syntax

    [exp.]do_print()

    Syntax example:

    do_print() is first {

    outf("Struct %s :", me.s);

    };

    scalar list If exp is a scalar list, a new list with the same size as the original list

    is allocated. The contents of the original list is duplicated.

    list of structs A new list with the same size as the original list is allocated. The

    contents of the list is copied by reference, meaning that each item in

    the new list points to the corresponding item in the original list.

    struct If exp is a struct instance, a new struct instance with the same type as

    the original struct is allocated. All scalar fields are duplicated. All

    compound fields (lists or structs) in the new struct instance point to the

    corresponding fields in the original struct.

  • 7/28/2019 Sequece library for E

    21/304

    init() PredefinedMethods

    e Libraries Preliminary 2-7

    Parameters

    Description

    Controls the printing of information about a particular struct. You can extend this

    method to customize the way information is displayed.

    This method is called by the print action whenever you print the struct.

    Example

    2.2.3 init()

    Purpose

    Initialize struct

    Category

    Predefined method of any struct or unit

    exp An expression that returns a unit or a struct.

  • 7/28/2019 Sequece library for E

    22/304

    Predefined Methods print_line()

    2-8 Preliminary e Libraries

    Syntax

    [exp.]init()

    Syntax example:

    init() is also {

    is_ok = TRUE;

    list_subs = {320; 330; 340; 350; 360};

    list_color = {black; red; green; blue; yellow; white};

    };

    Parameters

    DescriptionYou can extend the init() method of a struct to set values for fields that you want to

    have a different value than the default value.

    See Also

    Packing and Unpacking Lists on page 16-10 in the e Language Reference Manual

    e Data Types on page 3-2 in the e Language Reference Manual

    { ; } on page 2-63 in thee

    Language Reference Manual

    2.2.4 print_line()

    Purpose

    Print a struct or a unit in a single line

    Category

    Predefined method of any struct or unit

    Syntax

    [exp.]print_line(type: type-descriptor)

    exp An expression that returns a unit or a struct.

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    23/304

    quit() PredefinedMethods

    e Libraries Preliminary 2-9

    Syntax example:

    sys.pmi[0].print_line(sys.pmi[0].type());

    sys.pmi[0].print_line(NULL);

    Parameters

    Description

    You can call this method to print lists of structs of a common struct type in a tabulated

    table format. Each struct in the list is printed in a single line of the table.

    2.2.5 quit()

    Purpose

    Kill all threads of a struct or unit instance

    CategoryPredefined method of any struct or unit

    Syntax

    [exp.]quit()

    Syntax example:

    packet.quit();

    Parameters

    exp An expression that returns a struct or a unit.

    type To print a row representation of the struct or unit, the type argument is

    NULL.To print the header for the list, the struct argument is of the form

    type.type()

    exp An expression that returns a unit or a struct.

  • 7/28/2019 Sequece library for E

    24/304

    Predefined Methods run()

    2-10 Preliminary e Libraries

    Description

    Deactivates a struct instance, killing all threads associated with the struct and freeing

    up space in memory.

    2.2.6 run()

    Purpose

    Recommended place for starting TCMs

    Category

    Method of any struct or unit

    Syntax

    [exp.].run()

    Syntax example:

    run() is also {

    start monitor();

    };

    Parameters

    Description

    Can be extended to start user-defined TCMs. The method is initially empty.

    Example

  • 7/28/2019 Sequece library for E

    25/304

    Predefined Methods for Any Unit Predefined Methods

    e Libraries Preliminary 2-11

    };

    };

    run() is also {

    start monitor();

    };

    };

    '>

    See Also

    sys.run() on page 2-3

    start tcm() on page 6-21 in the e Language Reference Manual

    2.3 Predefined Methods for Any UnitThere is a predefined generic type any_unit, which is derived from any_struct. any_unit

    is the base type implicitly used in user-defined unit types, so all predefined methods for

    any_unit are available for any user-defined unit. The predefined methods for any_structare also available for any user-defined unit.

    The predefined methods for any unit include:

    hdl_path() on page 2-11

    full_hdl_path() on page 2-14

    e_path() on page 2-15

    get_parent_unit() on page 2-16

    See Also

    Unit-Related Predefined Methods for Any Struct on page 2-17

    Unit-Related Predefined Routines on page 4-36

    2.3.1 hdl_path()

    Purpose

    Return a relative HDL path for a unit instance

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    26/304

    Predefined Methods hdl_path()

    2-12 Preliminary e Libraries

    Category

    Predefined pseudo-method for any unit

    Syntax

    [unit-exp.]hdl_path(): string

    Syntax example:

    extend dut_error_struct {

    write() is first {

    var channel: XYZ_channel =

    source_struct().try_enclosing_unit(XYZ_channel);

    if (channel != NULL) {

    out("Error in XYZ channel: instance ",

    channel.hdl_path());

    };};

    };

    Parameters

    Description

    Returns the HDL path of a unit instance. The most important role of this method is to

    bind a unit instance to a particular component in the DUT hierarchy. Binding an e unit

    or unit instance to a DUT component allows you to reference signals within that

    component using relative HDL path names. Regardless of where the DUT component

    is instantiated in the final integration, the HDL path names are still valid. The binding

    of unit instances to HDL components must be done in keep constraints.

    This method always returns an HDL path exactly as it was specified in constraints.

    Note

    You cannot constrain the HDL path for sys.

    unit-exp An expression that returns a unit instance. If no expression is specified,

    the current unit instance is assumed.

  • 7/28/2019 Sequece library for E

    27/304

    hdl_path() PredefinedMethods

    e Libraries Preliminary 2-13

    Example 1

    This example shows how you can use relative paths in lower-level instances in the unit

    instance tree. To create the full HDL path of each unit instance, its HDL path is

    prefixed with the HDL path of its parent instance. In this example, because the HDL

    path ofsys is , the full HDL path of unit_core is top.router_i. The full HDL pathof extra_channel is top.router_i.chan3.

    extend sys {

    unit_core: XYZ_router is instance;

    keep unit_core.hdl_path() == "top.router_i";

    };

    extend XYZ_router {

    extra_channel: XYZ_channel is instance;

    keep extra_channel.hdl_path() == "chan3";

    };

    Example 2

    This example shows how hdl_path() returns the HDL path exactly as specified in the

    constraint. Thus the first print action prints `TOP.router_i. The second print action,

    in contrast, accesses top.router_i.clk.

    verilog import macros.v;

    extend sys {

    unit_core: XYZ_router is instance;

    keep unit_core.hdl_path() == "TOP.router_i";

    run() is also {

    print unit_core.hdl_path();

    print '(unit_core).clk';

    };

    };

    See Also

    HDL Paths and Units on page 5-3 in e Language Reference Manual

    full_hdl_path() on page 2-14

    e_path() on page 2-15

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    28/304

    Predefined Methods full_hdl_path()

    2-14 Preliminary e Libraries

    2.3.2 full_hdl_path()

    Purpose

    Return an absolute HDL path for a unit instance

    Category

    Predefined method for any unit

    Syntax

    [unit-exp.]full_hdl_path(): string

    Syntax example:

    out ("Mutex violation in ", get_unit().full_hdl_path());};

    Parameters

    Description

    Returns the absolute HDL path for the specified unit instance. This method is usedmainly in informational messages. Like the hdl_path() method, this method returns

    the path as originally specified in the keep constraint.

    Example

    This example uses full_hdl_path() to display information about where a mutex

    violation has occurred.

    extend XYZ_router {

    !current_chan: XYZ_channel;

    mutex_checker() @pclk is {while ('packet_valid') {

    var active_channel: int = UNDEF;

    for each XYZ_channel(current_chan) in channels {

    if '(current_chan).valid_out' {

    if active_channel != UNDEF then {

    out ("Mutex violation in ",

    unit-exp An expression that returns a unit instance. If no expression is specified,

    the current unit instance is assumed.

  • 7/28/2019 Sequece library for E

    29/304

    e_path() PredefinedMethods

    e Libraries Preliminary 2-15

    get_unit().full_hdl_path());};

    active_channel = index;

    };

    };

    wait cycle;

    };

    };

    };

    See Also

    hdl_path() on page 2-11

    e_path() on page 2-15

    2.3.3 e_path()

    Purpose

    Returns the location of a unit instance in the unit tree

    Category

    Predefined method for any unit

    Syntax

    [unit-exp.]e_path(): string

    Syntax example:

    out("Started checking ", get_unit().e_path());

    Parameters

    Description

    Returns the location of a unit instance in the unit tree. This method is used mainly in

    informational messages.

    unit-exp An expression that returns a unit instance. If no expression is specified, the

    current unit instance is assumed.

  • 7/28/2019 Sequece library for E

    30/304

    Predefined Methods get_parent_unit()

    2-16 Preliminary e Libraries

    Example

    This example uses e_path() to show which unit instance is being checked.

    extend XYZ_router {

    !current_chan: XYZ_channel;

    mutex_checker() @pclk is {

    out("Started checking ", get_unit().e_path());

    while ('packet_valid') {

    var active_channel: int = UNDEF;

    for each XYZ_channel(current_chan) in channels {

    if '(current_chan).valid_out' {

    check that active_channel == UNDEF else

    dut_error ("Violation of the mutual exclusion \

    by channels ", active_channel, " and ", index);

    active_channel = index;

    check that active_channel == 'addr' else

    dut_error ("Violation of the correspondence \between active channel and selected address");

    };

    };

    wait cycle;

    };

    };

    };

    See Also

    full_hdl_path() on page 2-14

    hdl_path() on page 2-11

    2.3.4 get_parent_unit()

    Purpose

    Return a reference to the unit containing the current unit instance

    Category

    Predefined method for any unit

  • 7/28/2019 Sequece library for E

    31/304

    Unit-Related Predefined Methods for Any Struct PredefinedMethods

    e Libraries Preliminary 2-17

    Syntax

    [unit-exp.]get_parent_unit():any_unit

    Syntax example:

    out(sys.unit_core.channels[0].get_parent_unit());

    Parameters

    Description

    Returns a reference to the unit containing the current unit instance.

    See Also

    get_unit() on page 2-18

    get_enclosing_unit() on page 2-19

    try_enclosing_unit() on page 2-21

    2.4 Unit-Related Predefined Methods for Any

    StructThe predefined methods for any struct include:

    get_unit() on page 2-18

    get_enclosing_unit() on page 2-19

    try_enclosing_unit() on page 2-21

    set_unit() on page 2-23

    See Also

    Predefined Methods for Any Unit on page 2-11

    Unit-Related Predefined Routines on page 4-36

    unit-exp An expression that returns a unit instance. If no expression is specified,

    the current unit instance is assumed.

  • 7/28/2019 Sequece library for E

    32/304

    Predefined Methods get_unit()

    2-18 Preliminary e Libraries

    2.4.1 get_unit()

    Purpose

    Return a reference to a unit

    Category

    Predefined method of any struct

    Syntax

    [exp.]get_unit(): any_unit

    Syntax example:

    out ("Mutex violation in ", get_unit().full_hdl_path());};

    Parameters

    Description

    When applied to an allocated struct instance, this method returns a reference to theparent unitthe unit to which the struct is bound. When applied to a unit, it returns

    the unit itself.

    Any allocated struct instance automatically establishes a reference to its parent unit. If

    this struct created before the run begins, it inherits the parent unit of its parent struct.

    If the struct is dynamically allocated by the new action, then the parent unit is

    inherited from the struct the enclosing method belongs to.

    This method is useful when you want to determine the parent unit instance of a struct

    or a unit. You can also use this method to access predefined unit members, such as

    hdl_path() or full_hdl_path(). To access user-defined unit members, useget_enclosing_unit(). See Example 1 on page 2-18 for an illustration of this point.

    Example 1

    This example shows that get_unit() can access predefined unit members, while

    get_enclosing_unit() must be used to access user-defined unit members.

    exp An expression that returns a unit or a struct. If no expression is specified, the

    current struct or unit is assumed.

  • 7/28/2019 Sequece library for E

    33/304

    get_enclosing_unit() PredefinedMethods

    e Libraries Preliminary 2-19

    struct instr {

    %opcode : cpu_opcode ;

    %op1 : reg ;

    kind : [imm, reg];

    run() is also {

    -- get_unit().print_msg() ; -- COMPILE-TIME ERROR

    get_enclosing_unit(XYZ_cpu).print_msg();

    out("Destination for this instruction is ",

    get_unit().hdl_path()) ;

    };

    };

    unit XYZ_cpu {

    instrs[3] : list of instr;

    print_msg() is {out("Sending instruction for \

    XYZ_cpu...");};

    };

    extend sys {

    cpu1: XYZ_cpu is instance;

    keep cpu1.hdl_path()=="TOP/CPU1";

    };

    '>

    See Also

    get_parent_unit() on page 2-16

    get_enclosing_unit() on page 2-19

    try_enclosing_unit() on page 2-21

    2.4.2 get_enclosing_unit()

    Purpose

    Return a reference to nearest unit of specified type

    Category

    Predefined pseudo-method of any struct

  • 7/28/2019 Sequece library for E

    34/304

    Predefined Methods get_enclosing_unit()

    2-20 Preliminary e Libraries

    Syntax

    [exp.]get_enclosing_unit(unit_type): unit_type

    Syntax example:

    unpack(p.get_enclosing_unit(XYZ_router).pack_config,

    'data', current_packet);

    Parameters

    Description

    Returns a reference to the nearest higher-level unit instance of the specified type,

    allowing you to access fields of the parent unit in a typed manner.

    You can use the parent unit to store shared data or options such as packing options that

    are valid for all its associated subunits or structs. Then you can access this shared data

    or options with the get_enclosing_unit() method.

    Notes

    The unit type is recognized according to the same rules used for the is a operator. Thismeans, for example, that if you specify a base unit type and there is an instance of a

    unit subtype, the unit subtype is found.

    If a unit instance of the specified type is not found, a run-time error is issued.

    Example 1

    In the following example, get_enclosing_unit() is used to print fields of the nearest

    enclosing unit instances of type XYZ_cpu and tbench. Unlike get_unit(), which

    returns a reference only to its immediate parent unit, get_enclosing_unit() searches

    up the unit instance tree for a unit instance of the type you specify.

    struct instr {

    %opcode : cpu_opcode ;

    %op1 : reg ;

    kind : [imm, reg];

    run() is also {

    exp An expression that returns a unit or a struct. If no expression is specified,

    the current struct or unit is assumed.

    unit_type The name of a unit type or unit subtype.

  • 7/28/2019 Sequece library for E

    35/304

    try_enclosing_unit() PredefinedMethods

    e Libraries Preliminary 2-21

    out("Debug mode for CPU is ",

    get_enclosing_unit(XYZ_cpu).debug_mode);

    out("Memory model is ",

    get_enclosing_unit(tbench).mem_model);

    };

    };

    unit XYZ_cpu {

    instr: instr;

    debug_mode: bool;

    };

    unit tbench {

    cpu: XYZ_cpu is instance;

    mem_model: [small, big];

    };

    extend sys {

    tb: tbench is instance;

    };

    See Also

    get_unit() on page 2-18

    set_unit() on page 2-23

    try_enclosing_unit() on page 2-21

    get_parent_unit() on page 2-16

    2.4.3 try_enclosing_unit()

    Purpose

    Return a reference to nearest unit of specified type or NULL

    Category

    Predefined method of any struct

    Syntax

    [exp.]try_enclosing_unit(unit_type): unit_type

    Syntax example:

  • 7/28/2019 Sequece library for E

    36/304

    Predefined Methods try_enclosing_unit()

    2-22 Preliminary e Libraries

    var MIPS := source_struct().try_enclosing_unit(MIPS);

    Parameters

    Description

    Like get_enclosing_unit(), this method returns a reference to the nearest higher-level

    unit instance of the specified type, allowing you to access fields of the parent unit in a

    typed manner.

    Unlike get_enclosing_unit(), this method does not issue a run-time error if no unit

    instance of the specified type is found. Instead, it returns NULL. This feature makesthe method suitable for use in extensions to global methods such as

    dut_error_struct.write(), which may be used with more than one unit type.

    Example

    See Also

    get_unit() on page 2-18

    get_enclosing_unit() on page 2-19

    get_parent_unit() on page 2-16

    exp An expression that returns a unit or a struct. If no expression is specified,

    the current struct or unit is assumed.

    unit_type The name of a unit type or unit subtype.

  • 7/28/2019 Sequece library for E

    37/304

    set_unit() PredefinedMethods

    e Libraries Preliminary 2-23

    2.4.4 set_unit()

    Purpose

    Change the parent unit of a struct

    Category

    Predefined method of any struct

    Syntax

    [struct-exp.]set_unit(parent:any_unit)

    Syntax example:

    p.set_unit(sys.unit_core)

    Parameters

    DescriptionChanges the parent unit of a struct to the specified unit instance.

    Note

    This method does not exist for units because the unit tree cannot be modified.

    2.5 Pseudo-Methods

    Pseudo-methods calls look like method calls, but unlike methods they are not associated

    with structs and are instead applied to other types of expressions, such as lists.

    Pseudo-methods cannot be changed or extended through use of the is only, is also or is

    first constructs.

    The following sections provide descriptions of the pseudo-methods:

    exp An expression that returns a struct. If no expression is specified, the current

    struct is assumed.

    parent An expression that returns a unit instance.

  • 7/28/2019 Sequece library for E

    38/304

    Predefined Methods declared_type()

    2-24 Preliminary e Libraries

    declared_type() on page 2-24

    type() on page 2-26

    field() on page 2-28

    unsafe() on page 2-29

    source_location() on page 2-30

    as_a() on page 4-25

    swap() on page 4-47

    See Also

    Chapter 3, List Pseudo-Methods

    File Routines on page 4-96

    Chapter 4, Predefined Routines

    2.5.1 declared_type()

    Purpose

    Get declared type descriptor

    Category

    Pseudo-method

    Syntax

    exp.declared_type()[.descriptor-field]: type_descriptor

    Syntax example:

    print pkt1.declared_type().size_in_bytes;

  • 7/28/2019 Sequece library for E

    39/304

    declared_type() PredefinedMethods

    e Libraries Preliminary 2-25

    Parameters

    Description

    Returns the (constant) declared type descriptor. This is useful in cases where the

    actual type of the expression differs from the declared type, due to an assignment of a

    different type or subtype.

    Example

    This example shows the difference between type() and declared_type().

    See Also

    type() on page 2-26

    field() on page 2-28

    exp Any legal e expression.

    descriptor-field The name of a particular field. Valid fields include: name,

    size_in_bytes, short_type, debug, c_name, predefined_declaration,

    parent, children, methods, d_index, range_list, extensions_refs,

    size_in_bits, type_range_list, the_rl, fields, init_fields,

    need_call_init, instantiated, long_copy_required, bit_fields_cnt,

    sgi, unit_info,friends

  • 7/28/2019 Sequece library for E

    40/304

    Predefined Methods type()

    2-26 Preliminary e Libraries

    unsafe() on page 2-29

    Chapter 3, Data Types in the e Language Reference Manual

    2.5.2 type()

    Purpose

    Get type descriptor

    Category

    Pseudo-method

    Syntax

    exp.type()[.descriptor-field]: type_descriptor

    Syntax example:

    print pkt1.type().children;

    Parameters

    Description

    Returns the type descriptor of an expression. When a descriptor field is specified, this

    method returns the value of that field as a string.

    Example 1

  • 7/28/2019 Sequece library for E

    41/304

    type() PredefinedMethods

    e Libraries Preliminary 2-27

    protocol: p;

    size: int [0..1k];

    data[size]: list of byte;

    };

    extend sys {

    m() is {

    var pkt1: packet = new;

    var pkt2: eth packet = new;

    print pkt1.type().children;

    };

    };

    '>

    Example 2

    See Also

    declared_type() on page 2-24

    field() on page 2-28

    unsafe() on page 2-29

    Chapter 3, Data Types in the e Language Reference Manual

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    42/304

    Predefined Methods field()

    2-28 Preliminary e Libraries

    2.5.3 field()

    Purpose

    Get type descriptor for a field

    Category

    Pseudo-method

    Syntax

    struct-exp.field(field-name)[.descriptor-field]: type_descriptor

    Syntax example:

    print pkt1.field(protocol).is_physical;

    Parameters

    Description

    Returns the type descriptor for the specified field.

    Example

  • 7/28/2019 Sequece library for E

    43/304

    unsafe() PredefinedMethods

    e Libraries Preliminary 2-29

    m() is {

    var pkt1: packet =new;

    var pkt2: eth packet = new;

    pkt1 = pkt2;

    print pkt1.field(protocol).is_physical;

    };

    };

    '>

    See Also

    declared_type() on page 2-24

    type() on page 2-26

    unsafe() on page 2-29

    Chapter 3, Data Types in the e Language Reference Manual

    2.5.4 unsafe()

    Purpose

    Bypass type checking

    CategoryPseudo-method

    Syntax

    exp.unsafe(): type

    Parameters

    Description

    Passes the expression with no type checking or auto-casting.

    This method should be used only when calling C routines that perform their own type

    checking.

    exp Any legal e expression.

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    44/304

    Predefined Methods source_location()

    2-30 Preliminary e Libraries

    See Also

    declared_type() on page 2-24

    type() on page 2-26

    field() on page 2-28

    Chapter 3, Data Types in the e Language Reference Manual

    2.5.5 source_location()

    Purpose

    Get source reference string

    Category

    Pseudo-method

    Syntax

    source_location(): string

    Syntax example:

    print source_location();

    Parameters

    None

    Description

    Returns the source location string. The string describes the line number and the

    module name in which the source_location() method was invoked. The format of the

    string is:

    at line line-number in @module-name

    Example

    // module1.e

  • 7/28/2019 Sequece library for E

    45/304

    Semaphore Methods PredefinedMethods

    e Libraries Preliminary 2-31

    extend sys {

    m() is {

    out("I'm ",source_location());

    };

    };

    '>

    See Also

    dut_error_struct on page 9-4 in the e Language Reference Manual

    2.6 Semaphore Methods

    The lock() and release() methods are methods of the struct locker. Together they are used

    as a semaphore to provide a fair, FIFO ordered sharing of resources between multiple

    competing methods.

    lock() and release() on page 2-31

    2.6.1 lock() and release()

    Purpose

    Control access to a shared resource

    Category

    Predefined TCM

    Syntax

    locker.lock()

    locker.release()

    Syntax example:

    lckr.lock();

    lckr.release();

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    46/304

    Predefined Methods lock() and release()

    2-32 Preliminary e Libraries

    Parameters

    Description

    locker is a predefined struct with two predefined methods, lock() and release(). These

    methods are TCMs.

    Once a field is declared to be of type locker, that field can be used to control the

    execution of TCMs by making calls from the TCMs to locker.lock() and

    locker.release().

    If you call locker.lock() from multiple TCMs, the first TCM gets the lock and can

    continue execution. The execution of the other TCMs is blocked. Thus any resources

    that are shared between the TCMs will be available only to the TCM that gets the lock.

    Upon release(), control goes to the next TCM serviced by the scheduler that is waiting

    on the locker. The order in which the lock is granted is by a FIFO (First In First Out)

    order of client lock() requests.

    locker An expression of type locker.

  • 7/28/2019 Sequece library for E

    47/304

    e Libraries Preliminary 3-1

    3 List Pseudo-MethodsThis chapter describes pseudo-methods used to work with lists. It contains the following

    sections:

    Pseudo-Methods Overview on page 3-1

    Using List Pseudo-Methods on page 3-2

    Pseudo-Methods to Modify Lists on page 3-3

    General List Pseudo-Methods on page 3-25

    Sublist Pseudo-Methods on page 3-67

    Math and Logic Pseudo-Methods on page 3-72

    List CRC Pseudo-Methods on page 3-79

    Keyed List Pseudo-Methods on page 3-85

    Restrictions on Keyed Lists on page 3-90

    3.1 Pseudo-Methods OverviewA pseudo-method is a type of method unique to the e language. Pseudo-methods are

    e macros that look like methods. They have the following characteristics:

    Unlike methods, pseudo-methods are not restricted to structs.

  • 7/28/2019 Sequece library for E

    48/304

    List Pseudo-Methods Using List Pseudo-Methods

    3-2 Preliminary e Libraries

    They can be applied to any expression, including literal values, scalars, and compoundarithmetic expressions.

    You cannot extend pseudo-methods.

    List pseudo-methods are associated with list data types, as opposed to being within thescope of a struct.

    See Also

    e Data Types on page 3-2 in the e Language Reference Manual

    list.list-method() on page 2-69 in the e Language Reference Manual

    Chapter 2, Predefined Methods

    3.2 Using List Pseudo-MethodsOnce a list field or variable has been declared, you can operate on it with a list

    pseudo-method by attaching the pseudo-method name, preceded by a period, to the list

    name. Any parameters required by the pseudo-method go in parentheses after the

    pseudo-method name.

    Many of the list pseudo-methods take expressions as parameters, an operate on every item

    in the list.

    For example, the following calls the apply() pseudo-method for the list named p_list,

    with the expression .length + 2 as a parameter. The pseudo-method returns a list ofnumbers found by adding 2 to the length field value in each item in the list.

    n_list = p_list.apply(.length + 2);

    It is important to put a period (.) in front of field names being accessed by pseudo-methods,

    as in .length +2, above.

    In pseudo-methods that take expressions as parameters, the it variable can be used in the

    expression to refer to the current list item, and the index variable can be used to refer to the

    current items list index number.

    Pseudo-methods that return values can only be used in expressions.

    See Also

    Pseudo-Methods Overview on page 3-1

    e Data Types on page 3-2 in the e Language Reference Manual

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    49/304

    Pseudo-Methods to Modify Lists List Pseudo-Methods

    e Libraries Preliminary 3-3

    list.list-method() on page 2-69 in the e Language Reference Manual

    3.3 Pseudo-Methods to Modify Lists

    This section describes the pseudo-methods that change one or more items in a list.The pseudo-methods in this section are:

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.clear() on page 3-9

    list.delete() on page 3-11

    list.fast_delete() on page 3-13

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.pop() on page 3-17

    list.pop0() on page 3-18

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

    See Also

    Pseudo-Methods Overview on page 3-1

    Using List Pseudo-Methods on page 3-2

    http://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdfhttp://../e_lrm/e_lrm.pdf
  • 7/28/2019 Sequece library for E

    50/304

    List Pseudo-Methods list.add(item)

    3-4 Preliminary e Libraries

    3.3.1 list.add(item)

    Purpose

    Add an item to the end of a list

    Category

    Pseudo-method

    Syntax

    list.add(item: list-type)

    Syntax example:

    var i_list: list of int;

    i_list.add(5);

    Parameters

    Description

    Adds the item to the end of the list.

    Example 1

    The following adds 2 to the end of the list named i_list (that is, to index position 3).

    var i_list: list of int = {3; 4; 6};

    i_list.add(2);

    See Also

    list.add(list) on page 3-5

    list A list.

    item An item of the same type as the list type, which is to be added to the list. The

    item is added at index list.size(). That is, if the list contains five items, the last

    item is at index list.size() - 1, or 4. Adding an item to this list places it at index

    5.

  • 7/28/2019 Sequece library for E

    51/304

    list.add(list) ListPseudo-Methods

    e Libraries Preliminary 3-5

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

    3.3.2 list.add(list)

    Purpose

    Add a list to the end of another list

    Category

    Pseudo-method

    Syntax

    list_1.add(list_2: list)

    Syntax example:

    i_list.add(l_list);

    Parameters

    Description

    Adds list_2 to the end oflist_1.

    list_1 A list.

    list_2 A list of the same type as list_1, which is to be added to the end of list_1. The

    list is added at index list.size(). That is, if the list contains five lists, the lastlist is at index list.size() - 1, or 4. Adding a list to this list places it at index 5.

  • 7/28/2019 Sequece library for E

    52/304

    List Pseudo-Methods list.add(list)

    3-6 Preliminary e Libraries

    Example 1

    The following adds blue, green, and red to the list named colors_1.

    Example 2The following example adds the literal list {blue; green; red} to the list named

    colors_3. The colors_3 list then contains red, red, blue, blue, green,

    red.

    var colors_3 := {"red"; "red"; "blue"};

    colors_3.add({"blue"; "green"; "red"});

    See Also

    list.add(item) on page 3-4

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

  • 7/28/2019 Sequece library for E

    53/304

    list.add0(item) ListPseudo-Methods

    e Libraries Preliminary 3-7

    3.3.3 list.add0(item)

    Purpose

    Add an item to the head of a list

    Category

    Pseudo-method

    Syntax

    list.add0(item: list-type)

    Syntax example:

    var l_list: list of int = {4; 6; 8};

    l_list.add0(2);

    Parameters

    Description

    Adds a new item to an existing list. The item is placed at the head of the existing list,

    as the first position (that is, at index 0). All subsequent items are then reindexed by

    incrementing their old index by one.

    Example

    The following example adds 1 to the beginning of the list named i_list. The i_list

    then contains 1, 1, 2, 3, 4, 5.

    var i_list: list of int = {1;2;3;4;5};

    i_list.add0(1);

    See Also

    list.add(item) on page 3-4

    list A list.

    item An item of the same type as the list items, which is to be added to the head of

    the list.

  • 7/28/2019 Sequece library for E

    54/304

    List Pseudo-Methods list.add0(list)

    3-8 Preliminary e Libraries

    list.add(list) on page 3-5

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

    3.3.4 list.add0(list)

    Category

    Pseudo-method

    Syntax

    list_1.add0(list_2: list)

    Syntax example:

    var i_list: list of int = {1; 3; 5};var l_list: list of int = {2; 4; 6};

    i_list.add0(l_list);

    Purpose

    Add a list to the head of another list

    Parameters

    list_1 A list.

    list_2 A list of the same type as list_1, which is to be added to the beginning of

    list_1 (at list_1 index 0)

  • 7/28/2019 Sequece library for E

    55/304

    list.clear() ListPseudo-Methods

    e Libraries Preliminary 3-9

    Description

    Adds a new list to an existing list. The list_2 list is placed at the head of the existing

    list_1 list, starting at the first list_1 index. All subsequent items are then reindexed by

    incrementing their old index by the size of the new list being added.

    Example

    The following adds 1, 2, 3, and 4 to the beginning of the list named b_list. The

    b_list then contains 1, 2, 3, 4, 5, 6.

    var a_list: list of int = {1;2;3;4};

    var b_list: list of int = {5;6};

    b_list.add0(a_list);

    Note

    b_list.add0(a) returns the same result as a_list.add(b) in the above example, except

    that in the example, b_list is added into a_list, while b_list.add0(a) adds a_list

    into b_list.

    See Also

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

    3.3.5 list.clear()

    Purpose

    Delete all items from a list

  • 7/28/2019 Sequece library for E

    56/304

    List Pseudo-Methods list.clear()

    3-10 Preliminary e Libraries

    Category

    Pseudo-method

    Syntax

    list.clear()

    Syntax example:

    a_list.clear();

    Parameters

    Return Value

    None

    Description

    Deletes all items in the list.

    Example

    The following removes all items from the list named l_list.

    l_list.clear();

    See Also

    list.delete() on page 3-11

    list.fast_delete() on page 3-13

    list.resize() on page 3-22

    list.pop() on page 3-17

    list.pop0() on page 3-18

    list A list.

  • 7/28/2019 Sequece library for E

    57/304

    list.delete() ListPseudo-Methods

    e Libraries Preliminary 3-11

    3.3.6 list.delete()

    Purpose

    Delete an item from a list

    Category

    Pseudo-method

    Syntax

    list.delete(index: int)

    Syntax example:

    var l_list: list of int = {2; 4; 6; 8};

    l_list.delete(2);

    Parameters

    Description

    Removes item number index from list(indexes start counting from 0). The indexes of

    the remaining items are adjusted to keep the numbering correct.

    Example 1

    The following deletes 7 from index position 1 in the list named y_list. The list then

    consists of 5 (index 0) and 9 (index 1).

    var y_list := {5; 7; 9};

    y_list.delete(1);

    list A list.

    index The index of the item that is to be deleted from the list.

  • 7/28/2019 Sequece library for E

    58/304

    List Pseudo-Methods list.delete()

    3-12 Preliminary e Libraries

    Example 2

    The following shows a user-defined method named del_range() which, given a list, a

    from value, and a to value, produces a new list (with the same name) of the items in

    the previous list minus the items with indexes in the given range.

    See Also

    list.clear() on page 3-9

    list.fast_delete() on page 3-13

    list.pop() on page 3-17

    list.pop0() on page 3-18

    list.resize() on page 3-22

    list.first_index() on page 3-34

    list.get_indices() on page 3-36

    list.last_index() on page 3-44

    list.max_index() on page 3-47

    list.min_index() on page 3-52

  • 7/28/2019 Sequece library for E

    59/304

    list.fast_delete() ListPseudo-Methods

    e Libraries Preliminary 3-13

    3.3.7 list.fast_delete()

    Purpose

    Delete an item without adjusting all indexes

    Category

    Pseudo-method

    Syntax

    list.fast_delete(index: int)

    Syntax example:

    var l_list: list of int = {2; 4; 6; 8};

    l_list.fast_delete(2);

    Parameters

    Description

    Removes item number index from list(indexes start counting from 0). The index of

    the last item in the list is changed to the index of the item that was deleted, so all items

    following the deleted item keep their original indexes except that the original last

    index is removed.

    Example

    The following deletes C from index position 2 in the list named y_list, and

    changes the index of the last item from 4 to 2. The new y_list is A, B, E, D.

  • 7/28/2019 Sequece library for E

    60/304

    List Pseudo-Methods list.insert(index, item)

    3-14 Preliminary e Libraries

    };

    };

    };

    >

    See Also

    list.clear() on page 3-9

    list.delete() on page 3-11

    list.pop() on page 3-17

    list.pop0() on page 3-18

    list.resize() on page 3-22

    list.first_index() on page 3-34

    list.get_indices() on page 3-36

    list.last_index() on page 3-44

    list.max_index() on page 3-47

    list.min_index() on page 3-52

    3.3.8 list.insert(index, item)

    Purpose

    Insert an item in a list at a specified index

    Category

    Pseudo-method

    Syntax

    list.insert(index: int, item: list-type)

    Syntax example:

    var l_list := {10; 20; 30; 40; 50};

    l_list.insert(3, 99);

  • 7/28/2019 Sequece library for E

    61/304

    list.insert(index, item) ListPseudo-Methods

    e Libraries Preliminary 3-15

    Parameters

    Description

    Inserts the item at the index location in the list. Ifindex is the size of the list, then the

    item is simply added at the end of the list. All indexes in the list are adjusted to keep

    the numbering correct.

    Example

    In the following example, 10 is first inserted into position 2 in s_list, and then 77 is

    inserted into position 1. The resulting list contains 5, 77, 1, 10.

    var s_list := {5; 1};

    s_list.insert(2,10);

    s_list.insert(1,77);

    See Also

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

    list A list.

    index The index in the list where the item is to be inserted.

    item An item of the same type as the list.

  • 7/28/2019 Sequece library for E

    62/304

    List Pseudo-Methods list.insert(index, list)

    3-16 Preliminary e Libraries

    3.3.9 list.insert(index, list)

    Purpose

    Insert a list in another list starting at a specified index

    Category

    Pseudo-method

    Syntax

    list_1.insert(index: int, list_2: list)

    Syntax example:

    var l_list := {10; 20; 30; 40; 50};

    var m_list := {11; 12; 13};

    l_list.insert(1, m_list);

    Parameters

    Description

    Inserts all items oflist_2 into list_1 starting at index. The index must be a positive

    integer. The size of the new list size is equal to the sum of the sizes oflist_1 and list_2.

    Example

    In the following example, blue, green, and red are inserted after red in the

    colors_1 list. The colors_l list is then red, blue, green, red, green,

    blue.

    var colors_14 := {"red"; "green"; "blue"};

    var colors_15 := {"blue"; "green"; "red"};

    colors_14.insert(1, colors_15);

    list_1 A list.

    index The index of the position in list_1 where list_2 is to be inserted.

    list_2 A list that is to be inserted into list_1.

  • 7/28/2019 Sequece library for E

    63/304

    list.pop() ListPseudo-Methods

    e Libraries Preliminary 3-17

    See Also

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.push() on page 3-19

    list.push0() on page 3-21

    list.resize() on page 3-22

    3.3.10 list.pop()

    Purpose

    Remove and return the last list item

    Category

    Pseudo-method

    Syntax

    list.pop(): list-type

    Syntax example:

    var i_list:= {10; 20; 30};

    var i_item: int;

    i_item = i_list.pop();

    Parameters

    list A list.

  • 7/28/2019 Sequece library for E

    64/304

    List Pseudo-Methods list.pop0()

    3-18 Preliminary e Libraries

    Description

    Removes the last item (the item at index list.size() - 1) in the listand returns it.

    Note

    Use list.top() to return the last item in listwithout removing it from the list.

    Example

    In the following example, the s_item variable gets d, and the s_list becomes

    a, b, c.

    var s_item: string;

    var s_list := {"a"; "b"; "c"; "d"};

    s_item = s_list.pop();

    See Also

    list.pop0() on page 3-18

    list.delete() on page 3-11

    list.top() on page 3-63

    3.3.11 list.pop0()

    Purpose

    Remove and return the first list item

    Category

    Pseudo-method

    Syntax

    list.pop0(): list-type

    Syntax example:

    var i_list:= {10; 20; 30};

    var i_item: int;

  • 7/28/2019 Sequece library for E

    65/304

    list.push() ListPseudo-Methods

    e Libraries Preliminary 3-19

    i_item = i_list.pop0();

    Parameters

    Description

    Removes the first item (the item at index 0) from the listand returns it. Subtracts 1

    from the index of each item remaining in the list.

    Note

    Use list.top0() to return the first item in listwithout removing it from the list.

    Example

    In the following example, the s_item variable gets a and s_list becomes b,

    c, d.

    var s_item: string;

    var s_list := {"a"; "b"; "c"; "d"};

    s_item = s_list.pop0();

    See Also

    list.delete() on page 3-11

    list.pop() on page 3-17

    list.top0() on page 3-64

    3.3.12 list.push()

    Purpose

    Put an item in the last position in a list

    Category

    Pseudo-method

    list A list.

  • 7/28/2019 Sequece library for E

    66/304

    List Pseudo-Methods list.push()

    3-20 Preliminary e Libraries

    Syntax

    list.push(item: list-type)

    Syntax example:

    i_list.push(3);

    Parameters

    Description

    Places the item as the last index position in list.

    Example

    In the following example, the s_list becomes a, b, c, d, e.

    var s_item: string;

    var s_list := {"a"; "b"; "c"; "d"};

    s_list.push("e");

    See Also

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push0() on page 3-21

    list A list.

    item An item of the same type as the list, which is to be inserted in the last position

    of the list (at index list.size() - 1).

  • 7/28/2019 Sequece library for E

    67/304

    list.push0() ListPseudo-Methods

    e Libraries Preliminary 3-21

    3.3.13 list.push0()

    Purpose

    Put an item in the first position in a list

    Category

    Pseudo-method

    Syntax

    list.push0(item: list-type)

    Syntax example:

    i_list.push0(3);

    Parameters

    DescriptionPlaces the item as the first index position in the list. Adds 1 to the indexes of the rest of

    the list items.

    Example

    In the following example, the s_list becomes e, a, b, c.

    var s_list := {"a"; "b"; "c"; "d"};

    s_list.push0("e");

    See Also

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list A list.

    item An item of the same type as the list, which is to be inserted in the first position

    of the list (at index 0).

  • 7/28/2019 Sequece library for E

    68/304

    List Pseudo-Methods list.resize()

    3-22 Preliminary e Libraries

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    3.3.14 list.resize()

    Purpose

    Change the size of a list

    Category

    Pseudo-method

    Syntax

    list.resize(size: int [, full: bool, filler: item, keep_old: bool])

    Syntax example:

    var r_list := {2; 3; 5; 6; 8; 9};

    r_list.resize(10, TRUE, 1, TRUE);

    Parameters

    list A list.

    size A positive integer specifying the desired size.

    full A Boolean value specifying all items will be filled with filler. Default:

    TRUE.

    filler An item of the same type of the list items, used as a filler when FULL is

    TRUE.

    keep_old A Boolean value specifying whether to keep existing items already in the

    list. Default: FALSE.

  • 7/28/2019 Sequece library for E

    69/304

    list.resize() ListPseudo-Methods

    e Libraries Preliminary 3-23

    Description

    Allocates a new list of declared size, or resize an old list ifkeep_oldis TRUE. Iffull is

    TRUE, sets all new items to have filleras their value.

    If only the first parameter,size

    , is used, it allocates a new list of the given size and allitems are initialized to the default value for the type.

    If any of the three parameters after size are used, all three of them must be used.

    If the full parameter and the keep_oldparameter are both TRUE, keep_oldhas priority

    over full.

    The full parameter and the keep_oldparameter must both be TRUE to resize a list and

    keep its old values. When keep_oldis TRUE, the list can be lengthened or shortened.

    If the list is lengthened, the added items are filled with filler.

    If the new size is smaller than the original size, the first size items are kept and the restare deleted.

    Ifkeep_oldis FALSE and full is FALSE, the new list has zero size but memory is

    allocated for a list ofsize items.

    Example 1

    The following example puts 200 NULL packet instances into q_list. The initial

    size of the list is 0 when it is created by the var command. The packets are NULL

    because that is the default value for a struct instance.

  • 7/28/2019 Sequece library for E

    70/304

    List Pseudo-Methods list.resize()

    3-24 Preliminary e Libraries

    Example 2

    The following example puts 20 NULL strings in r_list. The initial size of the list is

    0 when it is created by the var command.

    var r_list: list of string;r_list.resize(20, TRUE, NULL, FALSE);

    print r_list.size();

    print r_list;

    Example 3

    The following example makes s_list an empty list, but allocates space for it to hold

    20 integers. The initial size of the list is 0 when it is created by the var command,

    since full is FALSE.

    var s_list: list of int;

    s_list.resize(20, FALSE, 0, FALSE);

    print s_list.size();

    print s_list;

    See Also

    list.add(item) on page 3-4

    list.add(list) on page 3-5

    list.add0(item) on page 3-7

    list.add0(list) on page 3-8

    list.insert(index, item) on page 3-14

    list.insert(index, list) on page 3-16

    list.push() on page 3-19

    list.push0() on page 3-21

    list.max_index() on page 3-47

    list.size() on page 3-56

  • 7/28/2019 Sequece library for E

    71/304

    General List Pseudo-Methods ListPseudo-Methods

    e Libraries Preliminary 3-25

    3.4 General List Pseudo-Methods

    This section describes the syntax for pseudo-methods that perform various operations on

    lists.

    The pseudo-methods in this section are:

    list.apply() on page 3-26

    list.count() on page 3-29

    list.exists() on page 3-30

    list.field on page 3-32

    list.first() on page 3-33

    list.first_index() on page 3-34

    list.get_indices() on page 3-36

    list.has() on page 3-37

    list.is_a_permutation() on page 3-39

    list.is_empty() on page 3-40

    list.last() on page 3-42

    list.last_index() on page 3-44

    list.max() on page 3-45

    list.max_index() on page 3-47

    list.max_value() on page 3-48

    list.min() on page 3-50

    list.min_index() on page 3-52

    list.min_value() on page 3-53

    list.reverse() on page 3-55

    list.size() on page 3-56

    list.sort() on page 3-57

  • 7/28/2019 Sequece library for E

    72/304

    List Pseudo-Methods list.apply()

    3-26 Preliminary e Libraries

    list.sort_by_field() on page 3-59

    list.split() on page 3-61

    list.top() on page 3-63

    list.top0() on page 3-64

    list.unique() on page 3-65

    See Also

    Pseudo-Methods Overview on page 3-1

    Using List Pseudo-Methods on page 3-2

    3.4.1 list.apply()

    Purpose

    Perform a computation on each item in a list

    Category

    Pseudo-method

    Syntax

    list.apply(exp): list

    Syntax example:

    var p_list:= {1; 3; 5};

    var n_list: list of int;;

    n_list = p_list.apply(it*2);

    Parameterslist A list.

    exp Any expression. The it variable can be used to refer to the current list item, and

    the index variable can be used to refer to its index number.

  • 7/28/2019 Sequece library for E

    73/304

    list.apply() ListPseudo-Methods

    e Libraries Preliminary 3-27

    Description

    Applies the exp to each item in the listand returns the changed list.

    Note

    The expression list.apply(it.field) is the same as list.field when fieldis a scalar

    type. For example, the following expressions both return a concatenated list of the

    addr field in each packet item:

    packets.apply(it.addr)

    sys.packets.addr

    The two expressions are different, however, if the field not scalar. For example,

    assuming that data is a list of byte, the first expression returns a list containing the

    first byte of data of each packet item. The second expression is a single item, which

    is the first item in the concatenated list of all data fields in all packet items.

    packets.apply(it.data[0])

    packets.data[0]

    Example 1

    In the following example, the n_list in the sys struct gets a list of integers resulting

    from adding 1 to each len value in the list of packets.

  • 7/28/2019 Sequece library for E

    74/304

    List Pseudo-Methods list.apply()

    3-28 Preliminary e Libraries

    Example 2

    In the following example, the packet struct contains a get_crc() method that calls

    the predefined list.crc_32() on page 3-81. The crc_plus list gets the values returned

    by applying the get_crc() method to every packet in the p_list list.

    Example 3

    In the following example, the ind_list gets the indexes (0, 1, 2) of the items in the

    l_list.

    var l_list: list of int = {5; 7; 9};

    var ind_list: list of int = l_list.apply(index);

    print ind_list;

    See Also

    list.field on page 3-32

    list.all() on page 3-67

  • 7/28/2019 Sequece library for E

    75/304

    list.count() ListPseudo-Methods

    e Libraries Preliminary 3-29

    3.4.2 list.count()

    Purpose

    Return the number of items that satisfy a given condition

    Category

    Pseudo-method

    Syntax

    list.count(exp: bool): int

    Syntax example:

    var ct: int;

    ct = instr_list.count(it.op1 > 200);

    Parameters

    Description

    Returns the number of items for which the exp is TRUE.

    Note

    The syntax list.all(exp).size() returns the same result as the list.count(exp)

    pseudo-method, but list.all(exp).size() creates a new list and is faster.

    Example 1

    The following example prints 3, since there are three items in l_list with values

    greater than 3.

    var l_list: list of int = {2; 3; 4; 5; 6};

    print l_list.count(it > 3)

    list A list.

    exp A Boolean expression. The it variable can be used to refer to the current list

    item, and the index variable can be used to refer to its index number.

  • 7/28/2019 Sequece library for E

    76/304

    List Pseudo-Methods list.exists()

    3-30 Preliminary e Libraries

    Example 2

    The following example prints the number of packet struct instances in the packets

    list that have a length field value smaller than 5.

    See Also

    list.has() on page 3-37

    list.all() on page 3-67

    list.all_indices() on page 3-70

    list.key() on page 3-86

    list.key_exists() on page 3-89

    3.4.3 list.exists()

    Purpose

    Check if an index exists in a list

    Category

    Pseudo-method

    Syntax

    list.exists(index: int): bool

  • 7/28/2019 Sequece library for E

    77/304

    list.exists() ListPseudo-Methods

    e Libraries Preliminary 3-31

    Syntax example:

    var i_chk: bool;

    i_chk = packets.exist