prelim e lib

304
e Libraries Preliminary

Upload: chandan-sangal

Post on 20-Apr-2015

51 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Prelim e Lib

e LibrariesPreliminary

Page 2: Prelim e Lib

Inc.

he

anyrior

t aryay

en

to thet.

ay

th inse at

d

Legal Notice

Copyright © 1998-2002 Verisity Design, Inc. All rights reserved. The contents of thisdocument constitute valuable proprietary and confidential property of Verisity Design,

Trademarks

Verisity® is a trademark of Verisity Ltd or its subsidiaries (Verisity), registered in theUnited States and other jurisdictions. The Verisity logo,eVC, Invisible Specman, Lintrpt,Pure IP, Specman, Specman Elite, Specview, SureCov, SureLint, SureSight, andVerification Advisor are trademarks of Verisity Design, Inc. All other trademarks are texclusive property of their respective owners.

Confidentiality Notice

No part of this information product may be reproduced, transmitted, or translated in form or by any means, electronic, mechanical, manual, optical, or otherwise without pwritten permission from Verisity Design, Inc.

Information in this product is subject to change without notice and does not represencommitment on the part of Verisity. The information contained herein is the proprietaand confidential information of Verisity or its licensors, and is supplied subject to, and mbe used only by Verisity’s customers in accordance with, a written agreement betweVerisity and its customers. Except as may be explicitly set forth in such agreement,Verisity does not make, and expressly disclaims, any representations or warranties ascompleteness, accuracy, or usefulness of the information contained in this documenVerisity does not warrant that use of such information will not infringe any third partyrights, nor does Verisity assume any liability for damages or costs of any kind that mresult from use of such information.

Restricted Rights Legend

Use, duplication, or disclosure by the Government is subject to restrictions as set forsubparagraphs (c)(1)(ii) of the Rights in Technical Data and Computer Software clauDFARS 252.227-7013.

Destination Control Statement

All technical data contained in this product is subject to the export control laws of theUnited States of America. Disclosure to nationals of other countries contrary to UniteStates law is prohibited. It is the reader’s responsibility to determine the applicableregulations and to comply with them.

Page 3: Prelim e Lib

Table of Contents

.1-2

.1-3

. .2-2

.2-2

.2-3

.2-4

.2-5

.2-6

.2-7

2-8

.2-9

-102-11

2-11

-14

2-15

2-16-17

2-18

2-19

-21

2-23

1 About This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-11.1 Conventions in This Book . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

1.2 Syntax Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2 Predefined Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12.1 Predefined Methods of sys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.1.1 sys.init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.1.2 sys.run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2.2 Predefined Methods of Any Struct . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.2.1 copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.2.2 do_print() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.2.3 init() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.2.4 print_line() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.2.5 quit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.2.6 run() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22.3 Predefined Methods for Any Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.3.1 hdl_path() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.3.2 full_hdl_path() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2.3.3 e_path() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.3.4 get_parent_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2.4 Unit-Related Predefined Methods for Any Struct . . . . . . . . . . . . . . . . . .2

2.4.1 get_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.4.2 get_enclosing_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.4.3 try_enclosing_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2.4.4 set_unit() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

e Libraries Preliminary i

Page 4: Prelim e Lib

Table of Contents

.2-23

2-24

2-26

-28

2-29

2-302-31

-31

. .3-1

.3-2

.3-3

.3-4

.3-5

.3-7

.3-8

.3-9

3-11

3-13

-14

-16

3-17

3-18

3-19

3-21

3-22.3-25

-26

3-29

3-30

-32

-33

-34

3-36

3-37

2.5 Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.5.1 declared_type() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.5.2 type() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.5.3 field() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2

2.5.4 unsafe() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.5.5 source_location() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2.6 Semaphore Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

2.6.1 lock() and release() . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2

3 List Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13.1 Pseudo-Methods Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.2 Using List Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3 Pseudo-Methods to Modify Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.1 list.add(item) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.2 list.add(list) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.3 list.add0(item) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.4 list.add0(list) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.5 list.clear() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.6 list.delete() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.7 list.fast_delete() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.8 list.insert(index, item) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.3.9 list.insert(index, list) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.3.10 list.pop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.11 list.pop0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.12 list.push() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.13 list.push0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.3.14 list.resize() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.4 General List Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.1 list.apply() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.2 list.count() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.3 list.exists() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.4 list.field . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.5 list.first() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.6 list.first_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.7 list.get_indices() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.8 list.has() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ii Preliminary e Libraries

Page 5: Prelim e Lib

Table of Contents

3-39

3-40

3-42

3-44

3-45

3-47

3-48

-50

-52

-53

3-55

3-56

3-57

-59

-61

3-63

3-64

3-65.3-67

-67

-703-72

3-72

3-73

-75

-76

3-78.3-79

3-80

3-81

-84.3-85

3-86

-87

3-893-90

3.4.9 list.is_a_permutation() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.10 list.is_empty() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.11 list.last() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.12 list.last_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.13 list.max() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.14 list.max_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.15 list.max_value() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.16 list.min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.17 list.min_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.18 list.min_value() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.19 list.reverse() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.20 list.size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.21 list.sort() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.22 list.sort_by_field() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.23 list.split() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.4.24 list.top() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.25 list.top0() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.4.26 list.unique() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.5 Sublist Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.5.1 list.all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.5.2 list.all_indices() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33.6 Math and Logic Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.6.1 list.and_all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.6.2 list.average() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.6.3 list.or_all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.6.4 list.product() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.6.5 list.sum() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.7 List CRC Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.7.1 list.crc_8() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.7.2 list.crc_32() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.7.3 list.crc_32_flip() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .33.8 Keyed List Pseudo-Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.8.1 list.key() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

3.8.2 list.key_index() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3

3.8.3 list.key_exists() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3.9 Restrictions on Keyed Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

e Libraries Preliminary iii

Page 6: Prelim e Lib

Table of Contents

.4-1

. .4-2

.4-2

.4-5

4-104-12

4-12

4-14

4-15

4-16

4-17

4-18

4-19

4-20

4-21

4-224-23

4-23.4-25

4-25

4-354-36

4-364-37

-38

-42

4-47

-49

-53.4-57

4-59

4-60

4-61

4-62

4-64

4 Predefined Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14.1 Predefined Routines Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.2 Deep Copy and Compare Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.2.1 deep_copy() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.2.2 deep_compare() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.2.3 deep_compare_physical() . . . . . . . . . . . . . . . . . . . . . . . . . . .4.3 Arithmetic Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.1 min() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.2 max() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.3 abs() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.4 odd() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.5 even() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.6 ilog2() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.7 ilog10() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.8 ipow() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.9 isqrt() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.3.10 div_round_up() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.4 Bitwise Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.4.1 bitwise_op() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.5 Type-Related Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.5.1 as_a() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.5.2 all_values() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.6 Unit-Related Predefined Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.6.1 get_all_units() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.7 Constructs for Packing and Unpacking . . . . . . . . . . . . . . . . . . . . . . . . . .

4.7.1 pack() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.7.2 unpack() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.7.3 swap() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.7.4 do_pack() . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.7.5 do_unpack() . . . . . . . . . . . . . . . . . . . . . . . . . . .44.8 String Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.1 append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.2 appendf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.3 bin() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.4 dec() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.5 hex() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

iv Preliminary e Libraries

Page 7: Prelim e Lib

Table of Contents

4-65

4-66

4-67

4-68

4-69

4-70

4-71

4-72

4-73

4-75

4-76

4-78

4-79

4-80

4-81

4-82.4-84

4-84

4-854-88

.4-88

4-89

4-90

4-91

4-92

4-93

4-94

4-95.4-96

4-97-97

-98

4-99

-101

-102

-104

4.8.6 quote() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.7 str_chop() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.8 str_empty() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.9 str_exactly() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.10 str_insensitive() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.11 str_join() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.12 str_len() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.13 str_lower() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.14 str_match() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.15 str_pad() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.16 str_replace() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.17 str_split() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.18 str_split_all() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.19 str_sub() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.20 str_upper() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.8.21 to_string() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.9 Output Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.9.1 out() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.9.2 outf() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.9.3 Format String . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10 OS Interface Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.1 spawn() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.2 spawn_check() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.3 system() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.4 output_from() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.5 output_from_check() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.6 get_symbol() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.10.7 date_time() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.11 File Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.11.1 File Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4.11.2 Low-Level File Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.3 files.add_file_type() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.4 files.close() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

4.11.5 files.flush() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.6 files.open() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.7 files.read() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

e Libraries Preliminary v

Page 8: Prelim e Lib

Table of Contents

-106

107

109-110

-111

-113

114

-115

-116

-118

119

121

-122

123

125

126

-128

-129

130

132-133

-134

-135

137

139-141

-141

.5-1

. .5-2

. .5-2

. .5-5

.5-6

.5-8. .5-9

4.11.8 files.read_lob() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

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

4.11.10 files.write_lob() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-4.11.11 General File Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.12 files.file_age() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.13 files.file_append() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

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

4.11.15 files.file_delete() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.16 files.file_exists() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.17 files.file_extension() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

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

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

4.11.20 files.file_is_readable() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

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

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

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

4.11.24 files.file_rename() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.25 files.file_size() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

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

4.11.27 files.write_string_list() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-4.11.28 Reading and Writing Structs . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.29 files.read_ascii_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.11.30 files.read_binary_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

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

4.11.32 files.write_binary_struct() . . . . . . . . . . . . . . . . . . . . . . . . . . . .4-4.12 Calling Predefined Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4

4.12.1 routine() . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

5 Modeling State Machines . . . . . . . . . . . . . . . . . . . . . . . . . 5-15.1 State Machine Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.2 State Machine Constructs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.2.1 state machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.2.2 state => state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.2.3 * => state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.2.4 state action . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5.3 Sample State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

vi Preliminary e Libraries

Page 9: Prelim e Lib

Table of Contents

.5-10

-10

5-11

5-12

.5-135-14

5.4 Using State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.4.1 Initializing a State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . .5

5.4.2 Terminating a State Machine . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.4.3 Rules for State Transitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

5.4.4 Nested State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.4.5 Parallel State Machines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Index

e Libraries Preliminary vii

Page 10: Prelim e Lib

Table of Contents

viii Preliminary e Libraries

Page 11: Prelim e Lib

e the

ahisotty or

1 About This Book

Thee language is an object-oriented programming language. Althoughe can be used tocreate any general-purpose software program, it has been designed to facilitate theverification of electronic designs. The verification-specific constructs that distinguishefrom 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)

Thee language also is designed to reduce the effort required to write tests and to makhigh-level intent of the test readily apparent. In contrast to other object-orientedprogramming languages,e’s unique extensibility lets you modify multiple data objects insingle, separate test file that is layered on top of the base verification environment. Textensibility feature allows you to address systemic, test-specific concerns that are nlocalized to a single data object’s boundaries in a way that does not sacrifice modularireadability.

e Libraries provides detailed information one’s built-in (predefined) methods androutines.

For information on the constructs of theeprogramming language, refer to theeLanguageReference Manual.

e Libraries Preliminary 1-1

Page 12: Prelim e Lib

About This Book Conventions in This Book

se

,

t

d

e

:

1.1 Conventions in This BookThis manual uses visual cues to help you locate and interpret information easily. Thecues are explained in Table 1-1.

Table 1-1 Document Conventions

Visual Cue Represents

courier The Courier font indicateseor HDL code. For example, thefollowing line indicatesecode:

keep opcode in [ADD, ADDI];

bold The bold font indicates keywords in descriptive text. For examplethe following sentence contains the keyword “keep”:

Use thekeepconstruct to guide test generation andconfiguration.

The bold font is used in syntax descriptions to indicate text that musbe typed exactly as it appears. For example, in the followingsentence the keywords “keep” and “reset_soft”, as well as the perioand 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:

keepconstraint-bool-exp

[ ] squarebrackets

Square brackets indicate optional parameters. For example, in thfollowing construct the keywords “list of” are optional:

var name: [list of] type

[ ] bold brackets Bold square brackets are required. For example, in the followingconstruct you must type the bold square brackets as they appear

extendenum-type-name: [name,…]

1-2 Preliminary e Libraries

Page 13: Prelim e Lib

Syntax Notation About This Book

t has

own.e

ion.

e.

isfirst

)

e

1.2 Syntax NotationEach construct section starts with the syntax for the construct. The syntax shows theconstruct, any arguments it accepts with their types, and the construct’s return type if ione.

When using the construct, terms in bold in the syntax are to be entered exactly as shTerms in italics are to be replaced by terms of your own. The argument types and thconstruct return type are for information only and are not entered.

For example, the syntax notation for the predefined pseudo-method namedlist.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 express

• “: bool” indicates that the expression must be a Boolean expression.

• “: list-type” means that the pseudo-method returns an item of the list element typ

An example of a call to thelist.first() pseudo-method is shown below, where “numbers”a list of integer items and “my_number” is an integer. The pseudo-method returns theinteger in the list greater than 5:

my_number = numbers.first(it > 5)

construct, … An item, followed by a separator (usually a comma or a semicolonand an ellipsis is an abbreviation for a list of elements of thespecified type. For example, the following line means you can typa list of zero or more names separated by commas.

extendenum-type-name: [name,…]

| The | character indicates alternative syntax or parameters. Forexample, the following line indicates that either thebits or byteskeyword should be used:

type scalar-type (bits | bytes: num)

Table 1-1 Document Conventions (continued)

Visual Cue Represents

e Libraries Preliminary 1-3

Page 14: Prelim e Lib

About This Book Syntax Notation

1-4 Preliminary e Libraries

Page 15: Prelim e Lib

set, and

2 Predefined Methods

Part of the functionality ofe programs is implemented as set of predefined methodsdefined directly under thesys struct.

Furthermore, every struct that is already available to you or is defined by you inherits aof predefined methods. Some of these methods can be extended to add functionalitysome 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 ofexpressions.

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”

e Libraries Preliminary 2-1

Page 16: Prelim e Lib

Predefined Methods Predefined Methods of sys

• “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 forsys

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.

2-2 Preliminary e Libraries

Page 17: Prelim e Lib

sys.run() Predefined Methods

pty.

See Also

• init() on page 2-7

2.1.2 sys.run()

Purpose

Recommended place for starting TCMs

Category

Predefined method forsys

Syntax

[sys.]run()

Syntax example:

run() is also {start monitor();

};

Parameters

None

Description

You can extend this method to start user-defined TCMs. The method is initially em

Example

<'extend sys {

id : int;monitor() @sys.clk is {

while (TRUE) {wait [2] * cycle;out("cycle ", sys.time,

" Packet id ", id, " is still running");};

e Libraries Preliminary 2-3

Page 18: Prelim e Lib

Predefined Methods Predefined Methods of Any Struct

y ofry outfined

};

run() is also {start monitor();

};};'>

See Also

• run() on page 2-10

• start tcm() on page 6-21 in theeLanguage Reference Manual

2.2 Predefined Methods of Any StructThe following methods are available for any struct that you define and instantiate. Manthese methods do not require parameters, nor do they return values; they simply cara procedure. The predefined methods for any struct are also available for any user-deunit.

• 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

2-4 Preliminary e Libraries

Page 19: Prelim e Lib

copy() Predefined Methods

tems

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 theexpression is a list or a struct that contains other lists or structs, the second-level iare not duplicated. Instead, they are copied by reference.

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

exp Any legaleexpression.

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

string The whole string is copied.

e Libraries Preliminary 2-5

Page 20: Prelim e Lib

Predefined Methods do_print()

ns

st

in

as

e

Notes

• Use thedeep_copy()method if you want a recursive copy of a struct or list that contaicompound 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 Ifexp is a scalar list, a new list with the same size as the original liis 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. Thecontents of the list is copied by reference, meaning that each itemthe new list points to the corresponding item in the original list.

struct Ifexpis a struct instance, a new struct instance with the same typethe original struct is allocated. All scalar fields are duplicated. Allcompound fields (lists or structs) in the new struct instance point to thcorresponding fields in the original struct.

2-6 Preliminary e Libraries

Page 21: Prelim e Lib

init() Predefined Methods

Parameters

Description

Controls the printing of information about a particular struct. You can extend thismethod to customize the way information is displayed.

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

Example

<'struct a {

i: int;s: string;do_print() is first {

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

};extend sys {

m() is {var aa := a new a with {

.i = 1;

.s = "AA";};print aa;

};};'>

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.

e Libraries Preliminary 2-7

Page 22: Prelim e Lib

Predefined Methods print_line()

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

Description

You can extend theinit() method of a struct to set values for fields that you want tohave a different value than the default value.

See Also

• “Packing and Unpacking Lists” on page 16-10 in theeLanguage Reference Manual

• “e Data Types” on page 3-2 in theeLanguage Reference Manual

• { ; } on page 2-63 in theeLanguage 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.

2-8 Preliminary e Libraries

Page 23: Prelim e Lib

quit() Predefined Methods

ted

m

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 tabulatable 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

Category

Predefined 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, thetype argument isNULL.To print the header for the list, the struct argument is of the for

type .type()

exp An expression that returns a unit or a struct.

e Libraries Preliminary 2-9

Page 24: Prelim e Lib

Predefined Methods run()

eing

Description

Deactivates a struct instance, killing all threads associated with the struct and freup 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

<'struct packet {

id : int;monitor() @sys.any is {

while (TRUE) {wait [2] * cycle;out("cycle ", sys.time,

" Packet id ", id, " is still running");

exp An expression that returns a unit or a struct.

2-10 Preliminary e Libraries

Page 25: Prelim e Lib

Predefined Methods for Any Unit Predefined Methods

for

};};

run() is also {start monitor();

};};'>

See Also

• sys.run() on page 2-3

• start tcm() on page 6-21 in theeLanguage Reference Manual

2.3 Predefined Methods for Any UnitThere is a predefined generic typeany_unit, which is derived fromany_struct. any_unitis the base type implicitly used in user-defined unit types, so all predefined methodsany_unit are available for any user-defined unit. The predefined methods forany_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

e Libraries Preliminary 2-11

Page 26: Prelim e Lib

Predefined Methods hdl_path()

s to

nenting

ts.

ed,

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 ibind a unit instance to a particular component in the DUT hierarchy. Binding aneunitor unit instance to a DUT component allows you to reference signals within thatcomponent using relative HDL path names. Regardless of where the DUT compois instantiated in the final integration, the HDL path names are still valid. The bindof unit instances to HDL components must be done inkeep constraints.

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

Note

• You cannot constrain the HDL path forsys.

unit-exp An expression that returns a unit instance. If no expression is specifithe current unit instance is assumed.

2-12 Preliminary e Libraries

Page 27: Prelim e Lib

hdl_path() Predefined Methods

unit

DL

Example 1

This example shows how you can use relative paths in lower-level instances in theinstance tree. To create the full HDL path of each unit instance, its HDL path isprefixed with the HDL path of its parent instance. In this example, because the Hpath ofsysis “”, 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 howhdl_path() returns the HDL path exactly as specified in theconstraint. Thus the firstprint action prints “`TOP.router_i”. The secondprint 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 ineLanguage Reference Manual

• full_hdl_path() on page 2-14

• e_path() on page 2-15

e Libraries Preliminary 2-13

Page 28: Prelim e Lib

Predefined Methods full_hdl_path()

ed

ed,

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 usmainly in informational messages. Like thehdl_path() method, this method returnsthe path as originally specified in thekeep constraint.

Example

This example usesfull_hdl_path() to display information about where a mutexviolation 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 specifithe current unit instance is assumed.

2-14 Preliminary e Libraries

Page 29: Prelim e Lib

e_path() Predefined Methods

ly in

the

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 maininformational messages.

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

e Libraries Preliminary 2-15

Page 30: Prelim e Lib

Predefined Methods get_parent_unit()

Example

This example usese_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

2-16 Preliminary e Libraries

Page 31: Prelim e Lib

Unit-Related Predefined Methods for Any Struct Predefined Methods

fied,

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 AnyStruct

The 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 specithe current unit instance is assumed.

e Libraries Preliminary 2-17

Page 32: Prelim e Lib

Predefined Methods get_unit()

thens

it. Iftruct.

ructh as

t.

the

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 toparent unit—the unit to which the struct is bound. When applied to a unit, it returthe unit itself.

Any allocated struct instance automatically establishes a reference to its parent unthis struct created before the run begins, it inherits the parent unit of its parent sIf the struct is dynamically allocated by thenew action, then the parent unit isinherited from the struct the enclosing method belongs to.

This method is useful when you want to determine the parent unit instance of a stor a unit. You can also use this method to access predefined unit members, suchdl_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 poin

Example 1

This example shows thatget_unit() can access predefined unit members, whileget_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,current struct or unit is assumed.

2-18 Preliminary e Libraries

Page 33: Prelim e Lib

get_enclosing_unit() Predefined Methods

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

e Libraries Preliminary 2-19

Page 34: Prelim e Lib

Predefined Methods get_enclosing_unit()

e,

s thatdata

of a

ed,

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 typallowing 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 optionare valid for all its associated subunits or structs. Then you can access this sharedor options with theget_enclosing_unit() method.

Notes

• The unit type is recognized according to the same rules used for theis aoperator. Thismeans, for example, that if you specify a base unit type and there is an instanceunit 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 nearestenclosing unit instances of type “XYZ_cpu” and “tbench”. Unlikeget_unit(), whichreturns a reference only to its immediate parent unit,get_enclosing_unit() searchesup 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 specifithe current struct or unit is assumed.

unit_type The name of a unit type or unit subtype.

2-20 Preliminary e Libraries

Page 35: Prelim e Lib

try_enclosing_unit() Predefined Methods

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:

e Libraries Preliminary 2-21

Page 36: Prelim e Lib

Predefined Methods try_enclosing_unit()

velin a

kes

ed,

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

Parameters

Description

Like get_enclosing_unit(), this method returns a reference to the nearest higher-leunit instance of the specified type, allowing you to access fields of the parent unittyped manner.

Unlike get_enclosing_unit(), this method does not issue a run-time error if no unitinstance of the specified type is found. Instead, it returns NULL. This feature mathe method suitable for use in extensions to global methods such asdut_error_struct.write() , which may be used with more than one unit type.

Example

<'extend dut_error_struct {

write() is also {var MIPS := source_struct().try_enclosing_unit(MIPS);if MIPS != NULL then {

out("Status of ", MIPS.e_path()," at time of error:");

MIPS.show_status();};

};};'>

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 specifithe current struct or unit is assumed.

unit_type The name of a unit type or unit subtype.

2-22 Preliminary e Libraries

Page 37: Prelim e Lib

set_unit() Predefined Methods

iated

rent

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

Description

Changes 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-MethodsPseudo-methods calls look like method calls, but unlike methods they are not assocwith structs and are instead applied to other types of expressions, such as lists.

Pseudo-methods cannot be changed or extended through use of theis only, is also or isfirst constructs.

The following sections provide descriptions of the pseudo-methods:

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

parent An expression that returns a unit instance.

e Libraries Preliminary 2-23

Page 38: Prelim e Lib

Predefined Methods declared_type()

• 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;

2-24 Preliminary e Libraries

Page 39: Prelim e Lib

declared_type() Predefined Methods

et of a

tion,

Parameters

Description

Returns the (constant) declared type descriptor. This is useful in cases where thactual type of the expression differs from the declared type, due to an assignmendifferent type or subtype.

Example

This example shows the difference betweentype() anddeclared_type().

<'type p: [eth, ieee, foreign];struct packet {

protocol: p;size: int [0..1k];data[size]: list of byte;

};

extend sys {m() is {

var pkt1: packet = new;var pkt2: eth packet = new;pkt1 = pkt2;print pkt1.type().name;print pkt1.declared_type().name;

};};'>

See Also

• type() on page 2-26

• field() on page 2-28

exp Any legaleexpression.

descriptor-field The name of a particular field. Valid fields include: name,size_in_bytes, short_type, debug, c_name, predefined_declaraparent, 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

e Libraries Preliminary 2-25

Page 40: Prelim e Lib

Predefined Methods type()

, this

tion,

• unsafe() on page 2-29

• Chapter 3, “Data Types” in theeLanguage 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 specifiedmethod returns the value of that field as a string.

Example 1

<'type p: [eth, ieee, foreign];struct packet {

exp Any legaleexpression.

descriptor-field The name of a particular field. Valid fields include: name,size_in_bytes, short_type, debug, c_name, predefined_declaraparent, 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

2-26 Preliminary e Libraries

Page 41: Prelim e Lib

type() Predefined Methods

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

<'type p: [eth, ieee, foreign];struct packet {

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();

};};'>

See Also

• declared_type() on page 2-24

• field() on page 2-28

• unsafe() on page 2-29

• Chapter 3, “Data Types” in theeLanguage Reference Manual

e Libraries Preliminary 2-27

Page 42: Prelim e Lib

Predefined Methods field()

tion,

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

<'type p: [eth, ieee, foreign];struct packet {

protocol: p;size: int [0..1k];data[size]: list of byte;

};

extend sys {

struct-exp An expression that returns a struct.

descriptor-field The name of a particular field. Valid fields include: name,size_in_bytes, short_type, debug, c_name, predefined_declaraparent, 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

2-28 Preliminary e Libraries

Page 43: Prelim e Lib

unsafe() Predefined Methods

ype

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 theeLanguage Reference Manual

2.5.4 unsafe()

Purpose

Bypass type checking

Category

Pseudo-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 tchecking.

exp Any legaleexpression.

e Libraries Preliminary 2-29

Page 44: Prelim e Lib

Predefined Methods source_location()

See Also

• declared_type() on page 2-24

• type() on page 2-26

• field() on page 2-28

• Chapter 3, “Data Types” in theeLanguage 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 themodule name in which thesource_location()method was invoked. The format of thestring is:

at line line-number in @ module-name

Example

// module1.e<'

2-30 Preliminary e Libraries

Page 45: Prelim e Lib

Semaphore Methods Predefined Methods

le

extend sys {m() is {

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

};'>

See Also

• dut_error_struct on page 9-4 in theeLanguage Reference Manual

2.6 Semaphore MethodsThe lock() andrelease()methods are methods of the structlocker. Together they are usedas a semaphore to provide a fair, FIFO ordered sharing of resources between multipcompeting 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();

e Libraries Preliminary 2-31

Page 46: Prelim e Lib

Predefined Methods lock() and release()

rcesock.

ngut)

Parameters

Description

locker is a predefined struct with two predefined methods,lock() andrelease(). Thesemethods are TCMs.

Once a field is declared to be of typelocker, that field can be used to control theexecution of TCMs by making calls from the TCMs tolocker.lock() andlocker.release().

If you call locker.lock() from multiple TCMs, the first TCM gets the lock and cancontinue execution. The execution of the other TCMs is blocked. Thus any resouthat are shared between the TCMs will be available only to the TCM that gets the l

Uponrelease(), control goes to the next TCM serviced by the scheduler that is waition the locker. The order in which the lock is granted is by a FIFO (First In First Oorder of clientlock() requests.

locker An expression of typelocker.

2-32 Preliminary e Libraries

Page 47: Prelim e Lib

ing

3 List Pseudo-Methods

This chapter describes pseudo-methods used to work with lists. It contains the followsections:

• “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 thee language. Pseudo-methods areemacros that look like methods. They have the following characteristics:

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

e Libraries Preliminary 3-1

Page 48: Prelim e Lib

List Pseudo-Methods Using List Pseudo-Methods

ound

in the

list

y item

f

ods,

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

• You cannot extend pseudo-methods.

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

See Also

• “e Data Types” on page 3-2 in theeLanguage Reference Manual

• list.list-method() on page 2-69 in theeLanguage 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 listpseudo-method by attaching the pseudo-method name, preceded by a period, to thename. Any parameters required by the pseudo-method go in parentheses after thepseudo-method name.

Many of the list pseudo-methods take expressions as parameters, an operate on everin the list.

For example, the following calls theapply() pseudo-method for the list named “p_list”,with the expression “.length + 2” as a parameter. The pseudo-method returns a list onumbers 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-methas in “.length +2”, above.

In pseudo-methods that take expressions as parameters, theit variable can be used in theexpression to refer to the current list item, and theindex variable can be used to refer to thecurrent item’s 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 theeLanguage Reference Manual

3-2 Preliminary e Libraries

Page 49: Prelim e Lib

Pseudo-Methods to Modify Lists List Pseudo-Methods

• list.list-method() on page 2-69 in theeLanguage Reference Manual

3.3 Pseudo-Methods to Modify ListsThis 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

e Libraries Preliminary 3-3

Page 50: Prelim e Lib

List Pseudo-Methods list.add(item)

3).

Thestx

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 theitem to the end of thelist.

Example 1

The following adds 2 to the end of the list named “i_list” (that is, to index position

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. item is added at index list.size(). That is, if the list contains five items, the laitem is at index list.size() - 1, or 4. Adding an item to this list places it at inde5.

3-4 Preliminary e Libraries

Page 51: Prelim e Lib

list.add(list) List Pseudo-Methods

hest5.

• 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. Tlist is added at index list.size(). That is, if the list contains five lists, the lalist is at index list.size() - 1, or 4. Adding a list to this list places it at index

e Libraries Preliminary 3-5

Page 52: Prelim e Lib

List Pseudo-Methods list.add(list)

d

Example 1

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

<’type color: [blue, green, yellow, orange, red];extend sys {

run() is also {var colors_1: list of color = {red; red; blue};var colors_2: list of color = {blue; green; red};colors_1.add(colors_2);print colors_1;

};};’>

Example 2

The following example adds the literal list {“blue”; “green”; “red”} to the list name“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

3-6 Preliminary e Libraries

Page 53: Prelim e Lib

list.add0(item) List Pseudo-Methods

list, by

t”

d of

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 existingas the first position (that is, at index 0). All subsequent items are then reindexedincrementing their old index by one.

Example

The following example adds 1 to the beginning of the list named “i_list”. The “i_listhen 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 heathe list.

e Libraries Preliminary 3-7

Page 54: Prelim e Lib

List Pseudo-Methods list.add0(list)

f

• 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 olist_1 (at list_1 index 0)

3-8 Preliminary e Libraries

Page 55: Prelim e Lib

list.clear() List Pseudo-Methods

y

Description

Adds a new list to an existing list. Thelist_2 list is placed at the head of the existinglist_1 list, starting at the firstlist_1 index. All subsequent items are then reindexed bincrementing 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, exceptthat 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

e Libraries Preliminary 3-9

Page 56: Prelim e Lib

List Pseudo-Methods list.clear()

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.

3-10 Preliminary e Libraries

Page 57: Prelim e Lib

list.delete() List Pseudo-Methods

f

n

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 numberindexfrom list (indexes start counting from 0). The indexes othe 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 theconsists 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.

e Libraries Preliminary 3-11

Page 58: Prelim e Lib

List Pseudo-Methods list.delete()

st, as in

Example 2

The following shows a user-defined method named del_range() which, given a lifrom value, and a to value, produces a new list (with the same name) of the itemthe previous list minus the items with indexes in the given range.

<’extend sys {

my_list: list of byte;keep my_list.size() == 20;

del_range(in_l:list of byte,from:int,to:int):list of byteis {

result.add(in_l[..from-1]);result.add(in_l[to+1..]);

};

run() is also {my_list = del_range(my_list,5,15);

};};’>

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

3-12 Preliminary e Libraries

Page 59: Prelim e Lib

list.fast_delete() List Pseudo-Methods

ems

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 numberindex from list (indexes start counting from 0). The index ofthe last item in the list is changed to the index of the item that was deleted, so all itfollowing the deleted item keep their original indexes except that the original lastindex is removed.

Example

The following deletes “C” from index position 2 in the list named “y_list”, andchanges the index of the last item from 4 to 2. The new “y_list” is “A”, “B”, “E”, “D”.

<’extend sys {

run() is also {var y_list := {"A"; "B"; "C"; "D"; "E"};y_list.fast_delete(2);for i from 0 to 3 do {

print y_list[i];

list A list.

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

e Libraries Preliminary 3-13

Page 60: Prelim e Lib

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

};};

};’>

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);

3-14 Preliminary e Libraries

Page 61: Prelim e Lib

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

eep

is

Parameters

Description

Inserts theitem at theindex location in thelist. If index is the size of the list, then theitem is simply added at the end of the list. All indexes in the list are adjusted to kthe numbering correct.

Example

In the following example, 10 is first inserted into position 2 in “s_list”, and then 77inserted 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.

e Libraries Preliminary 3-15

Page 62: Prelim e Lib

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

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 atindex. Theindex must be a positiveinteger. The size of the new list size is equal to the sum of the sizes oflist_1andlist_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.

3-16 Preliminary e Libraries

Page 63: Prelim e Lib

list.pop() List Pseudo-Methods

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.

e Libraries Preliminary 3-17

Page 64: Prelim e Lib

List Pseudo-Methods list.pop0()

Description

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

Note

Uselist.top() to return the last item inlist without 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;

3-18 Preliminary e Libraries

Page 65: Prelim e Lib

list.push() List Pseudo-Methods

i_item = i_list.pop0();

Parameters

Description

Removes the first item (the item at index 0) from thelist and returns it. Subtracts 1from the index of each item remaining in the list.

Note

Uselist.top0() to return the first item inlist without 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.

e Libraries Preliminary 3-19

Page 66: Prelim e Lib

List Pseudo-Methods list.push()

ion

Syntax

list.push(item: list-type)

Syntax example:

i_list.push(3);

Parameters

Description

Places theitem as the last index position inlist.

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 positof the list (at index list.size() - 1).

3-20 Preliminary e Libraries

Page 67: Prelim e Lib

list.push0() List Pseudo-Methods

ion

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

Description

Places theitemas the first index position in thelist. Adds 1 to the indexes of the rest ofthe 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 positof the list (at index 0).

e Libraries Preliminary 3-21

Page 68: Prelim e Lib

List Pseudo-Methods list.resize()

is

the

• 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 FULLTRUE.

keep_old A Boolean value specifying whether to keep existing items already inlist. Default: FALSE.

3-22 Preliminary e Libraries

Page 69: Prelim e Lib

list.resize() List Pseudo-Methods

ll

d.

Description

Allocates a new list of declaredsize, or resize an old list ifkeep_oldis TRUE. If full isTRUE, sets all new items to havefiller as their value.

If only the first parameter,size, is used, it allocates a new list of the given size and aitems are initialized to the default value for the type.

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

If the full parameter and thekeep_oldparameter are both TRUE,keep_oldhas priorityoverfull.

Thefull parameter and thekeep_oldparameter must both be TRUE to resize a list ankeep its old values. Whenkeep_oldis TRUE, the list can be lengthened or shortenedIf the list is lengthened, the added items are filled withfiller.

If the newsizeis smaller than the original size, the firstsizeitems are kept and the restare deleted.

If keep_old is FALSE andfull is FALSE, the new list has zero size but memory isallocated for a list ofsize items.

Example 1

The following example puts 200 NULL “packet” instances into “q_list”. The initialsize of the list is 0 when it is created by thevar command. The packets are NULLbecause that is the default value for a struct instance.

<’struct packet {

len: uint;addr: byte;

};extend sys {

run() is also {var q_list: list of packet;print q_list.size();q_list.resize(200);print q_list.size();

};};’>

e Libraries Preliminary 3-23

Page 70: Prelim e Lib

List Pseudo-Methods list.resize()

s

ld

Example 2

The following example puts 20 NULL strings in “r_list”. The initial size of the list i0 when it is created by thevar 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 ho20 integers. The initial size of the list is 0 when it is created by thevar 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

3-24 Preliminary e Libraries

Page 71: Prelim e Lib

General List Pseudo-Methods List Pseudo-Methods

ns on

3.4 General List Pseudo-MethodsThis section describes the syntax for pseudo-methods that perform various operatiolists.

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

e Libraries Preliminary 3-25

Page 72: Prelim e Lib

List Pseudo-Methods list.apply()

d

• 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);

Parameters

list A list.

exp Any expression. Theit variable can be used to refer to the current list item, anthe index variable can be used to refer to its index number.

3-26 Preliminary e Libraries

Page 73: Prelim e Lib

list.apply() List Pseudo-Methods

e

theich

Description

Applies theexp to each item in thelist and returns the changed list.

Note

The expression “list.apply(it.field)” is the same as “list.field” whenfield is a scalartype. For example, the following expressions both return a concatenated list of th“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 containingfirst byte of “data” of each packet item. The second expression is a single item, whis 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 thesys struct gets a list of integers resultingfrom adding 1 to each “len” value in the list of packets.

<’struct packet {

len: uint;addr: byte;data: list of bit;!%crc: uint;

};extend sys {

p_list: list of packet;!n_list: list of uint;run() is also {

n_list = p_list.apply(it.len + 1);};

};’>

e Libraries Preliminary 3-27

Page 74: Prelim e Lib

List Pseudo-Methods list.apply()

llsd

e

Example 2

In the following example, the “packet” struct contains a “get_crc()” method that cathe predefinedlist.crc_32()on page 3-81. The “crc_plus” list gets the values returneby applying the “get_crc()” method to every packet in the “p_list” list.

<’struct packet {

%len: uint;%addr: byte;%data: list of byte;!%crc: int;get_crc(): int is {

return data.crc_32(0, data.size());};

};extend sys {

p_list: list of packet;!crc_plus: list of int;run() is also {

crc_plus = p_list.apply(it.get_crc());};

};’>

Example 3

In the following example, the “ind_list” gets the indexes (0, 1, 2) of the items in th“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

3-28 Preliminary e Libraries

Page 75: Prelim e Lib

list.count() List Pseudo-Methods

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 theexp is TRUE.

Note

The syntaxlist.all(exp).size() returns the same result as thelist.count(exp)pseudo-method, butlist.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 valuesgreater 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. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-29

Page 76: Prelim e Lib

List Pseudo-Methods list.exists()

ts”

Example 2

The following example prints the number of “packet” struct instances in the “packelist that have a “length” field value smaller than 5.

<’struct packet {

length: uint (bits: 4);};extend sys {

packets: list of packet;run() is also {

var pl: int;pl = packets.count(.length < 5);print pl;

};};’>

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

3-30 Preliminary e Libraries

Page 77: Prelim e Lib

list.exists() List Pseudo-Methods

n

Syntax example:

var i_chk: bool;i_chk = packets.exists(5);

Parameters

Description

Returns TRUE if an item with theindexnumber exists in thelist, or returns FALSE ifthe index does not exist.

Example

The firstprint action in the following prints TRUE, because the “int_list” contains aitem with an index of 1. The secondprint action prints FALSE, because there is noitem with index 7 in the list.

<’extend sys {

run() is also {var int_lst: list of int = {1; 2; 3; 4; 5};var ind_ex: bool;ind_ex = int_lst.exists(1);print ind_ex;ind_ex = int_lst.exists(7);print ind_ex;

};};’>

See Also

• list.first_index() on page 3-34

• list.all_indices() on page 3-70

list A list.

index An integer expression representing an index to the list.

e Libraries Preliminary 3-31

Page 78: Prelim e Lib

List Pseudo-Methods list.field

ts”

3.4.4 list.field

Purpose

Specifying a field from all items in a list

Category

Pseudo-method

Syntax

list.field-name

Syntax example:

s_list.fld_nm

Parameters

Description

Returns a list containing the contents of the specifiedfield-name for each item in thelist. If the list is empty, it returns an empty list. This syntax is the same aslist.apply(field).

Example

The following prints the values of the “length” fields in all the items in the “packelist.

<’struct packet {

length: uint;};extend sys {

packets: list of packet;run() is also {

print packets.length;};

list A list of structs.

field-name A name of a field or list in the struct type.

3-32 Preliminary e Libraries

Page 79: Prelim e Lib

list.first() List Pseudo-Methods

ro

};’>

See Also

• list.apply() on page 3-26

3.4.5 list.first()

Purpose

Get the first item that satisfies a given condition

Category

Pseudo-method

Syntax

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

Syntax example:

var i_item: instr;i_item = instr_list.first(it.op1 > 15);

Parameters

Description

Returns the first item for whichexp is TRUE. If there is no such item, the default forthe item’s type is returned (see “e Data Types” on page 3-2 in theeLanguageReference Manual).

For a list of scalars, a value of zero is returned if there is no such item. Since zemight be confused with a value found, it is safer to uselist.first_index() for lists ofscalars.

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-33

Page 80: Prelim e Lib

List Pseudo-Methods list.first_index()

ints

s

Example 1

The first command below creates a list of five integers. The second command prthe first item in the list smaller than 5 (that is, it prints 3).

var i_list :list of int = {8;3;7;3;4};print i_list.first(it < 5 );

Example 2

In the following example, thelist.first.() pseudo-method is used to make sure all itemin the “packets” list contain non-empty “cells” lists.

<’struct cell {

data: list of byte;};struct packet {

cells: list of cell;};extend sys {

packets: list of packet;run() is also {

check that sys.packets.first(.cells is empty) == NULL;};

};’>

See Also

• list.first_index() on page 3-34

• list.has() on page 3-37

• list.last() on page 3-42

3.4.6 list.first_index()

Purpose

Get the index of the first item that satisfies a given condition

3-34 Preliminary e Libraries

Page 81: Prelim e Lib

list.first_index() List Pseudo-Methods

ts 1,

e

Category

Pseudo-method

Syntax

list.first_index(exp: bool): int

Syntax example:

var i_item: int;i_item = instr_list.first_index(it.op1 > 15);

Parameters

Description

Returns the index of the first item for whichexpis TRUE or return UNDEF if there isno such item.

Example 1

The first command below creates a list of five integers. The second command prinwhich is the index of the first item in the list smaller than 5.

var i_list :list of int = {8;3;7;3};print i_list.first_index(it < 5);

Example 2

In the following example, thelist.first_index.() pseudo-method is used to make surall items in the “packets” list contain non-empty “cells” lists.

<’struct cell {

data: list of byte;};struct packet {

cells: list of cell;};

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-35

Page 82: Prelim e Lib

List Pseudo-Methods list.get_indices()

extend sys {packets: list of packet;run() is also {

check that packets.first_index(.cells is empty) == UNDEF;

};};’>

See Also

• list.first() on page 3-33

• list.has() on page 3-37

• list.last_index() on page 3-44

3.4.7 list.get_indices()

Purpose

Return a sublist of another list

Category

Pseudo-method

Syntax

list.get_indices(index-list: list of int): list-type

Syntax example:

var i_list: list of packet;i_list = packets.get_indices({0; 1; 2});

Parameters

list A list.

index-list A list of indexes within the list. Each index must exist in the list.

3-36 Preliminary e Libraries

Page 83: Prelim e Lib

list.has() List Pseudo-Methods

Description

Copies the items inlist that have the indexes specified inindex-list and returns a newlist containing those items. If theindex-list is empty, an empty list is returned.

Example

The following example puts “green” and “orange” in the list named “o_list”.

var c_list := {"red"; "green"; "blue"; "orange"};var o_list := c_list.get_indices({1;3});

See Also

• list.first_index() on page 3-34

• list.has() on page 3-37

• list.last_index() on page 3-44

• list.all_indices() on page 3-70

3.4.8 list.has()

Purpose

Check that a list has at least one item that satisfies a given condition

Category

Pseudo-method

Syntax

list.has(exp: bool): bool

Syntax example:

var i_ck: bool;i_ck = sys.instr_list.has(it.op1 > 31);

e Libraries Preliminary 3-37

Page 84: Prelim e Lib

List Pseudo-Methods list.has()

e

tains

Parameters

Description

Returns TRUE if thelist contains at least one item for which theexp is TRUE, orreturns FALSE if the expression is not TRUE for any item.

Example 1

The first command below creates a list containing the integers 8, 3, 7, and 3. Thsecond command checks that the list contains 7, and prints TRUE.

var l: list of int = {8;3;7;3};print l.has(it == 7);

The command below checks that there is no packet in the “packets” list that conan empty “cells” list.

<’struct cell {

data: list of byte;};struct packet {

cells: list of cell;};extend sys {

packets: list of packet;run() is also {

check that not sys.packets.has(.cells is empty);};

};’>

See Also

• list.first() on page 3-33

• list.last() on page 3-42

• list.max() on page 3-45

• list.min() on page 3-50

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

3-38 Preliminary e Libraries

Page 85: Prelim e Lib

list.is_a_permutation() List Pseudo-Methods

d tomslist.

• list.all() on page 3-67

3.4.9 list.is_a_permutation()

Purpose

Check that two lists contain exactly the same items

Category

Pseudo-method

Syntax

list_1.is_a_permutation(list_2: list): bool

Syntax example:

var lc: bool;lc = packets_1a.is_a_permutation(packets_1b);

Parameters

Description

Returns TRUE iflist_2 contains the same items aslist_1, or FALSE if any items inone list are not in the other list. The order of the items in the two lists does not neebe the same, but the number of items must be the same for both lists. That is, itethat are repeated in one list must appear the same number of times in the other

Notes

• If the lists are lists of structs,list_1.is_a_permutation(list_2) compares the addressesof the struct items, not their contents.

• This pseudo-method can be used in akeepconstraint to filllist_1with the same itemscontained in thelist_2, although not necessarily in the same order.

list_1 A list.

list_2 A list that is to be compared to list_1. Must be the same type as list_1.

e Libraries Preliminary 3-39

Page 86: Prelim e Lib

List Pseudo-Methods list.is_empty()

ms

Example 1

In the following example, the “l_comp” variable is TRUE because the two listscontain the same items.

<’extend sys {

run() is also {var l_1 := {1;3;5;7;9};var l_2 := {1;9;7;3;5};var l_comp: bool;l_comp = l_1.is_a_permutation(l_2);print l_comp;

};};’>

Example 2

In the following example, thekeep constraint causes the list named “l_2” have thesame items as in the list named “l_1”. Since “l_1” will have the same number of iteas “l_2”, there is an implicit constraint that “l_2” will be the same size at “l_1”. Toconstrain the size of the two lists, you can specify akeep constraint on the size ofeither “l_1” or “l_2”.

<’extend sys {

l_1: list of int;l_2: list of int;keep l_2.is_a_permutation(l_1);

};’>

See Also

• keep on page 10-7 in theeLanguage Reference Manual

• list.has() on page 3-37

3.4.10 list.is_empty()

Purpose

Check if a list is empty

3-40 Preliminary e Libraries

Page 87: Prelim e Lib

list.is_empty() List Pseudo-Methods

Category

Pseudo-method

Syntax

list.is_empty(): bool

Syntax example:

var no_l: bool;no_l = packets.is_empty();

Parameters

Description

Returns TRUE iflist is empty, or FALSE if the list is not empty.

Note

You can use “list is empty” as a synonym for “list.is_empty()”.

Similarly, you can use “list is not empty” to mean “not(list.is_empty())”.

Example 1

In the following example, the firstprint action prints TRUE because the “int_lst” isinitially empty. After an item is added, the secondprint action prints TRUE becausethe list is not empty.

<’extend sys {

int_list: list of int;run() is also {

var emp: bool;emp = int_list.is_empty();print emp;int_list.add(3);emp = int_list is not empty;print emp;

};};

list A list.

e Libraries Preliminary 3-41

Page 88: Prelim e Lib

List Pseudo-Methods list.last()

’>

Example 2

The following gives the same result as the “ck_instr()” method in the previousexample.

ck_instr() is {if int_list is not empty {

print int_list;}else {

outf("list is empty\n");return;

};};

See Also

• list.clear() on page 3-9

• list.exists() on page 3-30

• list.size() on page 3-56

3.4.11 list.last()

Purpose

Get the last item that satisfies a given condition

Category

Pseudo-method

Syntax

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

Syntax example:

var i_item: instr;i_item = sys.instr_list.last(it.op1 > 15);

3-42 Preliminary e Libraries

Page 89: Prelim e Lib

list.last() List Pseudo-Methods

suchthe

ro

The

tains

Parameters

Description

Returns the last item in the list that satisfies the Boolean expression. If there is noitem, the default for the item’s type is returned (see “e Data Types” on page 3-2 ineLanguage Reference Manual).

For a list of scalars, a value of zero is returned if there is no such item. Since zemight be confused with a found value, it is safer to uselist.last_index() for lists ofscalars.

Example 1

The first command below creates a list containing the integers 8, 3, 7, 3, and 4. second command prints 4.

var l :list of int = {8;3;7;3;4};print l.last(it < 5);

Example 2

The command below checks that there is no packet in the “packets” list that conan empty “cells” list.

<’struct cell {

data: list of byte;};struct packet {

cells: list of cell;};extend sys {

packets: list of packet;run() is also {

check that sys.packets.last(.cells is empty) == NULL;};

};’>

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-43

Page 90: Prelim e Lib

List Pseudo-Methods list.last_index()

See Also

• list.first() on page 3-33

• list.has() on page 3-37

• list.last_index() on page 3-44

• list.all() on page 3-67

3.4.12 list.last_index()

Purpose

Get the index of the last item that satisfies a given condition

Category

Pseudo-method

Syntax

list.last_index(exp: bool): int

Syntax example:

var i_item: int;i_item = instr_list.last_index(it.op1 > 15);

Parameters

Description

Returns the index of the last item for whichexp is TRUE, or returns UNDEF if thereis no such item.

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

3-44 Preliminary e Libraries

Page 91: Prelim e Lib

list.max() List Pseudo-Methods

The

ptyss

Example 1

The first command below creates a list containing the integers 8, 3, 7, 3, and 4. second command prints 3.

var l: list of int = {8;3;7;3;4};print l.last_index(it == 3);

Example 2

The command below checks that every packet in the “packets” list has a non-em“cells” list: if the index of the last packet that has a non-empty “cells” list is one lethan the size of the list, the check succeeds.

check thatsys.packets.last_index(.cells is not empty) ==sys.packets.size() - 1;

See Also

• list.first_index() on page 3-34

• list.has() on page 3-37

• list.last() on page 3-42

• list.all_indices() on page 3-70

3.4.13 list.max()

Purpose

Get the item with the maximum value of a given expression

Category

Pseudo-method

Syntax

list.max(exp: int): list-type

e Libraries Preliminary 3-45

Page 92: Prelim e Lib

List Pseudo-Methods list.max()

m

the

Syntax example:

var high_item: item_instance;high_item = item_list.max(it.f_1 + it.f_2);

Parameters

Description

Returns the item for which theexpevaluates to the largest value. If more than one iteresults in the same maximum value, the item latest in the list is returned.

Example

In the example below, the “high_item” variable gets the “instr” instance that has largest value of the sum of “op1” and “op2”.

<’struct instr {

op1: int;op2: int;

};extend sys {

instr_list: list of instr;keep instr_list.size() > 5;run() is also {

var high_item: instr;high_item = instr_list.max(.op1 + .op2);

};};’>

See Also

• list.has() on page 3-37

• list.max_index() on page 3-47

• list.max_value() on page 3-48

• list.min() on page 3-50

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

3-46 Preliminary e Libraries

Page 93: Prelim e Lib

list.max_index() List Pseudo-Methods

the

ce

• list.all() on page 3-67

3.4.14 list.max_index()

Purpose

Get the index of the item with the maximum value of a given expression

Category

Pseudo-method

Syntax

list.max_index(exp: int): int

Syntax example:

var item_index: index;item_index = sys.item_list.max_index(it.f_1 + it.f_2);

Parameters

Description

Returns the index of the item for which theexpevaluates to the largest value. If morethan one item results in the same maximum value, the index of the item latest inlist is returned.

Example

In the example below, the “high_indx” variable gets the index of the “instr” instanthat has the largest value of the sum of “op1” and “op2”.

<’struct instr {

op1: int;op2: int;

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-47

Page 94: Prelim e Lib

List Pseudo-Methods list.max_value()

};extend sys {

instr_list: list of instr;keep instr_list.size() > 5;run() is also {

var high_indx: int;high_indx = instr_list.max_index(.op1 + .op2);

};};’>

See Also

• list.first_index() on page 3-34

• list.has() on page 3-37

• list.last_index() on page 3-44

• list.max() on page 3-45

• list.max_value() on page 3-48

• list.min_index() on page 3-52

• list.all_indices() on page 3-70

3.4.15 list.max_value()

Purpose

Return the maximum value found by evaluating a given expression for all items

Category

Pseudo-method

Syntax

list.max_value(exp: int): (int | uint)

Syntax example:

var item_val: int;

3-48 Preliminary e Libraries

Page 95: Prelim e Lib

list.max_value() List Pseudo-Methods

sion

e

item_val = sys.item_list.max_value(it.f_1 + it.f_2);

Parameters

Description

Returns the largest integer value found by evaluating theexpfor every item in the list.If more than one item results in the same maximum value, the value of the expresfor the item latest in the list is returned.

For lists of integer types, one of the following is returned if thelist is empty:

Example 1

The example below prints the largest absolute value in the list of integers named“i_list”.

<’extend sys {

i_list: list of int;run() is also {

print i_list.max_value(abs(it));};

};’>

Example 2

In the example below, the “high_val” variable gets the “instr” instance that has thlargest value of the sum of “op1” and “op2”.

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

List Item Type Value Returned by list.max_value()

signed integer MIN_INT (see “Predefined Constants” on page 2-6 in theeLanguage Reference Manual)

unsigned integer zero

long integer error

e Libraries Preliminary 3-49

Page 96: Prelim e Lib

List Pseudo-Methods list.min()

<’struct instr {

op1: int;op2: int;

};extend sys {

instr_list: list of instr;keep instr_list.size() < 10;run() is also {

var high_val: int;high_val = instr_list.max_value(.op1 + .op2);print high_val;

};};’>

See Also

• list.has() on page 3-37

• list.max() on page 3-45

• list.max_index() on page 3-47

• list.min_value() on page 3-53

3.4.16 list.min()

Purpose

Get the item with the minimum value of a given expression

Category

Pseudo-method

Syntax

list.min(exp: int): list-type

Syntax example:

var low_item: item_instance;low_item = sys.item_list.min(it.f_1 + it.f_2);

3-50 Preliminary e Libraries

Page 97: Prelim e Lib

list.min() List Pseudo-Methods

e

Parameters

Description

Returns the item for which theexp evaluates to the smallest value. If more than oneitem results in the same minimum value, the item latest in the list is returned.

Example

In the example below, the “low_item” variable gets the “instr” instance that has thsmallest value of the sum of “op1” and “op2”.

<’struct instr {

op1: int;op2: int;

};extend sys {

instr_list: list of instr;keep instr_list.size() < 10;run() is also {

var low_item: instr;low_item = instr_list.min(.op1 + .op2);

};};’>

See Also

• list.first() on page 3-33

• list.has() on page 3-37

• list.last() on page 3-42

• list.max() on page 3-45

• list.min_index() on page 3-52

• list.min_value() on page 3-53

• list.all() on page 3-67

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-51

Page 98: Prelim e Lib

List Pseudo-Methods list.min_index()

st in

e

3.4.17 list.min_index()

Purpose

Get the index of the item with the minimum value of a given expression

Category

Pseudo-method

Syntax

list.min_index(exp: int): int

Syntax example:

var item_index: index;item_index = sys.item_list.min_index(it.f_1 + it.f_2);

Parameters

Description

Return the index of the item for which the specifiedexp gives the minimal value. Ifmore than one item results in the same minimum value, the index of the item latethe list is returned.

Example

In the example below, the “low_indx” variable gets the index of the “instr” instancthat has the smallest value of the sum of “op1” and “op2”.

<’struct instr {

op1: int;op2: int;

};extend sys {

instr_list: list of instr;

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

3-52 Preliminary e Libraries

Page 99: Prelim e Lib

list.min_value() List Pseudo-Methods

keep instr_list.size() < 10;run() is also {

var low_indx: int;low_indx = instr_list.min_index(.op1 + .op2);

};};’>

See Also

• list.first_index() on page 3-34

• list.has() on page 3-37

• list.last_index() on page 3-44

• list.max_index() on page 3-47

• list.min() on page 3-50

• list.min_value() on page 3-53

• list.all_indices() on page 3-70

3.4.18 list.min_value()

Purpose

Return the minimum value found by evaluating a given expression for all items

Category

Pseudo-method

Syntax

list.min_value(exp: int): (int | uint)

Syntax example:

var item_val: int;item_val = sys.item_list.min_value(it.f_1 + it.f_2);

e Libraries Preliminary 3-53

Page 100: Prelim e Lib

List Pseudo-Methods list.min_value()

Parameters

Description

Returns the smallest integer value found by evaluating theexp for every item in thelist. If more than one item results in the same minimum value, the value of theexpression for the item latest in the list is returned.

For lists of integer types, one of the following is returned if thelist is empty:

Example

In the example below, the “low_val” variable gets the “instr” instance that has thesmallest value of the sum of “op1” and “op2”.

<’struct instr {

op1: int;op2: int;

};extend sys {

instr_list: list of instr;keep instr_list.size() < 10;run() is also {

var low_val: int;low_val = instr_list.min_value(.op1 + .op2);print low_val;

};};’>

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

List Item Type Value Returned

signed integer MAX_INT (see “Predefined Constants” on page 2-6 in theeLanguage Reference Manual)

unsigned integer zero

long integer error

3-54 Preliminary e Libraries

Page 101: Prelim e Lib

list.reverse() List Pseudo-Methods

he

See Also

• list.has() on page 3-37

• list.max_value() on page 3-48

• list.min() on page 3-50

• list.min_index() on page 3-52

3.4.19 list.reverse()

Purpose

Reverse the order of a list

Category

Pseudo-method

Syntax

list.reverse(): list

Syntax example:

var s_list := {"A"; "B"; "C"; "D"};var r_list := s_list.reverse();

Parameters

Description

Returns a new list of all the items inlist in reverse order.

Example 1

In the following example the “rlist” variable gets a list that contains all the items in t“packets” list, but in reverse order.

<’

list A list.

e Libraries Preliminary 3-55

Page 102: Prelim e Lib

List Pseudo-Methods list.size()

struct cell {data: list of byte;

};struct packet {

cells: list of cell;};extend sys {

packets: list of packet;r_packets: list of packet;run() is also {

r_packets = sys.packets.reverse();};

};’>

Example 2

The following example prints 2, 1, 2, 4.

var i_list: list of int = {4; 2; 1; 2};var r_list: list of int = i_list.reverse();print r_list;

See Also

• list.sort() on page 3-57

• list.sort_by_field() on page 3-59

3.4.20 list.size()

Purpose

Return the size of a list

Category

Pseudo-method

Syntax

list.size(): int

3-56 Preliminary e Libraries

Page 103: Prelim e Lib

list.sort() List Pseudo-Methods

ed

Syntax example:

print packets.size();

Parameters

Description

Returns an integer equal to the number of items in thelist.

Example

In the following example, the “lsz” variable gets the number of items in the list nam“s_list”.

<’extend sys {

s_list: list of string;keep s_list == {"Aa"; "Ba"; "Cc"};run() is also {

var lsz: int;lsz = sys.s_list.size();print lsz;

};};’>

See Also

• list.resize() on page 3-22

• list.count() on page 3-29

3.4.21 list.sort()

Purpose

Sort a list

list A list.

e Libraries Preliminary 3-57

Page 104: Prelim e Lib

List Pseudo-Methods list.sort()

e

to

Category

Pseudo-method

Syntax

list.sort(exp: expression): list

Syntax example:

var s_list: list of packet;s_list = packets.sort(it.f_1 + it.f_2);

Parameters

Description

Returns a new list of all the items inlist, sorted in increasing order of the values of thexp.

If the exp is a scalar value, the list is sorted by value. If theexp is a nonscalar, the listis sorted by address.

Example 1

The following example prints 1, 2, 2, 4.

var sl: list of int = {4; 2; 1; 2};print sl.sort(it);

Example 2

In the following example, the “slist” variable gets the items in the “packets” list,sorted in increasing value of the product of the “length” and “width” fields.

<’struct packet {

length: uint;width: uint;

};

list A list of integers, strings, enumerated items, or Boolean values to sort.

exp A scalar or nonscalar expression. The expression may contain referencesfields or structs. Theit variable can be used to refer to the current list item.

3-58 Preliminary e Libraries

Page 105: Prelim e Lib

list.sort_by_field() List Pseudo-Methods

d

extend sys {packets: list of packet;run() is also {

var s_list: list of packet;s_list = packets.sort(.length * .width);

};};’>

See Also

• list.reverse() on page 3-55

• list.sort_by_field() on page 3-59

3.4.22 list.sort_by_field()

Purpose

Sort a list of structs by a selected field

Category

Pseudo-method

Syntax

struct-list.sort_by_field(field: field-name): list

Syntax example:

var s_list: list of packet;s_list = sys.packets.sort_by_field(length);

Parameters

struct-list A list of structs.

field The name of a field of the list’s struct type. Enter the name of the fielonly, with no preceding “.” or “it.”.

e Libraries Preliminary 3-59

Page 106: Prelim e Lib

List Pseudo-Methods list.sort_by_field()

Description

Returns a new list of all the items instruct-list, sorted in increasing order of theirfieldvalues.

Note

The list.sort() pseudo-method returns the same value as thelist.sort_by_field()pseudo-method, butlist.sort_by_field() is more efficient.

Example

In the following example, the “sf_list” variable gets the items in the “packets” list,sorted in increasing value of the “ptype” field (first “ATM”, then “ETH”, then“foreign”).

<’type pkt_type: [ATM, ETH, foreign];struct packet {

length: uint;width: uint;ptype: pkt_type;

};extend sys {

packets: list of packet;run() is also {

var sf_list: list of packet;sf_list = packets.sort_by_field(ptype);print sf_list;

};};’>

See Also

• list.reverse() on page 3-55

• list.sort() on page 3-57

3-60 Preliminary e Libraries

Page 107: Prelim e Lib

list.split() List Pseudo-Methods

listt

nd

3.4.23 list.split()

Purpose

Splits a list at each point where an expression is true

Category

Pseudo-method

Syntax

list.split(exp: expression): list, …

Syntax example:

var sl_hold := s_list.split(it.f_1 == 16);

Parameters

Description

Splits the items inlist into separate lists, each containing consecutive items inlistwhich evaluate to the sameexp value.

Sincee does not support lists of lists, this pseudo-method returns a list of typestruct-list-holder. The struct-list-holder type is a struct with a single field, “value: of any-struct;”. A struct-list-holder is a list of structs, with each struct containing a lisof items of the originallist type.

Each struct-list-holder in the returned list contains consecutive items from thelist thathave the sameexp value.

Note

Fields used in the expression must be defined in the base type definition, not inwhensubtypes.

list A list of type struct-list-holder.

exp An expression. Theit variable can be used to refer to the current list item, athe index variable can be used to refer to its index number.

e Libraries Preliminary 3-61

Page 108: Prelim e Lib

List Pseudo-Methods list.split()

st is,

e ofd 5.

Example 1

Suppose “packets” is a list that contains packet instances that have the following“length” values:

3; 5; 5; 7; 7; 7; 5;

The “packets.split(.length)” pseudo-method in the following creates a list of four listby splitting the “packets” list at each point where the “length” value changes, thabetween 3 and 5, between 5 and 7, and between 7 and 5.

<’struct packet {

length: uint;};extend sys {

packets: list of packet;run() is also {

var sl_hold := packets.split(.length);print sl_hold[2].value;print sl_hold.value[4];

};};’>

The struct-list-holder variable “sl_hold” then contains four lists:

3

5, 5

7, 7, 7

5

The “print sl_hold[2].value” action prints the third list, which is the one containingthree items whose “length” values are 7.

Theprint sl_hold.value[4]” action prints the fifth item in the “sl_hold” list, which isthe same as the fifth item in the “packets” list.

Example 2

The following splits the list in the preceding example at each point where the valuthe expression “.length > 5” changes, that is, between 5 and 7 and between 7 an

var sl_hold := sys.packets.split(.length > 5);

3-62 Preliminary e Libraries

Page 109: Prelim e Lib

list.top() List Pseudo-Methods

The struct-list-holder variable “sl_hold” then contains three lists:

3, 5, 5

7, 7, 7

5

Example 3

To sort the list before you split it, you can use the following syntax.

var sl_hold := sys.packets.sort(.length).split(.length);

See Also

• list.get_indices() on page 3-36

• list.has() on page 3-37

• list.all() on page 3-67

3.4.24 list.top()

Purpose

Return the last item in a list

Category

Pseudo-method

Syntax

list.top(): list-item

Syntax example:

var pk: packet;pk = sys.packets.top();

e Libraries Preliminary 3-63

Page 110: Prelim e Lib

List Pseudo-Methods list.top0()

Parameters

Description

Returns the last item in thelist without removing it from the list.

Example

The following example prints the contents of the last packet in the “packets” list.

print sys.packets.top();

See Also

• list.pop() on page 3-17

• list.top0() on page 3-64

3.4.25 list.top0()

Purpose

Return the first item of a list

Category

Pseudo-method

Syntax

list.top0(): list-item

Syntax example:

var pk: packet;pk = sys.packets.top0();

Parameters

list A list.

list A list.

3-64 Preliminary e Libraries

Page 111: Prelim e Lib

list.unique() List Pseudo-Methods

nd

Description

Returns the first item in thelist without removing it from the list.

This pseudo-method can be used withpop0() to emulate queues.

Example

The following example prints the contents of the first packet in the “packets” list.

print sys.packets.top0();

See Also

• list.pop0() on page 3-18

• list.top() on page 3-63

3.4.26 list.unique()

Purpose

Collapse consecutive items that have the same value into one item

Category

Pseudo-method

Syntax

list.unique(exp: expression): list

Syntax example:

var u_list: list of l_item;u_list = sys.l_list.unique(it.f_1);

Parameters

list A list.

exp An expression. Theit variable can be used to refer to the current list item, athe index variable can be used to refer to its index number.

e Libraries Preliminary 3-65

Page 112: Prelim e Lib

List Pseudo-Methods list.unique()

ele

de with, 7,

sthe

Description

Returns a new list of all the distinct values inlist. In the new list, all consecutiveoccurrences of items for which the value ofexp are the same are collapsed into oneitem.

Example 1

In the following example, thelist.unique() pseudo-method collapses the consecutiv5s and the consecutive 7s in “ilist” into a single 5 and a single seven. The exampprints 3, 5, 7, 5.

var i_list := {3; 5; 5; 7; 7; 7; 5};var pl: list of int;pl = i_list.unique(it);print pl;

Example 2

Suppose the “packets” list contains seven packets with the following “length” fielvalues: 3, 5, 5, 7, 7, 7, 5. Thelist.unique() pseudo-method collapses the consecutivpackets with lengths of 5 into a single item, and collapses the consecutive itemslengths of 7 into a single item. The “pl” list gets four packets, with lengths of 3, 5and 5.

var pl: list of packet;pl = packets.unique(.length);

Example 3

In the following example, thelist.unique() pseudo-method removes any packet itemwith repeated “length” values from the “packets” list before the list is sorted usinglist.sort() pseudo-method.

<’struct packet {

length: uint (bits: 8);width: uint (bits: 8);

};extend sys {

packets: list of packet;run() is also {

var s_list: list of packet;

3-66 Preliminary e Libraries

Page 113: Prelim e Lib

Sublist Pseudo-Methods List Pseudo-Methods

ll the

s_list= packets.sort(.length).unique(.length);print s_list;

};};’>

See Also

• list.count() on page 3-29

• list.size() on page 3-56

• list.sort() on page 3-57

• list.sort_by_field() on page 3-59

• list.all() on page 3-67

3.5 Sublist Pseudo-MethodsThis section describes the syntax for pseudo-methods that construct a new list from aitems in another list that satisfy specified conditions.

The pseudo-methods in this section are:

• list.all() on page 3-67

• list.all_indices() on page 3-70

See Also

• “Pseudo-Methods Overview” on page 3-1

• “Using List Pseudo-Methods” on page 3-2

• “Type-Related Constructs” on page 4-25

3.5.1 list.all()

Purpose

Get all items that satisfy a condition

e Libraries Preliminary 3-67

Page 114: Prelim e Lib

List Pseudo-Methods list.all()

re

,

Category

Pseudo-method

Syntax

list.all(exp: bool): list

Syntax example:

var l_2: list of packet;l_2 = sys.packets.all(it.length > 64);

Parameters

Description

Returns a list of all the items inlist for whichexp is TRUE. If no items satisfy theBoolean expression, an empty list is returned.

Example 1

The following example prints 7, 9, 11, since those are the values in “l_list” that agreater than 5.

var l_list: list of int = {1; 3; 5; 7; 9; 11};print l_list.all(it > 5);

Example 2

The following example creates a list named “pl” of all packets that have a “lengthfield value less than 5, and prints the “pl” list.

<’type packet_type: [ETH, ATM];struct packet {

length: uint (bits: 4);ptype: packet_type;

};extend sys {

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current itemand theindex variable can be used to refer to its index number.

3-68 Preliminary e Libraries

Page 115: Prelim e Lib

list.all() List Pseudo-Methods

of

packets: list of packet;run() is also {

var pl: list of packet;pl = packets.all(.length < 5);print pl;

};};’>

Example 3

The following creates a list named “pt” of all packets that have a “ptype” field value“ETH”, and prints the “pt” list. This example uses the “it is a type” syntax to specifywhich subtype of the packet struct to look for.

<’type packet_type: [ETH, ATM];struct packet {

length: uint (bits: 4);ptype: packet_type;

};extend sys {

packets: list of packet;run() is also {

var pt:= packets.all(it is a ETH packet);print pt;

};};’>

See Also

• is [not] a on page 2-71 in theeLanguage Reference Manual

• list.first() on page 3-33

• list.has() on page 3-37

• list.last() on page 3-42

• list.max() on page 3-45

• list.min() on page 3-50

• list.all_indices() on page 3-70

e Libraries Preliminary 3-69

Page 116: Prelim e Lib

List Pseudo-Methods list.all_indices()

f allr

3.5.2 list.all_indices()

Purpose

Get indexes of all items that satisfy a condition

Category

Pseudo-method

Syntax

list.all_indices(exp: bool): list of int

Syntax example:

var l_2: list of int;l_2 = sys.packets.all_indices(it.length > 5);

Parameters

Description

Returns a list of all indexes of items inlist for whichexpis TRUE. If no items satisfythe Boolean expression, an empty list is returned.

Example 1

The following example creates a list name “tl” that contains the index numbers othe “instr” instances in the list named “i_list” which have “op1” field values greatethan 63.

<’type op_code: [ADD, SUB, MLT];struct instr {

op1: int (bits: 8);op2: int;opcode: op_code;

};extend sys {

list A list.

exp A Boolean expression.

3-70 Preliminary e Libraries

Page 117: Prelim e Lib

list.all_indices() List Pseudo-Methods

t

i_list: list of instr;run() is also {

var tl: list of int;tl = i_list.all_indices(it.op1 > 63);print tl;

};};’>

Example 2

In the following example, thelist.all_indices() pseudo-method is used to create a lisnamed “pl” of the indexes of the “packets” list items that are of subtype “smallpacket”.

<’type pkt_type: [small, medium, large];struct packet {

address: byte;ptype: pkt_type;

};extend sys {

packets: list of packet;keep packets.size() == 10;run() is also {

print packets;var pl: list of int;pl = packets.all_indices(it is a small packet);print pl;

};};’>

See Also

• list.first_index() on page 3-34

• list.has() on page 3-37

• list.last_index() on page 3-44

• list.max_index() on page 3-47

• list.min_index() on page 3-52

• list.all() on page 3-67

e Libraries Preliminary 3-71

Page 118: Prelim e Lib

List Pseudo-Methods Math and Logic Pseudo-Methods

ical

3.6 Math and Logic Pseudo-MethodsThis section describes the syntax for pseudo-methods that perform arithmetic or logoperations to compute a value using all items in a list.

The pseudo-methods in this section are:

• list.and_all() on page 3-72

• list.average() on page 3-73

• list.or_all() on page 3-75

• list.product() on page 3-76

• list.sum() on page 3-78

See Also

• “Pseudo-Methods Overview” on page 3-1

• “Using List Pseudo-Methods” on page 3-2

3.6.1 list.and_all()

Purpose

Compute the logical AND of all items

Category

Pseudo-method

Syntax

list.and_all(exp: bool): bool

Syntax example:

var bool_val: bool;bool_val = m_list.and_all(it >= 1);

3-72 Preliminary e Libraries

Page 119: Prelim e Lib

list.average() List Pseudo-Methods

63, it

Parameters

Description

Returns a TRUE if all values of theexp are true, or returns FALSE if theexp is falsefor any item in thelist.

Example

The following command prints TRUE if the “length” field value of all items in the“packets” list is greater than 63. If any packet has a length less than or equal to prints FALSE.

print sys.packets.and_all(it.length > 63);

See Also

• list.average() on page 3-73

• list.or_all() on page 3-75

• list.product() on page 3-76

• list.sum() on page 3-78

3.6.2 list.average()

Purpose

Compute the average of an expression for all items

Category

Pseudo-method

Syntax

list.average(exp: int): int

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-73

Page 120: Prelim e Lib

List Pseudo-Methods list.average()

s

Syntax example:

var list_ave: int;list_ave = sys.item_list.average(it.f_1 * it.f_2);

Parameters

Description

Returns the integer average of theexp computed for all the items in thelist. ReturnsUNDEF if the list is empty.

Example 1

The following example prints 6 ((3 + 5 + 10)/3).

var a_list := {3; 5; 10};print a_list.average(it);

Example 2

The following example prints the average value of the “length” fields for all the itemin the “packets” list.

<’struct packet {

length: uint (bits: 4);width: uint (bits: 4);

};extend sys {

packets: list of packet;run() is also {

print packets.average(it.length);};

};’>

See Also

• list.and_all() on page 3-72

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

3-74 Preliminary e Libraries

Page 121: Prelim e Lib

list.or_all() List Pseudo-Methods

rints

• list.or_all() on page 3-75

• list.product() on page 3-76

• list.sum() on page 3-78

3.6.3 list.or_all()

Purpose

Compute the logical OR of all items

Category

Pseudo-method

Syntax

list.or_all(exp: bool): bool

Syntax example:

var bool_val: bool;bool_val = m_list.or_all(it >= 100);

Parameters

Description

Returns a TRUE if any value of theexpis true, or returns FALSE if theexpis false forevery item in the list. Returns FALSE if the list is empty.

Example

The following command prints TRUE if the “length” field value of any item in the“packets” list is greater than 150. If no packet has a length greater than 150, it pFALSE.

list A list.

exp A Boolean expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-75

Page 122: Prelim e Lib

List Pseudo-Methods list.product()

<’struct packet {

length: uint (bits: 4);width: uint (bits: 4);

};extend sys {

packets: list of packet;run() is also {

print packets.or_all(it.length > 150);};

};’>

See Also

• list.and_all() on page 3-72

• list.average() on page 3-73

• list.product() on page 3-76

• list.sum() on page 3-78

3.6.4 list.product()

Purpose

Compute the product of an expression for all items

Category

Pseudo-method

Syntax

list.product(exp: int): int

Syntax example:

var list_prod: int;list_prod = sys.item_list.product(it.f_1);

3-76 Preliminary e Libraries

Page 123: Prelim e Lib

list.product() List Pseudo-Methods

Parameters

Description

Returns the integer product of theexpcomputed over all the items in thelist. Returns1 if the list is empty.

Example 1

The following example prints 150 (3 * 5 * 10).

var p_list := {3; 5; 10};print p_list.product(it);

Example 2

The following example prints the product of the “mlt” fields in all the items in the“packets” list.

<’struct packet {

mlt: uint (bits: 3);keep mlt > 0;

};extend sys {

packets[5]: list of packet;run() is also {

print packets.product(it.mlt);};

};’>

See Also

• list.and_all() on page 3-72

• list.average() on page 3-73

• list.or_all() on page 3-75

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

e Libraries Preliminary 3-77

Page 124: Prelim e Lib

List Pseudo-Methods list.sum()

• list.sum() on page 3-78

3.6.5 list.sum()

Purpose

Compute the sum of all items

Category

Pseudo-method

Syntax

list.sum(exp: int): int

Syntax example:

var op_sum: int;op_sum = sys.instr_list.sum(.op1);

Parameters

Description

Returns the integer sum of theexpcomputed over all the items in thelist. Returns 0 ifthe list is empty.

Example 1

The following example prints 18 (3 + 5 + 10).

var s_list := {3; 5; 10};print s_list.sum(it);

list A list.

exp An integer expression. Theit variable can be used to refer to the current listitem, and theindex variable can be used to refer to its index number.

3-78 Preliminary e Libraries

Page 125: Prelim e Lib

List CRC Pseudo-Methods List Pseudo-Methods

in

Example 2

The following example prints the sum of the “length” field values for all the itemsthe “packets” list.

<’struct packet {

length: uint (bits: 4);keep length in [1..5];width: uint (bits: 4);keep width in [1..5];

};extend sys {

packets[5]: list of packet;run() is also {

print packets.sum(it.length);};

};’>

See Also

• list.and_all() on page 3-72

• list.average() on page 3-73

• list.or_all() on page 3-75

• list.product() on page 3-76

3.7 List CRC Pseudo-MethodsThis section describes the syntax for pseudo-methods that perform CRC (cyclicredundancy check) functions on lists.

The pseudo-methods in this section are:

• list.crc_8() on page 3-80

• list.crc_32() on page 3-81

• list.crc_32_flip() on page 3-84

See Also

• “Pseudo-Methods Overview” on page 3-1

e Libraries Preliminary 3-79

Page 126: Prelim e Lib

List Pseudo-Methods list.crc_8()

ist

• “Using List Pseudo-Methods” on page 3-2

3.7.1 list.crc_8()

Purpose

Compute the CRC8 of a list of bits or a list of bytes

Category

Pseudo-method

Syntax

list.crc_8(from-byte: int, num-bytes: int): int

Syntax example:

print b_data.crc_8(2,4);

Parameters

Description

Reads thelist byte-by-byte and returns the integer value of the CRC8 function of a lof bits or bytes. Only the least significant byte (LSB) is used in the result.

The CRC is computed starting with thefrom-byte, for num-bytes.

Note

The algorithm for computing CRC8 is specific for the ATM HEC (Header ErrorControl) computation. The code used for HEC is a cyclic code with the followinggenerating polynomial:

x**8 + x**2 + x + 1

list A list of bits or bytes.

from-byte The index number of the starting byte.

num-bytes The number of bytes to use.

3-80 Preliminary e Libraries

Page 127: Prelim e Lib

list.crc_32() List Pseudo-Methods

5 in

Example

In the example below, the “e_crc” variable gets the CRC8 of the bytes 2, 3, 4, andthe list named “b_data”.

<'extend sys { run() is also { var b_data: list of byte =

{0xff;0xaa;0xdd;0xee;0xbb;0xcc}; print b_data.crc_8(2,4); };};'>

See Also

• list.crc_32() on page 3-81

• list.crc_32_flip() on page 3-84

• list.product() on page 3-76

• list.sum() on page 3-78

• pack() on page 4-38

• unpack() on page 4-42

3.7.2 list.crc_32()

Purpose

Compute the CRC32 of a list of bits or a list of bytes

Category

Pseudo-method

Syntax

list.crc_32(from-byte: int, num-bytes: int): int

Syntax example:

e Libraries Preliminary 3-81

Page 128: Prelim e Lib

List Pseudo-Methods list.crc_32()

a

of allken

nce

print b_data.crc_32(2,4);

Parameters

Description

Reads thelist byte-by-byte and returns the integer value of the CRC32 function oflist of bits or bytes. Only the least significant word is used in the result.

The CRC is computed starting with thefrom-byte, for num-bytes.

Note

The algorithm for computing CRC32 generates a two-bit CRC that is used formessages up to 64 kilobytes in length. Such a CRC can detect 99.999999977%errors. The generator polynomial for the 32-bit CRC used for both Ethernet and toring is:

x**32 + x**26 + x**23 + x**22 + x**16 + x**12 + x**11 + x**10 + x**8 +x**7 + x**5 + x**4 +x**2 + x + 1

Example 1

In the example below, the “b_data” variable gets the packed “packet” struct instaas a list of bytes, and the CRC32 of bytes 2, 3, 4, and 5 of “b_data” is printed.

<’struct packet {

%byte_1: byte;%byte_2: byte;%byte_3: byte;%byte_4: byte;%byte_5: byte;%byte_6: byte;

};extend sys {

packet;run() is also {

var b_data: list of byte = pack(NULL, me.packet);print b_data.crc_32(2,4);

list A list of bits or bytes.

from-byte The index number of the starting byte.

num-bytes The number of bytes to use.

3-82 Preliminary e Libraries

Page 129: Prelim e Lib

list.crc_32() List Pseudo-Methods

it

};};’>

Example 2

In the example below, the CRC32 value is calculated for the data field value. The“is_good_crc()” method checks the value and returns TRUE if it is good, FALSE ifis bad.

<’struct packet {

%data: list of byte;!%crc: uint;packed: list of byte;run() is also {

crc = (data.crc_32(0, data.size()) ^ 0xffff_ffff);packed = pack(packing.low, me);

};is_good_crc(): bool is {

result = (packed.crc_32(0, packed.size()) == 0xffff_ffff);

};};extend sys {

packets: list of packet;run() is also {

for each in packets {outf("frame %d ", index);print it.is_good_crc();

};};

};’>

See Also

• list.crc_8() on page 3-80

• list.crc_32_flip() on page 3-84

• list.product() on page 3-76

• list.sum() on page 3-78

• pack() on page 4-38

e Libraries Preliminary 3-83

Page 130: Prelim e Lib

List Pseudo-Methods list.crc_32_flip()

ahe

• unpack() on page 4-42

3.7.3 list.crc_32_flip()

Purpose

Compute the CRC32 of a list of bits or a list of bytes, flipping the bits

Category

Pseudo-method

Syntax

list.crc_32_flip(from-byte: int, num-bytes: int): int

Syntax example:

print b_data.crc_32_flip(2,4);

Parameters

Description

Reads thelist byte-by-byte and returns the integer value of the CRC32 function oflist of bits or bytes, with the bits flipped. Only the least significant word is used in tresult.

The CRC is computed starting with thefrom-byte, for num-bytes.

The bits are flipped as follows:

1. The bits inside each byte of the input are flipped.

2. The bits in the result are flipped.

list A list of bits or bytes.

from-byte The index number of the starting byte.

num-bytes The number of bytes to use.

3-84 Preliminary e Libraries

Page 131: Prelim e Lib

Keyed List Pseudo-Methods List Pseudo-Methods

d 5

d lists.

e aularf

Example

In the example below, the “tc_crc” variable gets the CRC32 of the bytes 2, 3, 4, anin the list named “b_data”, with the bits flipped.

<’struct packet {

%byte_1: byte;%byte_2: byte;%byte_3: byte;%byte_4: byte;%byte_5: byte;%byte_6: byte;

};extend sys {

packet;run() is also {

var b_data: list of byte = pack(NULL, me.packet);print b_data.crc_32_flip(2,4);

};};’>

See Also

• list.crc_8() on page 3-80

• list.crc_32() on page 3-81

• list.product() on page 3-76

• list.sum() on page 3-78

• pack() on page 4-38

• unpack() on page 4-42

3.8 Keyed List Pseudo-MethodsThis section describes the syntax for pseudo-methods that can be used only on keye

Keyed lists are list in which each item has a key associated with it. The key must havunique value for each item. For a list of structs, the key typically is the name of a particfield in each struct. Each unique value for that field may be used as a key. For a list oscalars, the key can be theit variable referring to each item.

e Libraries Preliminary 3-85

Page 132: Prelim e Lib

List Pseudo-Methods list.key()

lists.

Keyed lists can be searched quickly, by searching on a key value.

This section contains descriptions of pseudo-methods that can only be used for keyed

The pseudo-methods in this section are:

• list.key() on page 3-86

• list.key_index() on page 3-87

• list.key_exists() on page 3-89

See Also

• “Pseudo-Methods Overview” on page 3-1

• “Using List Pseudo-Methods” on page 3-2

3.8.1 list.key()

Purpose

Get the item that has a particular key

Category

Pseudo-method

Syntax

list.key(key-exp: expression): list-item

Syntax example:

var loc_list_item: location;var i_key: uint;i_key = 5;loc_list_item = locations.key(i_key);

Parameters

list A keyed list.

key-exp The key of the item that is to be returned.

3-86 Preliminary e Libraries

Page 133: Prelim e Lib

list.key_index() List Pseudo-Methods

sts

roalar

is

Description

Returns the list item that has the specified key, or NULL if no item with that key exiin the list.

For a list of scalars, a value of zero is returned if there is no such item. Since zemight be confused with a found value, it is not advisable to use zero as a key for sclists.

Example 1

The following example uses a list of integers for which the key is the item itself. Thexample prints 5.

var l_list: list(key: it) of int = {5; 4; 3; 2; 1};print l_list.key(5);

See Also

• list.key_index() on page 3-87

• list.key_exists() on page 3-89

3.8.2 list.key_index()

Purpose

Get the index of an item that has a particular key

Category

Pseudo-method

Syntax

list.key_index(key-exp: expression): int

Syntax example:

var loc_list_ix: int;loc_list_ix = locations.key_index(i);

e Libraries Preliminary 3-87

Page 134: Prelim e Lib

List Pseudo-Methods list.key_index()

F if

is

ess.

Parameters

Description

Returns the integer index of the item that has the specified key, or returns UNDEno item with that key exists in the list.

Example 1

The following example uses a list of integers for which the key is the item itself. Thexample prints 1, since that is the index of the list item with a value of 2.

var l_list: list(key: it) of int = {1; 2; 3; 4; 5};print l_list.key_index(2);

Example 2

The locations.key_index()pseudo-method in the following gets the index of the itemin the “locations” list that has an address of 9, if any item in the list has that addr

<’struct location {

address: int;value: int;

};extend sys {

!locations: list(key: address) of location;run() is also {

var l_ix: int;l_ix = locations.key_index(9);if l_ix != UNDEF {print locations[l_ix].value}

else {outf("key_index %d does not exist\n", 9)};};

};’>

See Also

• list.key() on page 3-86

• list.key_exists() on page 3-89

list A keyed list.

key-exp The key of the item for which the index is to be returned.

3-88 Preliminary e Libraries

Page 135: Prelim e Lib

list.key_exists() List Pseudo-Methods

he

3.8.3 list.key_exists()

Purpose

Check that a particular key is in a list

Category

Pseudo-method

Syntax

list.key_exists(key-exp: expression): bool

Syntax example:

var loc_list_k: bool;var i:= 5;loc_list_k = locations.key_exists(i);

Parameters

Description

Returns TRUE if the key exists in the list, or FALSE if it does not.

Example 1

The following example uses a list of integers for which the key is the item itself. Tfirst print action prints TRUE, since 2 exists in the list. The secondprint action printsFALSE, since 7 does not exist in the list.

var l_list: list(key: it) of int = {1; 2; 3; 4; 5};print l_list.key_exists(2);print l_list.key_exists(7);

list A keyed list.

key The key that is to be searched for.

e Libraries Preliminary 3-89

Page 136: Prelim e Lib

List Pseudo-Methods Restrictions on Keyed Lists

of

wed

Example 2

The locations.key_exists()pseudo-method in the following example returns TRUE t“k” if there is an item in the “locations” list that has a key value of 30, or FALSE ithere is no such item.

<’struct location {

address: int;value: int;

};extend sys {

!locations: list(key: address) of location;run() is also {

var k: bool;k = locations.key_exists(30);if k {outf("key %d exists\n", 30)}

else {outf("key %d does not exist\n", 30)};};

};’>

See Also

• list.key() on page 3-86

• list.key_index() on page 3-87

3.9 Restrictions on Keyed Lists• The following pseudo-methods cannot be used on keyed lists:

• list.resize()

• list.apply()

• list.field

• Keyed lists and regular (unkeyed) lists are different types. Assignment is not allobetween a keyed list and a regular list.

3-90 Preliminary e Libraries

Page 137: Prelim e Lib

cs

4 Predefined Routines

Predefined routines areemacros that look like methods. The distinguishing characteristiof predefined routines are:

• They are not associated with any particular struct

• They share the same name space for user-defined routines andglobal methods

• They cannot be modified or extended with theis only, is also or is first constructs

4.1 Predefined Routines OverviewThe following sections describe the predefined routines:

• “Deep Copy and Compare Routines” on page 4-2

• “Arithmetic Routines” on page 4-12

• “Bitwise Routines” on page 4-23

• “Type-Related Constructs” on page 4-25

• “Unit-Related Predefined Routines” on page 4-36

• “String Routines” on page 4-57

• “Output Routines” on page 4-84

• “OS Interface Routines” on page 4-88

e Libraries Preliminary 4-1

Page 138: Prelim e Lib

Predefined Routines Deep Copy and Compare Routines

nd

• “File Routines” on page 4-96

• “Calling Predefined Routines” on page 4-141

See Also

• “Invoking Methods” on page 6-18 in theeLanguage Reference Manual

• Chapter 2, “Predefined Methods”

4.2 Deep Copy and Compare RoutinesThe following routines perform recursive copies and comparisons of nested structs alists:

• deep_copy() on page 4-2

• deep_compare() on page 4-5

• deep_compare_physical() on page 4-10

4.2.1 deep_copy()

Purpose

Make a recursive copy of a struct and its descendants

Category

Predefined routine

Syntax

deep_copy(struct-exp): struct-type

Syntax example:

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

Parameters

struct-exp An expression that returns a struct instance.

4-2 Preliminary e Libraries

Page 139: Prelim e Lib

deep_copy() Predefined Routines

by

ce.

eld

Description

Returns a deep, recursive copy of the struct instance. This routine descendsrecursively through the fields of a struct and its descendants, copying each field value, copying it by reference, or ignoring it, depending on thedeep_copy attributeset for that field.

The return type ofdeep_copy()is the same as the declared type of the struct instan

The following table details how the copy is made, depending on the type of the fiand thedeep_copy attribute (normal, reference, ignore) set for that field. For anexample of how field attributes affectdeep_copy(), seeattribute field on page 4-22in theeLanguage Reference Manual.

Field Type/Attribute Normal Reference Ignore

scalar The new field holds acopy of the originalvalue.

The new field holds acopy of the originalvalue.

The new fieldholds a copy ofthe originalvalue.

string The new field holds acopy of the originalvalue.

The new field holds acopy of the originalvalue.

The new fieldholds a copy ofthe originalvalue.

scalar list A new list is allocatedwith the same sizeand same elements asthe original list.

The new list fieldholds a copy of the

original list pointer.1

A new list isallocated withzero size.

struct A new struct instancewith the same type asthe original struct isallocated. Each fieldis copied or ignored,depending on itsdeep_copy attribute.

The new struct fieldholds a pointer to the

original struct.1

A new structinstance isallocated and it isNULL.

e Libraries Preliminary 4-3

Page 140: Prelim e Lib

Predefined Routines deep_copy()

the

is

eis

seans deep

r

ces

Notes

• A deep copy of a scalar field (numeric, Boolean, enumerated) or a string field is same as a shallow copy performed by a call tocopy().

• A struct or list is duplicated no more than once during a single call todeep_copy().

If there is more than one reference to a struct or list instance, and that instance duplicated by the call todeep_copy(), every field that referred to the original instanceis updated to point to the new instance.

• Thecopy() method of the struct is called bydeep_copy().

The struct’scopy() method is called before its descendants are deep copied. If thdefaultcopy() method is overwritten or extended, this new version of the method used.

• You should apply thereference attribute to fields that store shared data and to fieldthat are backpointers (pointers to the parent struct). Shared data in this context mdata shared between objects inside the deep copy graph and objects outside the

list of structs A new list is allocatedwith the same numberof elements as theoriginal list.

New struct instancesare also allocated andeach field in eachstruct is copied orignored, dependingon itsdeep_copyattribute.

The new list fieldholds a copy of the

original list pointer.1

A new list isallocated withzero size.

1. If the list or struct that is pointed to is duplicated (possibly because anothefield with a normal attribute is also pointing to it) the pointer in this field isupdated to point to the new instance. This duplication applies only to instanduplicated by thedeep_copy() itself, and not duplications made by theextended/overriddencopy() method.

Field Type/Attribute Normal Reference Ignore

4-4 Preliminary e Libraries

Page 141: Prelim e Lib

deep_compare() Predefined Routines

rsinges are

copy graph. A deep copy graph is the imaginary directed graph created by travethe structs and lists duplicated, where its nodes are the structs or lists, and its edgdeep references to other structs or lists.

Example

<'struct packet { header: header; data[10]: list of byte; protocol: [ATM, ETH, IEEE];};struct header { code: uint;};extend sys { pmi: packet; m1() is { var pmv: packet = deep_copy(sys.pmi); pmv.data[0] = 0xff; pmv.header.code = 0xaa; pmv.protocol = IEEE; print pmi.data[0], pmi.header.code, pmi.protocol; print pmv.data[0], pmv.header.code, pmv.protocol; };};'>

See Also

• copy() on page 2-5

• deep_compare() on page 4-5

• deep_compare_physical() on page 4-10

• attribute field on page 4-22 in theeLanguage Reference Manual

4.2.2 deep_compare()

Purpose

Perform a recursive comparison of two struct instances

e Libraries Preliminary 4-5

Page 142: Prelim e Lib

Predefined Routines deep_compare()

theuct

elds

UE.

s are

is thehere

cts or

u

Category

Predefined routine

Syntax

deep_compare(inst1: base-struct, inst2: base-struct, max-diffs: int): list of string

Syntax example:

var diff: list of string = deep_compare(pmi[0], pmi[1], 100);

Parameters

Description

Returns a list of strings, where each string describes a single difference betweentwo struct instances. This routine descends recursively through the fields of a strand its descendants, comparing each field or ignoring it, depending on thedeep_compare attribute set for that field.

The two struct instances are “deep equal” if the returned list is empty.

“Deep equal” is defined as follows:

• Two struct instances are deep equal if they are of the same type and all their fiare deep equal.

• Two scalar fields are deep equal if an equality operation applied to them is TR

• Two list instances are deep equal is they are of the same size and all their itemdeep equal.

Topology is taken into account. If two non-scalar instances are not in the samelocation in the deep compare graphs, they are not equal. A deep compare graphimaginary directed graph created by traversing the structs and lists compared, wits nodes are the structs or lists, and its edges are deep references to other strulists.

inst1, inst2 An expression returning a struct instance.

max-diffs An integer representing the maximum number of differences yowant reported.

4-6 Preliminary e Libraries

Page 143: Prelim e Lib

deep_compare() Predefined Routines

e of

The following table details the differences that are reported, depending on the typthe field and thedeep_compare attribute (normal, reference, ignore) set for thatfield. For an example of how field attributes affect deep_copy(), seeattribute field onpage 4-22 in theeLanguage Reference Manual.

Field Type/Attribute Normal Reference Ignore

scalar Their values, ifdifferent, arereported.

Their values, ifdifferent, arereported.

The fields are notcompared.

string Their values, ifdifferent, arereported.

Their values, ifdifferent, arereported.

The fields are notcompared.

scalar list Their sizes, ifdifferent, arereported. All items inthe smaller list arecompared to those inthe longer list andtheir differences arereported.

The fields are equal iftheir addresses are thesame. The items arenot compared.

The fields are notcompared.

struct If two structs are notof the same type, theirtype difference isreported. Also, anydifferences incommon fields is

reported.1

If two structs are ofthe same type, everyfield difference isreported.

The fields are equal ifthey point to the same

struct instance.2

If the fields do notpoint to the sameinstance, only theaddresses arereported as different;the data is notcompared.

The fields are notcompared and nodifferences forthem or theirdescendants arereported.

e Libraries Preliminary 4-7

Page 144: Prelim e Lib

Predefined Routines deep_compare()

e, ifhe

al

e

p

Difference String Format

The difference string is in the following format:

Differences between <inst1-id> and <inst2-id>---------------------------------------------<path>: <inst1-value> != <inst2-value>

list of structs Their sizes, ifdifferent, arereported. All structsin the smaller list aredeep compared tothose in the longer listand their differencesare reported.

The fields are equal iftheir addresses are thesame and they pointto the same struct

instance.2

The fields are notcompared and nodifferences forthem or theirdescendants arereported.

1. Two fields are considered common only if the two structs are the same typthey are both subtypes of the same base type, or if one is a base type of tother.

2. If the reference points inside the deep compare graph, a limited topologicequivalence check is performed, not just an address comparison.

path A list of field names separated by periods (.) from (and not including) thstruct instances being compared to the field with the difference.

value For scalar field differences,value is the result ofout(field).

For struct field type differences,type() is appended to the path andvalueis the result ofout(field.type()).

For list field size differences,size()is appended to the path andvalueis theresult ofout(field.size()).

For a shallow comparison of struct fields that point outside the deepcompare graph,value is the struct address.

For a comparison of struct fields that point to different locations in the deecompare graphs (topological difference),valueis struct# appended to anindex representing its location in the deep compare graph.

Field Type/Attribute Normal Reference Ignore

4-8 Preliminary e Libraries

Page 145: Prelim e Lib

deep_compare() Predefined Routines

more

d

Note

The same two struct instances or the same two list instances are not compared than once during a single call todeep_compare().

Example

This example usesdeep_compare() to show the differences between copying nestestructs by reference (withcopy()) and copying nested structs by allocation (withdeep_copy()).

<'struct a {

x: byte;};struct b {

as: list of a;keep as.size() in [2 .. 3];

};struct c {

bs: list of b;keep bs.size() in [2 .. 3];

print() is {var idx: uint;for each b (b) in bs {

idx = index;for each a (a) in b.as {

out ("b[",idx,"] - a[",index,"] : ",hex(bs[idx].as[index].x));

};};

};};

extend sys {c1: c;run() is also {

var c2: c = new;var c3: c = new;

out("C1:");c1.print();

// copy by allocation

out("C2:");

e Libraries Preliminary 4-9

Page 146: Prelim e Lib

Predefined Routines deep_compare_physical()

c2 = deep_copy(c1);c2.print();print deep_compare(c1,c2,20);

// copy by reference

out("C3:");c3 = c1.copy();c3.print();print deep_compare(c1,c3,20);

// demonstrate difference - change original

out("Change C1:");c1.bs[0].as[0].x = 0;c1.print();print deep_compare(c1,c2,20);print deep_compare(c1,c3,20);

};};'>

See Also

• deep_compare_physical() on page 4-10

• deep_copy() on page 4-2

• attribute field on page 4-22 in theeLanguage Reference Manual

4.2.3 deep_compare_physical()

Purpose

Perform a recursive comparison of the physical fields of two struct instances

Category

Predefined routine

Syntax

deep_compare_physical(inst1: base-struct, inst2: base-struct, max-diffs: int): list ofstring

4-10 Preliminary e Libraries

Page 147: Prelim e Lib

deep_compare_physical() Predefined Routines

theuctfield

u

Syntax example:

var diff: list of string = deep_compare_physical(pmi[0],pmi[1], 100);

Parameters

Description

Returns a list of strings, where each string describes a single difference betweentwo struct instances. This routine descends recursively through the fields of a strand its descendants, ignoring all non-physical fields and comparing each physicalor ignoring it, depending on thedeep_compare_physical attribute set for that field.

This routine is the same as thedeep_compare() routine except that only physicalfields (indicated with the % operator prefixed to the field name) are compared.

Example

<'struct packet { %header: header; %data[10] :list of byte; protocol: [ATM, ETH, IEEE];};struct header { %code: uint;};extend sys { pmi[2]: list of packet; run() is also { var diff: list of string = deep_compare_physical(pmi[0],

pmi[1], 100); if (diff.size() != 0) { out(diff); }; };};'>

inst1, inst2 An expression returning a struct instance.

max-diffs An integer representing the maximum number of differences yowant reported.

e Libraries Preliminary 4-11

Page 148: Prelim e Lib

Predefined Routines Arithmetic Routines

See Also

• deep_compare() on page 4-5

• deep_copy() on page 4-2

• attribute field on page 4-22 in theeLanguage Reference Manual

4.3 Arithmetic RoutinesThe following sections describe the predefined arithmetic routines ine:

• min() on page 4-12

• max() on page 4-14

• abs() on page 4-15

• odd() on page 4-16

• even() on page 4-17

• ilog2() on page 4-18

• ilog10() on page 4-19

• ipow() on page 4-20

• isqrt() on page 4-21

• div_round_up() on page 4-22

• bitwise_op() on page 4-23

See Also

• “Predefined Routines Overview” on page 4-1

4.3.1 min()

Purpose

Get the minimum of two values

4-12 Preliminary e Libraries

Page 149: Prelim e Lib

min() Predefined Routines

Category

Routine

Syntax

min(x: int, y: int): int

Syntax example:

print min((x + 5), y);

Parameters

Description

Returns the smaller of the two integer values.

Example

<'extend sys {

m1() is {var x:int = 5;var y: int = 123;print min((x + 5), y);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

• “Predefined Routines Overview” on page 4-1

x An integer expression.

y An integer expression.

e Libraries Preliminary 4-13

Page 150: Prelim e Lib

Predefined Routines max()

4.3.2 max()

Purpose

Get the maximum of two values

Category

Routine

Syntax

max(x: int, y: int): int

Syntax example:

print max((x + 5), y);

Parameters

Description

Returns the larger of the two integer values.

Example

<'extend sys {

m1() is {var x:int = 5;var y: int = 123;print max((x + 5), y);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

x An integer expression.

y An integer expression.

4-14 Preliminary e Libraries

Page 151: Prelim e Lib

abs() Predefined Routines

• “Predefined Routines Overview” on page 4-1

4.3.3 abs()

Purpose

Get the absolute value

Category

Routine

Syntax

abs(x: int): int

Syntax example:

print abs(x);

Parameter

Description

Returns the absolute value of the expression.

Example

<'extend sys {

m1() is {var x: int = -5;print abs(x);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

x An integer expression.

e Libraries Preliminary 4-15

Page 152: Prelim e Lib

Predefined Routines odd()

• “Predefined Routines Overview” on page 4-1

4.3.4 odd()

Purpose

Check if an integer is odd

Category

Routine

Syntax

odd(x: int): bool

Syntax example:

print odd(x);

Parameter

Description

Returns TRUE if the integer is odd, FALSE if the integer is even.

Example

<'extend sys {

m1() is {var x: int = -5;print odd(x);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

x An integer expression.

4-16 Preliminary e Libraries

Page 153: Prelim e Lib

even() Predefined Routines

• “Predefined Routines Overview” on page 4-1

4.3.5 even()

Purpose

Check if an integer is even

Category

Routine

Syntax

even(x: int): bool

Syntax example:

print even(x);

Parameter

Description

Returns TRUE if the integer passed to it is even, FALSE if the integer is odd.

Example

<'extend sys {

m1() is {var x: int = -5;print even(x);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

x An integer expression.

e Libraries Preliminary 4-17

Page 154: Prelim e Lib

Predefined Routines ilog2()

• “Predefined Routines Overview” on page 4-1

4.3.6 ilog2()

Purpose

Get the base-2 logarithm

Category

Routine

Syntax

ilog2(x: uint): int

Syntax example:

print ilog2(x);

Parameter

Description

Returns the integer part of the base-2 logarithm of x.

Example

<'extend sys {

m1() is {var x: int = 1034;print ilog2(x);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

x An unsigned integer expression.

4-18 Preliminary e Libraries

Page 155: Prelim e Lib

ilog10() Predefined Routines

• “Predefined Routines Overview” on page 4-1

4.3.7 ilog10()

Purpose

Get the base-10 logarithm

Category

Routine

Syntax

ilog10(x: uint): int

Syntax example:

print ilog10(x);

Parameter

Description

Returns the integer part of the base-10 logarithm of x.

Example

<'extend sys {

m1() is {var x: int = 1034;print ilog10(x);

};};'>

See Also

• “Arithmetic Routines” on page 4-12

x An unsigned integer expression.

e Libraries Preliminary 4-19

Page 156: Prelim e Lib

Predefined Routines ipow()

• “Predefined Routines Overview” on page 4-1

4.3.8 ipow()

Purpose

Raise to a power

Category

Routine

Syntax

ipow(x: int, y: int): int

Syntax example:

print ipow(x, y);

Parameters

Description

Raises x to the power of y and returns the integer result.

Example

<'extend sys {

m1() is {var x: int = 4;var y: int = 3;print ipow(x, y);

};};'>

x An integer expression.

y An integer expression.

4-20 Preliminary e Libraries

Page 157: Prelim e Lib

isqrt() Predefined Routines

See Also

• “Arithmetic Routines” on page 4-12

• “Predefined Routines Overview” on page 4-1

4.3.9 isqrt()

Purpose

Get the square root

Category

Routine

Syntax

isqrt(x: uint): int

Syntax example:

print isqrt(x);

Parameter

Description

Returns the integer part of the square root of x.

Example

<'extend sys {

m1() is {var x: int = 67;print isqrt(x);

};};'>

x An unsigned integer expression.

e Libraries Preliminary 4-21

Page 158: Prelim e Lib

Predefined Routines div_round_up()

See Also

• “Arithmetic Routines” on page 4-12

• “Predefined Routines Overview” on page 4-1

4.3.10 div_round_up()

Purpose

Division rounded up

Category

Routine

Syntax

div_round_up(x: int, y: int): int

Syntax example:

print div_round_up(x, y);

Parameters

Description

Returns the result of x / y rounded up to the next integer.

Example

<'extend sys {

m1() is {var x: int = 5;var y: int = 2;print div_round_up(x, y);

};

x An integer expression. to use as the dividend.

y An integer expression to use as the divisor.

4-22 Preliminary e Libraries

Page 159: Prelim e Lib

Bitwise Routines Predefined Routines

l

};'>

See Also

• “Arithmetic Routines” on page 4-12

• “Predefined Routines Overview” on page 4-1

• “/” arithmetic operator in+ - * / % on page 2-43 in theeLanguage Reference Manua

4.4 Bitwise RoutinesThe predefined bitwise routines perform Boolean operations bit-by-bit and return asingle-bit result.

See Also

• “Predefined Routines Overview” on page 4-1

4.4.1 bitwise_op()

Purpose

Perform a Verilog-style unary reduction operation

Category

Pseudo-method

Syntax

exp.bitwise_op(exp: int|uint): bit

Syntax example:

print bitwise_and(b);

e Libraries Preliminary 4-23

Page 160: Prelim e Lib

Predefined Routines bitwise_op()

ce a

gers.

Parameters

Description

Performs a Verilog-style unary reduction operation on a single operand to produsingle bit result.

Table 4-1 shows the predefined pseudo-methods for bitwise operations.

Note

These routines cannot be used to perform bitwise operations on unbounded inte

Example 1

<'struct nums { m1() is { var b: uint = 0xffffffff; print bitwise_and(b); print bitwise_nand(b); };};

extend sys { pmi:nums;

exp A 32-bit numeric expression.

op One ofand, or, xor, nand, nor, xnor.

Table 4-1 Bitwise Operation Pseudo-Methods

Pseudo-Method Operation

bitwise_and() Boolean AND of all bits

bitwise_or() Boolean OR of all bits

bitwise_xor() Boolean XOR of all bits

bitwise_nand() !bitwise_and()

bitwise_nor() !bitwise_or()

bitwise_xnor() !bitwise_xor()

4-24 Preliminary e Libraries

Page 161: Prelim e Lib

Type-Related Constructs Predefined Routines

};'>

See Also

• “Arithmetic Routines” on page 4-12

4.5 Type-Related ConstructsThis section contains:

• as_a() on page 4-25

• all_values() on page 4-35

4.5.1 as_a()

Purpose

Casting operator

Category

Expression

Syntax

exp.as_a(type): type

Syntax example:

print (b).as_a(uint);

Parameters

exp Any eexpression.

type Any legale type.

e Libraries Preliminary 4-25

Page 162: Prelim e Lib

Predefined Routines as_a()

type

e

s the

itly

.

s.

Description

Converts an expression into the specified type. Althoughe supports some automaticcasting, (see “Automatic Type Casting” on page 3-22 in theeLanguage ReferenceManual), explicit casting is required in some cases when making assignmentsbetween different but compatible types.

Type Conversion Between Scalars and Lists of Scalars

Numeric expressions (unsigned and signed integers) of any size are automaticallycast upon assignment to different numeric types.

For other scalars and lists of scalars, there are a number of ways to perform typconversion, including theas_a() method, thepack() method, the%{} bitconcatenation operator and various string routines. Table 4-2 on page 4-26 showrecommended methods for converting between scalars and lists of scalars.

In Table 4-2 on page 4-26,int representsint /uint of any size, including bit, byte, andany user-created size. If a solution is specific to bit or byte, then bit or byte is explicstated.

int(bits:x) meansx as any constant; variables cannot be used as the integer width

The solutions assume that there is a variables declared as

var int : int ;var bool : bool ;var enum : enum ;var list_of_bit : list of bit ;var list_of_byte : list of byte ;var list_of_int : list of int ;

Any conversions not explicitly shown may have to be accomplished in two stage

Table 4-2 Type Conversion Between Scalars and Lists of Scalars

From To Solutions

int list of bit list_of_bit = int[..]

int list of int list_of_int =%{ int}

list_of_int =pack(packing.low, int)

(LSB of int goes to list[0] for either choice)

4-26 Preliminary e Libraries

Page 163: Prelim e Lib

as_a() Predefined Routines

list of bit

list of byte

int int = list_of_bit[:]

list of int int int = pack(packing.low, list_of_int)

(or packing.high for list in other order)

int(bits:x) int(bits:y) intx = inty

(truncation or extension is automatic)

intx.as_a(int(bits:y))

bool int int = bool.as_a(int)

(TRUE becomes 1, FALSE becomes 0)

int bool bool = int.as_a(bool)

(0 becomes FALSE, non-0 becomes TRUE)

int enum enum = int.as_a(enum)

(no checking is performed to make sure the int value isvalid for the range of enum)

enum int int = enum.as_a(int)

(truncation is automatic)

list ofint(bits:x)

list ofint(bits:y)

listx.as_a(list of int(bits:y))

(same number of items, each padded or truncated)

listy = pack(packing.low, listx)

(concatenated data, different number of items)

Table 4-2 Type Conversion Between Scalars and Lists of Scalars

From To Solutions

e Libraries Preliminary 4-27

Page 164: Prelim e Lib

Predefined Routines as_a()

rs or

how

itly

.

s.

Type Conversion Between Strings and Scalars or Lists of Scalars

There are a number of ways to perform type conversion between strings and scalalists of scalars, including theas_a() method, thepack() method, the%{} bitconcatenation operator and various string routines. Table 4-3 on page 4-28 showsto convert between strings and scalars or lists of scalars.

In Table 4-3 on page 4-28,int representsint /uint of any size, including bit, byte, andany user-created size. If a solution is specific to bit or byte, then bit or byte is explicstated.

int(bits:x) meansx as any constant; variables cannot be used as the integer width

The solutions assume that there is a variables declared as

var int : int ;var list_of_byte : list of byte ;var list_of_int : list of int ;var bool : bool ;var enum : enum ;var string : string ;

Any conversions not explicitly shown may have to be accomplished in two stage

Table 4-3 Type Conversion Between Strings and Scalars or Lists of Scalars

From ToASCIIConvert ? Solutions

list of byte string yes list_of_byte.as_a(string)

(byte[0] represents left-most character)

string list of byte yes string.as_a(list of byte)

(left-most character becomes byte[0])

string list of int yes list_of_int =pack(packing.low, string)

list_of_int =%{ string}

(any pack option gives same result; nullbyte, 00, will be last item in list)

4-28 Preliminary e Libraries

Page 165: Prelim e Lib

as_a() Predefined Routines

youut

Type Conversion Between Structs, Struct Subtypes, and Lists of Structs

Struct subtypes are automatically cast to their base struct type, so, for example,can assign a variable of type “Ethernet packet” to a variable of type “packet” withousingas_a().

string int yes int =%{ string}

int = pack(packing.low, string)

(any pack option gives same result)

int string yes unpack(packing.low, %{8’b0, int},string)

(any pack option withscalar_reorder={} gives same result)

string bool no bool =(string == "TRUE")

bool string no string =append(bool)

string enum no enum = string.as_a(enum)

enum string no string = enum.as_a(string)

string int no string.as_a(int)(convert to decimal)

append(“0b”, string).as_a(int)(convert to binary)

append(“0x”, string).as_a(int)(convert to hexadecimal)

int string no append(int)(convert int according to current printradix)

dec(int), hex(int), bin(int)(convert int according to specific radix)

Table 4-3 Type Conversion Between Strings and Scalars or Lists of Scalars

From ToASCIIConvert ? Solutions

e Libraries Preliminary 4-29

Page 166: Prelim e Lib

Predefined Routines as_a()

pe

nf the

pe.

32.

eric

en

You can useas_a() to cast a base struct type to one of its subtypes; if a mismatchoccurs, then NULL is assigned. For example, the “print pkt.as_a(foreign packet)”action results in “pkt.as_a(foreign packet) = NULL” if pkt is not a foreign packet.

When the expression to be converted is a list of structs,as_a() returns a new list ofitems whose type matches the specified type parameter. If no items match the typarameter, an empty list is returned.

The list can contain items of various subtypes, but all items must have a commoparent type. That is, the specified type parameter must be a subtype of the type olist.

Assigning a struct subtype to a base struct type does not change the declared tyThus, you have to useas_a() to cast the base struct type as the subtype in order toaccess any of the subtype-specific struct members. See “Example 5” on page 4-

Subtypes created throughlike inheritance exhibit the same behavior as subtypescreated throughwhen inheritance.

Notes

• Casting between strings and Booleans usingas_a()causes an error.

• No checking is performed when casting between an enumerated type and a numtype to make sure the value is valid.

• Casting an enumerated type or a numeric type to a string usingas_a()is not supported.

Example 1

In this example, the most significant bits of the 32-bit variable “i” are truncated wh“i” is printed as a 16-bit variable. When “i” is printed as a 64-bit variable, it issign-extended to fit.

extend sys {m() is {

var i : int = 0xffff000f;print (i).as_a(int(bits:16));print (i).as_a(int(bits:64));

};};

4-30 Preliminary e Libraries

Page 167: Prelim e Lib

as_a() Predefined Routines

l,not

Example 2

No checking is performed when “c”, a variable of type color, is assigned a valueoutside its range. However, a message is issued when the “c” is accessed by theprintstatement.

type color: [red=2, blue=0, yellow=1];extend sys{

m() is {var c : color = blue;var i : int = 2;var u : uint = 0x74786574;print (i).as_a(color);print (c).as_a(int);c = u.as_a(color); --no checkingprint c; --message issued

};};

Example 3

You can use theas_a() method to convert a Boolean type to a numeric or anenumerated type or from one of those types to a Boolean.

Casting between strings and Booleans withas_a() causes an error.

type color: [red=2, blue=0, yellow=1];extend sys{

m() is {var c : color = blue;var i : int = 2;var s : string = "hello";print (i).as_a(bool);print (c).as_a(bool);print (s).as_a(color); --error message

};};

Example 4

You can useas_a()to convert a string to a numeric if the string holds a numeric literaas in the “print (s1).as_a(int)” action below. Casting a numeric type to a string is supported.

type color: [red=2, blue=0, yellow=1];extend sys{

e Libraries Preliminary 4-31

Page 168: Prelim e Lib

Predefined Routines as_a()

se

m() is {var c : color = blue;var i : int = 2;var s1 : string = "3";var s2 : string = "/tmp";print (s1).as_a(int);print (c).as_a(string);

--print (s2).as_a(int); // Run-time error--print (i).as_a(string); // Compile-time error};

};

Example 5

The “print pkt.as_a(foreign packet)” action below results in “pkt.as_a(foreignpacket) = NULL” because “pkt” is of type “Ethernet packet”.

The “print pkt.e_field” action in this example results in a compile-time error becauthe declared type of “pkt” does not have a field “e_field”. However, the “printpkt.as_a(Ethernet packet).e_field” action prints the value of the field.

type packet_protocol: [Ethernet, IEEE, foreign];struct packet {

protocol: packet_protocol;size: int [0..1k];data[size]: list of byte;show() is undefined; // To be defined by children

};extend Ethernet packet {

e_field: int;show() is {out("I am an Ethernet packet")};

};extend sys {

m() is {var epkt: Ethernet packet = new;var pkt: packet = epkt;print pkt.type().name;print pkt.declared_type().name;print pkt.as_a(foreign packet);

-- print pkt.e_field; //compile-time errorprint pkt.as_a(Ethernet packet).e_field;print pkt.size;

};};

4-32 Preliminary e Libraries

Page 169: Prelim e Lib

as_a() Predefined Routines

size

f

Example 6

Theas_a()pseudo-method, when applied to a scalar list, creates a new list whoseis the same as the original size and then casts each element separately.

To pass a list of integer(bits: 4) as a parameter to a method that requires a list ointegers, you can use explicit casting, as follows:

struct dtypes {increment_list (cnt: list of int) is {

for each in cnt {cnt[index] = cnt[index] + 1;

};};

};

extend sys {di:dtypes;m() is {

var small_list: list of int (bits: 5) = {3;5;7;9};var big_list: list of int = {0;0;0;0;};big_list = small_list.as_a(list of int);di.increment_list(big_list);print big_list;

};};

Example 7

When theas_a() operator is applied to a list of structs, the list items for which thecasting failed are omitted from the list.

type packet_protocol: [Ethernet, IEEE, foreign];struct packet {

protocol: packet_protocol;size: int [0..1k];data[size]: list of byte;show() is undefined; // To be defined by children

};extend Ethernet packet {

e_field: int;show() is {out("I am an Ethernet packet")};

};extend sys {

packets[5]: list of packet;run() is also {

print packets;

e Libraries Preliminary 4-33

Page 170: Prelim e Lib

Predefined Routines as_a()

fII

se

tch.

a file.

print packets.as_a(list of IEEE packet);};

};

Example 8

You can useas_a() to cast between a list of numerics and a string. Casting a list onumerics to a string results in a string expression whose characters are the ASCvalues of each list item. Casting a string to a list of numerics results in a list whoitems each contain the numeric representation of a single ASCII character.

extend sys {m() is {

var lobyte: list of byte = {116;101;120;116};print lobyte.as_a(string);print "text".as_a(list of byte);

};};

Example 9

You can useas_a()to convert a string to an enumerated type. The string has to maletter by letter one of the possible values of that type or a runtime error is issued

This example sets a list of items of an enumerated type to the values read from

type reg_address: [UARTCTL1, UARTDATA1, UARTCTL2, UARTDATA2];extend sys {

ctl_regs: list of reg_address;

keep ctl_regs == (each line in file"~/data/enum_items").apply(it.as_a(reg_address));

run() is also {print sys.ctl_regs;

};};

See Also

• “Automatic Type Casting” on page 3-22 in theeLanguage Reference Manual

• “e Data Types” on page 3-2 in theeLanguage Reference Manual

• is [not] a on page 2-71 in theeLanguage Reference Manual

4-34 Preliminary e Libraries

Page 171: Prelim e Lib

all_values() Predefined Routines

thathichthe

4.5.2 all_values()

Purpose

Access all values of a scalar type

Category

Pseudo routine

Syntax

all_values(scalar-type): list of scalar type

Syntax example:

print all_values(reg_address);

Parameters

Description

Returns a list that contains all the legal values of the specified scalar type. Whentype is an enumerated type, the order of the items is the same as the order in wthey were defined. When the type is a numeric type, the order of the items in fromsmallest to the largest.

Example

type reg_address: [UARTCTL1, UARTDATA1, UARTCTL2, UARTDATA2];extend sys {

ctl_regs: list of reg_address;

keep ctl_regs ==all_values(reg_address).all(it.as_a(string) ~"*CTL*");

run() is also {print sys.ctl_regs;

};};

scalar-type Any legalescalar type.

e Libraries Preliminary 4-35

Page 172: Prelim e Lib

Predefined Routines Unit-Related Predefined Routines

f this

,

urs.

4.6 Unit-Related Predefined RoutinesThis section contains the following:

• “get_all_units()” on page 4-36

4.6.1 get_all_units()

Purpose

Return a list of instances of a specified unit type

Category

Routine

Syntax

get_all_units(unit-type): list of unit-type

Syntax example:

print get_all_units(XYZ_channel);

Parameter

Description

This routine receives a unit type as a parameter and returns a list of instances ounit as well as any unit instances contained within each instance.

Example

This example usesget_all_units()to print a list of the instances of XYZ_router. Notethat the display also shows that this instance of XYZ_router contains “channels”which is a list of three unit instances.

<'unit XYZ_router { channels: list of XYZ_channel is instance;

unit-type The name of a unit type. The type must be defined or an error occ

4-36 Preliminary e Libraries

Page 173: Prelim e Lib

Constructs for Packing and Unpacking Predefined Routines

keep channels.size() == 3; keep for each in channels {

.hdl_path() == append("chan", index);

.router == me};

};

unit XYZ_channel { router:XYZ_router;};

extend sys { router:XYZ_router is instance;

run() is also {print get_all_units(XYZ_router);

};};'>

See Also

• “Predefined Methods for Any Unit” on page 2-11

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

4.7 Constructs for Packing and UnpackingThe following sections describe the constructs used in packing and unpacking:

• pack() on page 4-38

• unpack() on page 4-42

• %{…} on page 2-64 in theeLanguage Reference Manual

• swap() on page 4-47

• do_pack() on page 4-49

• do_unpack() on page 4-53

See Also

• Chapter 16, “Packing and Unpacking” in theeLanguage Reference Manual

e Libraries Preliminary 4-37

Page 174: Prelim e Lib

Predefined Routines pack()

e

d or

or

siont,

4.7.1 pack()

Purpose

Perform concatenation and type conversion

Category

Pseudo-method

Syntax

pack(options: pack_options, exp, …)

Syntax example:

i_stream = pack(packing.high, opcode, operand1, operand2);

Parameters

pack-options For basic packing, this parameter is one of the following. Se“Using the Predefined pack_options Instances” on page 16-13intheeLanguage Reference Manual for information on theseoptions.

packing.high Places the least significant bit of the last physical field declarethe highest list item at index [0] in the resulting list of bit. Themost significant bit of the first physical field or lowest list item isplaced at the highest index in the resulting list of bit.

packing.low Places the least significant bit of the first physical field declaredlowest list item at index [0] in the resulting list of bit. The mostsignificant bit of the last physical field or highest list item isplaced at the highest index in the resulting list of bit.

NULL If NULL is specified, the global default is used. This globaldefault is set initially topacking.low.

exp One or more expressions separated by commas. Each expresis a path to a scalar or a compound data item, such as a strucfield, list, or variable.

4-38 Preliminary e Libraries

Page 175: Prelim e Lib

pack() Predefined Routines

he

tion

3-13

itall

Description

Performs concatenation of items, including items in a list or fields in a struct, in torder specified by the pack options parameter. This method also performs typeconversion between any of the following:

• scalars

• strings

• lists and list subtypes (same type but different width)

• Packing is commonly used to prepare high-leveledata into a form that can be appliedto a DUT. For other uses, see Chapter 16, “Packing and Unpacking” in theeLanguageReference Manual.

Packing operates on scalar or compound (struct, list) data items. For more informaand examples of how packing operates on different data types, see Chapter 16,“Packing and Unpacking” in theeLanguage Reference Manual.

Pack expressions are untyped expressions. See “Untyped Expressions” on pagein theeLanguage Reference Manual for more information.

Note

You cannot pack an unbounded integer.

Example 1

The example shown below packs the “opcode” and the “operand” fields of the“instruction” struct from the low bit of the last field defined (“operand”) to the high bof the first field defined (“opcode”) into the “data_packed_high” field. It also packsthe physical fields into “data_packed_low” using thepacking.low option. The resultsare shown in Figure 4-1 on page 4-40.

<'struct instruction {

%opcode : uint (bits : 3);%operand : uint (bits : 5);%address : uint (bits : 8);

!data_packed_high : list of bit;!data_packed_low : list of bit;

keep opcode == 0b100;keep operand == 0b11001;

e Libraries Preliminary 4-39

Page 176: Prelim e Lib

Predefined Routines pack()

keep address == 0b00001111;

pack_data() is {data_packed_high = pack(packing.high,

opcode,operand);data_packed_low = pack(packing.low, me);print me using bin;print data_packed_low using bin;print data_packed_high using bin;

};};'>

Figure 4-1 Packed Instruction Data

The “instruction” struct:

opcode == 0x4

operand == 0x19

1

1 0 0

1 1 10 0

1 001 10 0

The fields “opcode” and “operand” packed, using packing.high

opcodeoperand

list of bit [7] list of bit [0]

0011 0 0 11

opcode operand

address == 0x0f 1 110 0 10 0

The instruction packed, using packing.low

0 00 1 10 1 1

address

list of bit [15] list of bit [0]

4-40 Preliminary e Libraries

Page 177: Prelim e Lib

pack() Predefined Routines

ket”4-2

Example 2

This example shows how to pack the packet data. The “header” field of the “pacstruct is a struct itself, so this is a recursive pack. The results are shown in Figureon page 4-42.

<'struct packet {

%header : header;%payload : list of byte;

!data_packed_low : list of byte;

keep payload.size() == 6;keep for each in payload {

it == index;};

pack_data() is {data_packed_low = pack(packing.low, me);out("payload: ", payload);out("data packed low: ", data_packed_low);

};};

struct header {%dest : int (bits : 8);%version : int (bits : 2);%type : uint (bits : 6);

keep dest == 0x55;keep version == 0x0;keep type == 0x3f;

};'>

e Libraries Preliminary 4-41

Page 178: Prelim e Lib

Predefined Routines unpack()

Figure 4-2 Packed Packet Data

See Also

• unpack() on page 4-42

• %{…} on page 2-64 in theeLanguage Reference Manual

• swap() on page 4-47

• do_pack() on page 4-49

• do_unpack() on page 4-53

4.7.2 unpack()

Purpose

Unpack a bit stream into one or more expressions

0 000 0 00 0

payload

The “packet” struct:Header:

dest

version

type

111 0 0 10 0

0 000 0 00 0

0 0

1 11 1 1 1

Payload

1 000 0 10 0 .....

111 0 0 10 0

0 0

The “packet” data packed, using packing.low

destversion

1 11 1 1 1

type

list of bit [0]list of bit [127].....

4-42 Preliminary e Libraries

Page 179: Prelim e Lib

unpack() Predefined Routines

ein

t

it

t is

ssionct,

Category

Pseudo-method

Syntax

unpack(options: pack_options, val-exp, target-exp1 [, target-exp2, …])

Syntax example:

unpack(packing.high, lob, s1, s2);

Parameters

Description

Converts a raw bit stream into high level data by storing the bits of the valueexpression into the target expressions.

pack-options For basic packing, this parameter is one of the following. Se“Using the Predefined pack_options Instances” on page 16-13theeLanguage Reference Manualfor information on other packoptions.

packing.high Places the most significant bit of the list of bit at the mostsignificant bit of the first field or lowest list item. The leastsignificant bit of the list of bit is placed into the least significanbit of the last field or highest list item.

packing.low Places the least significant bit of the list of bit into the leastsignificant bit of the first field or lowest list item. The mostsignificant bit of the list of bit is placed at the most significant bof the last field or highest list item.

NULL If NULL is specified, the global default is used. This globaldefault is set initially topacking.low.

value-exp A scalar expression or list of scalars that provides a value thato be unpacked.

target-exp One or more expressions separated by commas. Each expreis a path to a scalar or a compound data item, such as a strufield, list, or variable.

e Libraries Preliminary 4-43

Page 180: Prelim e Lib

Predefined Routines unpack()

gn

get;

If the value expression is not a list of bit, it is first converted into a list of bit by callinpack() usingpacking.low. (See “Implicit Packing and Unpacking” on page 16-24 itheeLanguage Reference Manual for more information.) Then the list of bit isunpacked into the target expressions.

The value expression is allowed to have more bits than are consumed by the tarexpressions. In that case, ifpacking.low is used, the extra high-order bits are ignoredif packing.high is used, the extra low-order bits are ignored.

Unpacking is commonly used to convert raw bit stream output from the DUT intohigh-leveledata.

Unpacking operates on scalar or compound (struct, list) data items. For moreinformation and examples of how packing operates on different data types, seeChapter 16, “Packing and Unpacking” in theeLanguage Reference Manual.

Example 1

This example unpacks a list of bits into a variable “inst”. The results are shown inFigure 4-3 on page 4-45.

extend sys {pack_data() is {

var inst : instruction;var packed_data: list of bit;packed_data = {1;1;1;1;0;0;0;0;1;0;0;1;1;0;0;1};

unpack(packing.high, packed_data, inst);

print packed_data using bin;out("the result of unpacking it: ");print inst using bin;

};};

struct instruction {%opcode : uint (bits : 3);%operand : uint (bits : 5);%address : uint (bits : 8);

};

4-44 Preliminary e Libraries

Page 181: Prelim e Lib

unpack() Predefined Routines

ults

Figure 4-3 Unpacked Instruction Data

Example 2

This example unpacks a list of bytes into a variable “pkt” usingpacking.low. This is arecursive unpack because the “header” field of “packet” is a struct itself. The resare shown in Figure 4-4 on page 4-46.

extend sys {pack_data() is {

var pkt : packet;var packed_data : list of byte;packed_data =

{0x55;0xfc;0x00;0x01;0x02;0x03;0x04;0x05};

unpack(packing.low, packed_data, pkt);

print packed_data;out("the unpacked struct:");print pkt.header, pkt.payload;

};};

struct packet {%header : header;%payload : list of byte;

};

struct header {

The packed data

1 1 10 0 10 0

The result of unpacking the data with packing.high:

0 010 1 11 0

opcode == 0x4

operand == 0x19

1 0 0

1 1 10 0

address == 0x0f 1 110 0 10 0

e Libraries Preliminary 4-45

Page 182: Prelim e Lib

Predefined Routines unpack()

r

%dest : int (bits : 8);%version : int (bits : 2);%type : int (bits : 6);

};

Figure 4-4 Unpacked Packet Data

Example 3

This example usesunpack() sequentially to set up virtual fields that are required fothe full unpack.

struct packet {%header: header;len : uint;%data[len] : list of byte;

};struct header {

%code : uint;};extend sys {

m() is {var DUT_bytes: list of byte = {0x11;0xff;0x22;0xee;0x33;0xdd;0x44;0xcc;0x55;0xbb;0x66};

000 0 0 00 0 1 11 1 0 01 1 1 000 1 10 1

The packed data

.....

The unpacked struct

Header:

dest

version

type

0 000 0 00 0

0 0

Payload

1 000 0 10 0 .....

111 0 0 10 0

1 11 1 1 1

4-46 Preliminary e Libraries

Page 183: Prelim e Lib

swap() Predefined Routines

var p : packet = new;unpack(packing.low, DUT_bytes, p.header);if p.header.code > 1500 {

p.len = 10;} else {

p.len = 20;};unpack(packing.low, DUT_bytes,p);print p;print p.data;

};};

See Also

• pack() on page 4-38

• %{…} on page 2-64 in theeLanguage Reference Manual

• swap() on page 4-47

• do_pack() on page 4-49

• do_unpack() on page 4-53

4.7.3 swap()

Purpose

Swap small bit chunks within larger chunks

Category

Pseudo-method

Syntax

list-of-bit.swap(small: int, large: int);

Syntax example:

s2 = s1.swap(2, 4);

e Libraries Preliminary 4-47

Page 184: Prelim e Lib

Predefined Routines swap()

ndith

ults.

ifed.

very

ireire

Parameters

Description

This predefined list method accepts a list of bits, changes the order of the bits, athen returns the reordered list of bits. This method is often used in conjunction wpack() or unpack() to reorder the bits in a bit stream going to or coming from theDUT.

Notes

• If large is not a factor of the number of bits in the entire list, an error message res

• If smallis not a factor oflarge, you will see an error message. The only exception islarge is UNDEF andsmallis not a factor, no swap is performed and no error is issu

Example 1

This example shows two swaps. The first swap reverses the order of nibbles in ebyte. The second swap reverses the whole list.

small An integer that is a factor oflarge.

large An integer that is either UNDEF or a factor of the number of bits in the entlist. If UNDEF, the method reverses the order of small chunks within the entlist. Thus, “lob.swap(1, UNDEF)” is the same as “lob.reverse()”.

0 000 1 00 1 1 001 1 11 1

my_list

1 000 0 10 0 1 110 1 10 1

my_list.swap(4, 8)

1 111 0 11 0 0 110 0 00 0

my_list.swap(1, UNDEF)

4-48 Preliminary e Libraries

Page 185: Prelim e Lib

do_pack() Predefined Routines

Example 2

This example showsswap()used withunpack() to reorder the bits before unpackingthem.

extend sys {pack_data() is also {

var num1 : uint (bits : 32);var num2 : uint (bits : 32);num1 = 0x12345678;

unpack(NULL, pack(NULL, num1).swap(16, -1), num2);print num2;unpack(NULL, pack(NULL, num1).swap(8, -1), num2);print num2;

};};

See Also

• pack() on page 4-38

• unpack() on page 4-42

• %{…} on page 2-64 in theeLanguage Reference Manual

• do_pack() on page 4-49

• do_unpack() on page 4-53

4.7.4 do_pack()

Purpose

Pack the physical fields of the struct

Category

Predefined method of any struct

Syntax

do_pack(pack-options, l: * list of bit)

e Libraries Preliminary 4-49

Page 186: Prelim e Lib

Predefined Routines do_pack()

s

t

tt

chd

achd

Syntax example:

do_pack(options:pack_options, l: *list of bit) is only {var L : list of bit = pack(packing.low, operand2,

operand1,operand3);l.add(L);

};

Parameters

options This parameter is one of the following pack optionstructs. See “Using the Predefined pack_optionsInstances” on page 16-13 in theeLanguageReference Manual for information on these packoptions.

packing.high Places the least significant bit of the last field orhighest list item at index [0] in the resulting list of bit.The most significant bit of the first field or lowest listitem is placed at the highest index in the resulting lisof bit.

packing.low Places the least significant bit of the first field orlowest list item at index [0] in the resulting list of bit.The most significant bit of the last field or highest lisitem is placed at the highest index in the resulting lisof bit.

packing.low_big_endian Similar to packing.low, but swaps every byte in eapair of bytes and every two bytes in each 32-bit worfor each scalar before it is packed.

packing.high_big_endian Similar to packing.high, but swaps every byte in epair of bytes and every two bytes in each 32-bit worfor each scalar before it is packed.

packing.global_default Set initially to packing.low.

NULL If NULL is specified, the global default is used.

list-of-bits An empty list of bits that will be extended asnecessary to hold the data from the struct fields.

4-50 Preliminary e Libraries

Page 187: Prelim e Lib

do_pack() Predefined Routines

%)

time

gny

on

es

Description

Thedo_pack() method of a struct is called automatically whenever the struct ispacked. This method appends data from the physical fields (the fields marked withof the struct into a list of bits according to flags determined by the pack optionsparameter. The virtual fields of the struct are skipped. The method issues a run-error message if this struct has no physical fields.

For example, the following assignment to “lob”

lob = pack(packing.high, i_struct, p_struct);

makes the following calls to thedo_pack method of each struct, wheretmp is anempty list of bits:

i_struct.do_pack(packing.high, *tmp)p_struct.do_pack(packing.high, *tmp)

You can extend thedo_pack()method for a struct in order to create a unique packinscenario for that struct. You should handle variations in packing that apply to mastructs by creating a custompack_optionsinstance. See in theeLanguage ReferenceManual for information on how to do this.

Notes

• Do not callpack(me) in thedo_pack() method. This causes infinite recursion. Callpacking.pack_struct(me)instead. You can callpack() within thedo_pack()methodto pack objects other thanme.

• Do not forget to append the results of any pack operation withindo_pack()to the emptylist of bits referenced in thedo_pack() parameter list.

• If you modify thedo_pack()method and then later add physical fields in an extensito the struct, you may have to make adjustments in the modifications todo_pack().

Example 1

This example shows how to override thedo_pack()method for a struct called “cell”.The extension todo_pack() overrides any packing option passed in and always uspacking.low. It packs “operand2” first, then “operand1” and “operand3”.

<'struct cell {

%operand1: uint(bytes:2);%operand2: uint(bytes:2);%operand3: uint(bytes:2);

e Libraries Preliminary 4-51

Page 188: Prelim e Lib

Predefined Routines do_pack()

the

};

extend cell {do_pack(options:pack_options, l: *list of bit) is only {

var L : list of bit = pack(packing.low, operand2,operand1,operand3);

l.add(L);};

};

Example 2

In the following example, thedo_pack() method for “cell” is overwritten to use thelow_big_endian packing option by default.

struct cell {%operand1: uint(bytes: 2);%operand2: uint(bytes: 2);%operand3: uint(bytes: 2);

};

extend cell {do_pack(options: pack_options, l: *list of bit) is only {

if (options == NULL) then {packing.pack_struct(me,

packing.low_big_endian,l);} else {

packing.pack_struct(me, options, l);};

};};

extend sys {pi: cell;

};

Example 3

This example swaps every pair of bits within each 4-bit chunk after packing withpacking options specified in thepack() call.

struct cell {%operand1: uint(bytes: 2);%operand2: uint(bytes: 2);

4-52 Preliminary e Libraries

Page 189: Prelim e Lib

do_unpack() Predefined Routines

%operand3: uint(bytes: 2);};

extend cell {do_pack(options:pack_options, l: *list of bit) is only {

var L1 : list of bit;packing.pack_struct(me, options, L1);var L2 : list of bit = L1.swap(2,4);l.add(L2);

};};

See Also

• pack() on page 4-38

• unpack() on page 4-42

• %{…} on page 2-64 in theeLanguage Reference Manual

• swap() on page 4-47

• do_unpack() on page 4-53

4.7.5 do_unpack()

Purpose

Unpack a packed list of bit into a struct

Category

Predefined method of any struct

Syntax

do_unpack(options: pack_options,l: list-of-bit, from:int): int

Syntax example:

do_unpack(options:pack_options, l: list of bit, from: int):int is only {

var L : list of bit = l[from..];unpack(packing.low, L, op2, op1, op3);

e Libraries Preliminary 4-53

Page 190: Prelim e Lib

Predefined Routines do_unpack()

in

dre

r

chd

achd

t

t

e

return from + 8 + 5 + 3;};

Parameters

options For basic packing, this parameter is one of thefollowing pack options structs. See “Using thePredefined pack_options Instances” on page 16-13theeLanguage Reference Manualfor information onthese pack options.

packing.high Takes the item at index [0] of the input list of bit anplaces it at the least significant bit of the last field ohighest list item. The item at the highest index of thinput list of bit is placed at the most significant bit ofthe first field or lowest list item.

packing.low Takes the item at index [0] of the input list of bit andplaces it at the least significant bit of the first field olowest list item. The item at the highest index of theinput list of bit is placed at the most significant bit ofthe last field or highest list item.

packing.low_big_endian Similar to packing.low, but swaps every byte in eapair of bytes and every two bytes in each 32-bit worfor each scalar before it is packed.

packing.high_big_endian Similar to packing.high, but swaps every byte in epair of bytes and every two bytes in each 32-bit worfor each scalar before it is packed.

packing.global_default Set initially to packing.low.

NULL If NULL is specified, the global default is used.

l A list of bits containing data to be stored in the strucfields.

from An integer that specifies the index of the bit to starunpacking.

to An integer that specifies the index of the last bit in thlist of bits that was unpacked.

4-54 Preliminary e Libraries

Page 191: Prelim e Lib

do_unpack() Predefined Routines

he ofd by

list

If atthan

t

add

ned

”,

Description

Thedo_unpack()method is called automatically whenever data is unpacked into tcurrent struct. This method unpacks bits from a list of bits into the physical fieldsthe struct. It starts at the bit with the specified index, unpacks in the order definethe pack options, and fills the current struct’s physical fields in the order they aredefined.

For example, the following call to unpack()

unpack(packing.low, lob, c1, c2);

makes the following calls to thedo_unpack method of each struct:

c1.do_unpack(packing.low, lob, index);c2.do_unpack(packing.low, lob, index);

The method returns an integer, which is the index of the last bit unpacked into theof bits.

The method issues a run-time error message if the struct has no physical fields.the end of packing there are leftover bits, it is not an error. If more bits are neededcurrently exist in the list of bits, a run-time error is issued (“Ran out of bits whiletrying to unpack intostruct_name”).

You can extend thedo_unpack() method for a struct in order to create a uniqueunpacking scenario for that struct. You should handle variations in unpacking thaapply to many structs by creating a custompack_optionsinstance. See “CustomizingPack Options” on page 16-19 in theeLanguage Reference Manualfor information onhow to do this.

Note

When you modify thedo_unpack() method, you need to calculate and return theindex of the last bit in the list of bits that was unpacked. In most cases, you simplythe bit width of each physical field in the struct to the startingindexparameter. If youare unpacking into a struct that has conditional physical fields (physical fields defiunder awhen, extend, or like construct), this calculation is a bit tricky.

Example 1

This first example shows how to modifydo_unpack() to change the order in whichthe fields of a struct are filled. In this case, the order is changed from “op1”, “op2“op3” to “op2”, “op1”, “op3”. You can see also thatdo_unpack() returns the bitwidths of the three physical fields, “op1”, “op2”, and “op3”, to the starting index,“from”.

e Libraries Preliminary 4-55

Page 192: Prelim e Lib

Predefined Routines do_unpack()

bit

struct cell {%op1: uint(bytes:1);%op2: uint(bits:5);%op3: uint(bits:3);

};

extend cell {do_unpack(options:pack_options, l: list of bit,

from: int) :int is only {var L : list of bit = l[from..];unpack(packing.low, L, op2, op1, op3);return from + 8 + 5 + 3;

};};

Example 2

This example modifies thedo_unpack method of the “frame” struct to first calculatethe length of the “data” field. The calculation uses “from”, which indicates the lastto be unpacked, to calculate the length of “data”.

extend sys {!packet1 : packet;!packet2 : packet;

pack_data() is {var raw_data : list of byte;for i from 0 to 39 {

raw_data.add(i);};unpack(packing.low, raw_data, packet1);print packet1.header, packet1.frame.data,

packet1.frame.crc;unpack(packing.high, raw_data, packet2);print packet2.header, packet2.frame.data,

packet2.frame.crc;};

};

struct packet {%header : int (bits : 16);%frame : frame;

};

struct frame {%data[len] : list of byte;

4-56 Preliminary e Libraries

Page 193: Prelim e Lib

String Routines Predefined Routines

ter copy,

%crc : int (bits : 32);len : int;

do_unpack(options :pack_options, l :list of bit,from :int):int is first {

if options.reverse_fields then {len = (from - 32 + 1) / 8;

} else {len = (l.size() - from - 32) / 8;

};};

};

See Also

• pack() on page 4-38

• unpack() on page 4-42

• %{…} on page 2-64 in theeLanguage Reference Manual

• swap() on page 4-47

• do_pack() on page 4-49

4.8 String RoutinesNone of the string routines ine modify the input parameters. When you pass a parameto one of these routines, the routine makes a copy of the parameter, manipulates theand returns the copy.

Routines that convert expressions into a string:

• append() on page 4-59

• appendf() on page 4-60

• quote() on page 4-65

• to_string() on page 4-82

Routines that manipulate substrings:

• str_join() on page 4-70

• str_split() on page 4-78

e Libraries Preliminary 4-57

Page 194: Prelim e Lib

Predefined Routines String Routines

• str_split_all() on page 4-79

• str_sub() on page 4-80

Routines that manipulate regular expressions:

• str_match() on page 4-73

• str_replace() on page 4-76

• str_insensitive() on page 4-69

Routines that change the radix of a numeric expression:

• bin() on page 4-61

• dec() on page 4-62

• dec() on page 4-62

Routines that manipulate the length of an expression:

• str_chop() on page 4-66

• str_empty() on page 4-67

• str_exactly() on page 4-68

• str_len() on page 4-71

• str_pad() on page 4-75

Routines that manipulate the case of characters within a string:

• str_lower() on page 4-72

• str_upper() on page 4-81

• str_insensitive() on page 4-69

See Also

• “String Matching” on page 2-54 in theeLanguage Reference Manual

• “The String Type” on page 3-13 in theeLanguage Reference Manual

• “File Routines” on page 4-96

4-58 Preliminary e Libraries

Page 195: Prelim e Lib

append() Predefined Routines

renthe

t ID

4.8.1 append()

Purpose

Concatenate expressions into a string

Category

Routine

Syntax

append(exp, …): string

Syntax example:

message = append(list1, " ", list2);

Parameter

Description

Callsto_string() on page 4-82 to convert each expression to a string using the curradix setting for any numeric expressions, then concatenates them and returns tresult as a single string.

Example

extend sys {m1() is {

var message: string;var u1:uint = 55;var u2:uint = 44;message = append(u1, " ", u2);print message;var list1:list of bit = {0;1;0;1};var list2:list of bit = {1;1;1;0};message = append(list1, " ", list2);print message;

exp A list of zero or more legaleexpressions. String expressions must beenclosed in double quotes. If the expression is a struct instance, the strucis printed.

e Libraries Preliminary 4-59

Page 196: Prelim e Lib

Predefined Routines appendf()

rentates

ting

truct

};};

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.2 appendf()

Purpose

Concatenate expressions into a string according to a given format

Category

Routine

Syntax

appendf(format, exp, …): string

Syntax example:

message = appendf("%4d\n %4d\n %4d\n", 255, 54, 1570);

Parameters

Description

Callsto_string() on page 4-82 to convert each expression to a string using the curradix setting for any numeric expressions and the specified format, then concatenthem and returns the result as a single string.

format A string enclosed in double quotes and containing a standard C formatmask for each expression. See “Format String” on page 4-88 for moreinformation.

exp A list of zero or more legaleexpressions. String expressions must beenclosed in double quotes. If the expression is a struct instance, the sID is printed.

4-60 Preliminary e Libraries

Page 197: Prelim e Lib

bin() Predefined Routines

and

es

Note

If the number and type of masks in the format string does not match the numbertype of expressions, an error is issued.

Example

<'extend sys { m1() is {

var message: string;message = appendf("%4d\n %4d\n %4d\n", 255, 54, 1570);out(message);

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.3 bin()

Purpose

Concatenate expressions into string, using binary representation for numeric typ

Category

Routine

Syntax

bin(exp, …): string

Syntax example:

var my_string: string = bin(pi.i, " ", list1, " ",8);

e Libraries Preliminary 4-61

Page 198: Prelim e Lib

Predefined Routines dec()

for

pes

edted.

Parameter

Description

Concatenates one or more expressions into a string, using binary representationany expressions of numeric types, regardless of the current radix setting.

Example

<'struct p { i:int;};

extend sys {pi:p;m1() is {

pi = new;pi.i = 11;var list1:list of bit = {0;1;1;0};var my_string: string = bin(pi.i, " ", list1, " ",8);print my_string;

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.4 dec()

Purpose

Concatenate expressions into string, using decimal representation for numeric ty

exp A list of one or more legaleexpressions. String expressions must be enclosin double quotes. If the expression is a struct instance, the struct ID is prin

4-62 Preliminary e Libraries

Page 199: Prelim e Lib

dec() Predefined Routines

on for

edted.

Category

Routine

Syntax

dec(exp, …): string

Syntax example:

var my_string: string = dec(pi.i, " ", list1, " ",8);

Parameter

Description

Concatenates one or more expressions into a string, using decimal representatiany expressions of numeric types, regardless of the current radix setting.

Example

<'struct p { i:int;};

extend sys {pi:p;m1() is {

pi = new;pi.i = 11;var list1:list of bit = {0;1;1;0};var my_string: string = dec(pi.i, " ", list1, " ",8);print my_string;

};};'>

See Also

• “String Routines” on page 4-57

exp A list of one or more legaleexpressions. String expressions must be enclosin double quotes. If the expression is a struct instance, the struct ID is prin

e Libraries Preliminary 4-63

Page 200: Prelim e Lib

Predefined Routines hex()

ric

tation

ct

• “Predefined Routines Overview” on page 4-1

4.8.5 hex()

Purpose

Concatenate expressions into string, using hexadecimal representation for numetypes

Category

Routine

Syntax

hex(exp, …): string

Syntax example:

var my_string: string = hex(pi.i, " ", list1, " ",8);

Parameter

Description

Concatenates one or more expressions into a string, using hexadecimal represenfor any expressions of numeric types, regardless of the current radix setting.

Example

<'struct p { i: int;};

extend sys {pi: p;m1() is {

exp A list of one or more legaleexpressions. String expressions must beenclosed in double quotes. If the expression is a struct instance, the struID is printed.

4-64 Preliminary e Libraries

Page 201: Prelim e Lib

quote() Predefined Routines

te or

pi = new;pi.i = 11;var list1:list of bit = {0;1;1;0};var my_string: string = hex(pi.i, " ", list1, " ",8);print my_string;

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.6 quote()

Purpose

Enclose a string with double quotes

Category

Routine

Syntax

quote(text: string): string

Syntax example:

out(quote(message));

Parameter

Description

Returns a copy of the text, enclosed in double quotes (" "), with any internal quobackslash preceded by a backslash (\).

text An expression of typestring.

e Libraries Preliminary 4-65

Page 202: Prelim e Lib

Predefined Routines str_chop()

Example

<'extend sys {

m1() is {var message: string = "Error occurred in \"D\" block...";out(message);out(quote(message));

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.7 str_chop()

Purpose

Chop the tail of a string

Category

Routine

Syntax

str_chop(str: string, length: int): string

Syntax example:

var test_dir: string = str_chop(tmp_dir, 13);

Parameters

str An expression of typestring.

length An integer representing the desired length.

4-66 Preliminary e Libraries

Page 203: Prelim e Lib

str_empty() Predefined Routines

th. If

Description

Returnsstr (if its length is <=length), or a copy of the firstlength chars ofstr.

Removes characters from the end of a string, returning a string of the desired lengthe original string is already less than or equal to the desired length, this routinereturns a copy of the original string.

Example

<'extend sys {

m1() is { var tmp_dir: string = "/rtests/test1/tmp"; var test_dir: string = str_chop(tmp_dir, 13); print test_dir;

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.8 str_empty()

Purpose

Check if a string is empty

Category

Routine

Syntax

str_empty(str: string): bool

Syntax example:

print str_empty(s1);

e Libraries Preliminary 4-67

Page 204: Prelim e Lib

Predefined Routines str_exactly()

Parameter

Description

Returns TRUE if the string is uninitialized or empty.

Example

<'extend sys{

m1() is {var s1: string;var s2: string = "";print str_empty(s1);print str_empty(s2);

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.9 str_exactly()

Purpose

Get a string with exact length

Category

Routine

Syntax

str_exactly(str: string, length: int): string

Syntax example:

str An expression of typestring.

4-68 Preliminary e Libraries

Page 205: Prelim e Lib

str_insensitive() Predefined Routines

ng

in the

var long: string = str_exactly("123", 6);

Parameters

Description

Returns a copy of the original string, whose length is the desired length, by addiblanks to the right or by truncating the expression from the right as necessary. Ifnon-blank characters are truncated, the * character appears as the last characterstring returned.

Example

<'extend sys { m1() is { var short: string = str_exactly("123000",3); print short; var long: string = str_exactly("123", 6); print long; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.10 str_insensitive()

Purpose

Get a case-insensitive AWK-style regular-expression

Category

Routine

str An expression of typestring.

length An integer representing the desired length.

e Libraries Preliminary 4-69

Page 206: Prelim e Lib

Predefined Routines str_join()

sion

Syntax

str_insensitive(regular_exp: string): string

Syntax example:

var insensitive: string = str_insensitive("/hello.*/");

Parameter

Description

Returns an AWK-style regular expression string which is the case-insensitive verof the original regular expression.

Example

<'extend sys { m1() is { var insensitive: string = str_insensitive("/hello.*/"); print insensitive; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.11 str_join()

Purpose

Concatenate a list of strings

Category

Routine

regular-exp An AWK-style regular expression.

4-70 Preliminary e Libraries

Page 207: Prelim e Lib

str_len() Predefined Routines

gs,

Syntax

str_join( list: list of string, separator: string): string

Syntax example:

var s := str_join(slist," - ");

Parameters

Description

Returns a single string which is the concatenation of the strings in the list of strinseparated by the separator.

Example

<'extend sys { m1() is {

var slist: list of string = {"first";"second";"third"}; var s := str_join(slist," - "); print s; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.12 str_len()

Purpose

Get string length

list A list of typestring.

separator The string that will be used to separate the list elements.

e Libraries Preliminary 4-71

Page 208: Prelim e Lib

Predefined Routines str_lower()

ting

Category

Routine

Syntax

str_len(str: string): int

Syntax example:

var length: int = str_len("hello");

Parameter

Description

Returns the number of characters in the original string, not counting the terminaNULL character \0.

Example

<'extend sys { m1() is { var length: int = str_len("hello"); print length; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.13 str_lower()

Purpose

Convert string to lowercase

str An expression of typestring.

4-72 Preliminary e Libraries

Page 209: Prelim e Lib

str_match() Predefined Routines

s the

Category

Routine

Syntax

str_lower(str: string): string

Syntax example:

var lower: string = str_lower("UPPER");

Parameter

Description

Converts all upper case characters in the original string to lower case and returnstring.

Example

<'extend sys { m1() is { var lower: string = str_lower("UPPER"); print lower; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.14 str_match()

Purpose

Match strings

str An expression of typestring.

e Libraries Preliminary 4-73

Page 210: Prelim e Lib

Predefined Routines str_match()

ine

ed

Category

Routine

Syntax

str_match(str: string, regular-exp: string): bool

Syntax example:

print str_match("ace", "/c(e)?$/");

Parameters

Description

Returns TRUE if the strings match, or FALSE if the strings do not match. The routstr_match() is fully equivalent to the operator ~.

Example 1

After doing a match, you can use the local pseudo-variables $1, $2…$27, whichcorrespond to the parenthesized pieces of the match. $0 stores the whole matchpiece of the string.

<'extend sys {

m1() is {print str_match("a", "/^(a)?(b)?$/");print $0, $1, $2;print str_match("hello","/^\d*$/");print $0, $1, $2;print str_match("b", "/^(a)?(b)?$/");print $0, $1, $2;print str_match("ace", "/c(e)?$/");print $0, $1;

};};'>

str An expression of typestring.

regular-exp An AWK-style regular expression, surrounded by slashes.

4-74 Preliminary e Libraries

Page 211: Prelim e Lib

str_pad() Predefined Routines

dgth,

See Also

• “String Routines” on page 4-57

• ~ !~ on page 2-51 in theeLanguage Reference Manual

4.8.15 str_pad()

Purpose

Pad string with blanks

Category

Routine

Syntax

str_pad(str: string, length: int): string

Syntax example:

var s: string = str_pad("hello world",14);

Parameters

Description

Returns a copy of the original string padded with blanks on the right, up to desirelength. If the length of the original string is greater than or equal to the desired lenthen the original string is returned (not a copy) with no padding.

Example

<'extend sys { m1() is { var s: string = str_pad("hello world",14); print s;

str An expression of typestring.

length An integer representing the desired length, no greater than 4000.

e Libraries Preliminary 4-75

Page 212: Prelim e Lib

Predefined Routines str_replace()

larf the

r

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.16 str_replace()

Purpose

Replace a substring in a string with another string

Category

Routine

Syntax

str_replace(str: string, regular-exp: string, replacement: string): string

Syntax example:

var s: string = str_replace("crc32", "/(.*32)/", "32_flip");

Parameters

Description

A new copy of the original string is created, and then all the matches of the reguexpression are replaced by the replacement string. If no match is found, a copy osource string is returned.

str An expression of typestring.

regular-exp An AWK-style regular expression, surrounded by slashes.

replacement The string that you want to replace all occurrences of the regulaexpression.

4-76 Preliminary e Libraries

Page 213: Prelim e Lib

str_replace() Predefined Routines

ithters

To incorporate the matched substrings in thereplacement string, use back-slashescaped numbers \1, \2, …

You can mark the portions of the regular expressions that you want to replace wparentheses. For example, the following regular expression marks all the characafter “on”, up to and including “th” to be replaced.

"/on(.*th)/"

Example 1

<'extend sys {

m1() is {var new_str : string = str_replace("testing one two \

three", "/on(.*th)/" , "f");print new_str;

};};'>

Example 2

This example uses \1, \2:

<'extend sys { m1() is {

var new_str : string = str_replace("A saw B","/(.*) saw (.*)/" , "\2 was seen by \1");

print new_str; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

e Libraries Preliminary 4-77

Page 214: Prelim e Lib

Predefined Routines str_split()

ns a

in

4.8.17 str_split()

Purpose

Split a string to substrings

Category

Routine

Syntax

str_split(str: string, regular-exp: string): list of string

Syntax example:

var s: list of string = str_split("first-second-third", "-");

Parameters

Description

Splits the original string on each occurrence of the regular expression, and returlist of strings. If the regular expression occurs at the beginning or the end of theoriginal string, an empty string is returned.

If the regular expression is an empty string, it has the effect of removing all blanksthe original string.

Example 1

<'extend sys { m1() is {

var s: list of string = str_split(" A B C", "/ +/");print s;

};};'>

str An expression of typestring.

regular-exp An AWK-style regular expression that specifies where to split thestring.

4-78 Preliminary e Libraries

Page 215: Prelim e Lib

str_split_all() Predefined Routines

ns a

e

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.18 str_split_all()

Purpose

Split a string to substrings, including separators

Category

Routine

Syntax

str_split_all(str: string, regular-exp: string): list of string

Syntax example:

var s: list of string = str_split_all(" A B C", "/ +/");

Parameters

Description

Splits the original string on each occurrence of the regular expression, and returlist of strings. If the regular expression occurs at the beginning or the end of theoriginal string, an empty string is returned.

This routine is similar tostr_split(), except that it includes the separators in theresulting list of strings.

Example

<'

str An expression of typestring.

regular-exp An AWK-style regular expression that specifies where to split thstring.

e Libraries Preliminary 4-79

Page 216: Prelim e Lib

Predefined Routines str_sub()

he

extend sys { m1() is {

var s: list of string = str_split_all(" A B C", "/ +/"); print s; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.19 str_sub()

Purpose

Extract a substring from a string

Category

Routine

Syntax

str_sub(str: string, from: int, length: int): string

Syntax example:

var dir: string = str_sub("/rtests/test32/tmp", 8, 6);

Parameters

str An expression of typestring.

from The index position from which to start extracting. The first character in tstring is at index 0.

length An integer representing the number of characters to extract.

4-80 Preliminary e Libraries

Page 217: Prelim e Lib

str_upper() Predefined Routines

the

Description

Returns a substring of the specified length from the original string, starting from specified index position.

Example

<'extend sys {

m1() is {var dir: string = str_sub("/rtests/test32/tmp", 8, 6);print dir;

};};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.20 str_upper()

Purpose

Convert a string to uppercase

Category

Routine

Syntax

str_upper(str: string): string

Syntax example:

var upper: string = str_upper("lower");

e Libraries Preliminary 4-81

Page 218: Prelim e Lib

Predefined Routines to_string()

case

Parameter

Description

Returns a copy of the original string, converting all lower case characters to uppercharacters.

Example

<'extend sys { m1() is { var upper: string = str_upper("lower"); print upper; };};'>

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.8.21 to_string()

Purpose

Convert any expression to a string

Category

Method

Syntax

exp.to_string(): string

Syntax example:

print pkts[0].to_string();

str An expression of typestring.

4-82 Preliminary e Libraries

Page 219: Prelim e Lib

to_string() Predefined Routines

teach

adix

Parameter

Description

This method can be used to convert any type to a string.

If the expression is a struct expression, theto_string() method returns a uniqueidentification string for each struct instance.

If the expression is a list of strings, theto_string() method is called for each elemenin the list. The string returned contains all the elements with a newline between element.

If the expression is a list of any type exceptstring, theto_string() method returns astring containing all the elements with a space between each element.

If the expression is a numeric type, the expression is converted using the current rwith the radix prefix.

If the expression is a string, theto_string() method returns the string.

If the expression is an enumerated or a Boolean type, theto_string() method returnsthe value.

Example

<'struct pkt { protocol: [ethernet, atm, other]; legal : bool; data[2]: list of byte;};

extend sys { pkts[5]: list of pkt; m1() is { var slist: list of string = {"strA";"strB";"strC"}; print pkts[0].to_string(); print pkts[0].data.to_string(); print pkts[0].protocol.to_string(); print pkts[0].legal.to_string(); print slist.to_string(); };};'>

exp A legaleexpression.

e Libraries Preliminary 4-83

Page 220: Prelim e Lib

Predefined Routines Output Routines

reen

een

inted.

See Also

• “String Routines” on page 4-57

• “Predefined Routines Overview” on page 4-1

4.9 Output RoutinesThe predefined output routines print formatted and unformatted information to the scand to open log files. The following sections describe the output routines:

• out() on page 4-84

• outf() on page 4-85

4.9.1 out()

Purpose

Print expressions to output, with a new line at the end

Category

Routine

Syntax

out(exp, …)

Syntax example:

out("pkts[1].data is ", pkts[1].data);

Parameter

Description

Callsto_string() to convert each expression to a string and prints them to the scr(and to the log file if it is open), followed by a new line.

exp A list of zero or moreeexpressions. String expressions must be encloseddouble quotes. If the expression is a struct instance, the struct ID is prin

4-84 Preliminary e Libraries

Page 221: Prelim e Lib

outf() Predefined Routines

Example

This first example shows that if the expression is a struct,out() prints the ID of thestruct. If the expression is a list,out() prints each element of the list from left to right,starting with the element with the lowest index. If no expression is passed,out() printsa new line.

struct pkt { protocol: [ethernet, atm, other]; legal : bool; data[2]: list of byte;

};

extend sys { pkts[5]: list of pkt; m1() is { out(); out("ID of first packet is ", pkts[0]); out("pkts[1].data is ", pkts[1].data); out("pkts[1].data[0] is ", pkts[1].data[0]); out(); };};

See Also

• outf() on page 4-85

• “Predefined Routines Overview” on page 4-1

4.9.2 outf()

Purpose

Print formatted expressions to output, with no new line at the end

Category

Routine

e Libraries Preliminary 4-85

Page 222: Prelim e Lib

Predefined Routines outf()

if it

and

ethe

Syntax

outf(format-string, exp, …)

Syntax example:

outf("%s %#x","pkts[1].data[0] is ", pkts[1].data[0]);

Parameters

Description

Callsto_string() on page 4-82 to convert each expression to a string using thecorresponding format string and then prints them to the screen (and to the log fileis open).

To add a new line, add the \n characters to the format string.

Notes

• If the number and type of masks in the format string does not match the numbertype of expressions, an error is issued.

Example 1

This example has similar results to the in the description ofout() on page 4-84. Notethatoutf() allows you to add the new lines where needed.

extend sys { pkts[5]: list of pkt; m1() is { outf("%s %s\n","pkts[0] ID is ", pkts[0]);

outf("%s %#x","pkts[1].data[0] is ", pkts[1].data[0]); };};

format-string A string enclosed in double quotes and containing a standard Cformatting mask for each expression. See “Format String” onpage 4-88 for more information.

exp A list of one or more legaleexpressions. String expressions must benclosed in double quotes. If the expression is a struct instance,struct ID is printed. If the expression is a list, an error is issued.

4-86 Preliminary e Libraries

Page 223: Prelim e Lib

outf() Predefined Routines

wide

Example 2

This example shows the control over formatting of strings thatoutf() allows. Thefields have been enclosed in double “:” characters so that you can easily see howthe field is.

<'extend sys { m1() is { outf(":%s:\n", "hello world"); outf(":%15s:\n", "hello world"); outf(":%-15s:\n", "hello world"); outf(":%.8s:\n", "hello world"); outf(":%08d:\n", 12); };};'>

See Also

• out() on page 4-84

• “Predefined Routines Overview” on page 4-1

e Libraries Preliminary 4-87

Page 224: Prelim e Lib

Predefined Routines Format String

he

ot

ers

er,

4.9.3 Format String

The format string for theoutf() and for theappendf() routine uses the following syntax:

"%[0|-][digit1][.[digit2]](s|d|[#]x|b|o|u) "

4.10 OS Interface RoutinesThe routines in this section enable use of operating system commands from within teprogramming language. These routines work on all supported operating systems.

The OS interface routines in this section are:

• spawn() on page 4-89

• spawn_check() on page 4-90

• system() on page 4-91

• output_from() on page 4-92

• output_from_check() on page 4-93

• get_symbol() on page 4-94

• date_time() on page 4-95

0 Pads with 0 instead of blanks.

- Aligns left. The default is to align right.

digit1 Specifies the minimum number of characters and digits. If there are nenough characters and digits, the expression is padded.

digit2 Specifies the maximum number of characters and digits. Extra charactand digits are truncated.

s Converts the expression to a string.

d Prints a numeric expression in decimal format.

[#]x Prints a numeric expression in hex format. With the optional # charactadds 0x before the number.

b Prints a numeric expression in binary format.

o Prints a numeric expression in octal format.

u Prints integers (int anduint ) in uint format.

4-88 Preliminary e Libraries

Page 225: Prelim e Lib

spawn() Predefined Routines

tes the

rs

4.10.1 spawn()

Purpose

Send commands to the operating system

Category

Pseudo-routine

Syntax

spawn(“command”, …)

Syntax example:

spawn("touch error.log;","grep Error test1.elog > \error.log");

Parameter

Description

Takes a variable number of parameters, concatenates them together, and execustring result as an operating system command viasystem().

Example

<'extend sys {

m1() is {spawn("touch error.log;","grep Error test.elog > \

error.log");};

};'>

See Also

• “OS Interface Routines” on page 4-88

command A list of zero or more system commands, with or without parameteand enclosed in double quotes.

e Libraries Preliminary 4-89

Page 226: Prelim e Lib

Predefined Routines spawn_check()

in

• “Predefined Routines Overview” on page 4-1

4.10.2 spawn_check()

Purpose

Send a command to the operating system and report error

Category

Routine

Syntax

spawn_check(“command”)

Syntax example:

spawn_check("grep Error test.elog >& error.log");

Parameter

Description

Executes a single string as an operating system command viasystem(), then callserror() if the execution of the command returned an error status.

Example

<'extend sys {

m1() is {spawn_check("grep Error test.elog >& error.log");

};};'>

command A single system command, with or without parameters and encloseddouble quotes.

4-90 Preliminary e Libraries

Page 227: Prelim e Lib

system() Predefined Routines

in

See Also

• “OS Interface Routines” on page 4-88

• “Predefined Routines Overview” on page 4-1

4.10.3 system()

Purpose

Send a command to the operating system

Category

Routine

Syntax

system(“command”) : int

Syntax example:

stub = system("cat cpu.v");

Parameter

Description

Executes the string as an operating system command using the Csystem()call andreturns the result.

Example

<'extend sys { m1() is { var stub: int; stub = system("cat cpu.v"); print stub; };

command A single system command, with or without parameters and encloseddouble quotes.

e Libraries Preliminary 4-91

Page 228: Prelim e Lib

Predefined Routines output_from()

list of

d

};'>

See Also

• “OS Interface Routines” on page 4-88

• “Predefined Routines Overview” on page 4-1

4.10.4 output_from()

Purpose

Collect the results of a system call

Category

Routine

Syntax

output_from(“ command”) : list of string

Syntax example:

log_list = output_from("ls *log");

Parameter

Description

Executes the string as an operating system command and returns the output as astring. Under UNIX,stdout andstderr go to the string list.

Example

<'extend sys { m1() is {

command A single system command, with or without parameters and enclosein double quotes.

4-92 Preliminary e Libraries

Page 229: Prelim e Lib

output_from_check() Predefined Routines

t ofs.

var log_list: list of string; log_list = output_from("ls *log"); print log_list; };};'>

See Also

• “OS Interface Routines” on page 4-88

• “Predefined Routines Overview” on page 4-1

4.10.5 output_from_check()

Purpose

Collect the results of a system call and check for errors

Category

Routine

Syntax

output_from_check(“command”) : list of string

Syntax example:

log_list = output_from_check("ls *.log");

Parameter

Description

Executes the string as an operating system command, returns the output as a lisstring, and then callserror() if the execution of the command returns an error statuUnder UNIX,stdout andstderr go to the string list.

command A single system command with or without parameters andenclosed in double quotes.

e Libraries Preliminary 4-93

Page 230: Prelim e Lib

Predefined Routines get_symbol()

Example

<'extend sys { m1() is { var log_list: list of string; log_list = output_from_check("ls *.log"); print log_list; };};'>

See Also

• “OS Interface Routines” on page 4-88

• “Predefined Routines Overview” on page 4-1

4.10.6 get_symbol()

Purpose

Get UNIX environment variable

Category

Routine

Syntax

get_symbol(“env_variable”) : string

Syntax example:

current_dir = get_symbol("PWD");

Parameter

Description

Returns the environment variable as a string.

env-variable A UNIX environment variable enclosed in double quotes.

4-94 Preliminary e Libraries

Page 231: Prelim e Lib

date_time() Predefined Routines

Example

<'extend sys {

m1() is {var current_dir: string;current_dir = get_symbol("PWD");print current_dir;

};};'>

See Also

• “OS Interface Routines” on page 4-88

• “Predefined Routines Overview” on page 4-1

4.10.7 date_time()

Purpose

Retrieve current date and time

Category

Routine

Syntax

date_time(): string

Syntax example:

print date_time();

Parameters

None

Description

Returns the current date and time as a string.

e Libraries Preliminary 4-95

Page 232: Prelim e Lib

Predefined Routines File Routines

ost

Example

extend sys {m1() is {

print date_time();};run()is also {m1()};

};

See Also

• “OS Interface Routines” on page 4-88

• “Predefined Routines Overview” on page 4-1

4.11 File RoutinesThe global struct namedfiles contains predefined routines for working with files. Thischapter contains information about using files and the predefined file routines. Like mglobal objects, the predefined routines in thefilesstruct are not meant to be extended withis also or is only.

General information about working with files is provided in the following sections.

• “File Descriptors” on page 4-97

Syntax for the predefined file routines is described in the following sections.

• “Low-Level File Routines” on page 4-97

• “General File Routines” on page 4-110

• “Reading and Writing Structs” on page 4-133

See Also

• “File Iteration Actions” on page 8-17 in theeLanguage Reference Manual

• “String Routines” on page 4-57

4-96 Preliminary e Libraries

Page 233: Prelim e Lib

File Descriptors Predefined Routines

file.

4.11.1 File Descriptors

For every open file, a file descriptor struct exists which contains information about theThe routinefiles.open()on page 4-102 returns the file descriptor as a variable of typefile.The name of the file variable is used in low-level file operations such as thefiles.read(),files.write() andfiles.flush() routines. These routines are described in “Low-Level FileRoutines” on page 4-97.

4.11.2 Low-Level File Routines

This section contains descriptions of the file routines that use file descriptor structs.

To write strings to a file, the simplest routine isfiles.write_string_list() on page 4-132.

The following file routines are described in this section.

• files.add_file_type() on page 4-98

• files.close() on page 4-99

• files.flush() on page 4-101

• files.open() on page 4-102

• files.read() on page 4-104

• files.read_lob() on page 4-106

• files.write() on page 4-107

• files.write_lob() on page 4-109

See Also

• “File Routines” on page 4-96

• “General File Routines” on page 4-110

• “Reading and Writing Structs” on page 4-133

e Libraries Preliminary 4-97

Page 234: Prelim e Lib

Predefined Routines files.add_file_type()

e

4.11.3 files.add_file_type()

Purpose

Get a file name

Category

Method

Syntax

files.add_file_type(file-name: string, file-ext: string, exists: bool): string

Syntax example:

var fv: string;fv = files.add_file_type("fname", ".e", FALSE);

Parameters

Description

Returns a string holding the file name.

This routine assigns a string consisting offile-nameandfile-extto astring variable. Iffile-namealready contains an extension, thenfile-extis ignored. Iffile-extis empty, thefile-name is used with no extension.

If exists is FALSE, the routine returns the file-name string without checking for thexistence of the file.

If exists is TRUE, the routine checks to see if there is a file that matches thefile-namein the current directory.

Example

The following assigns ex_file.e to the f1 variable, without checking to see if theex_file.e file exists.

file-name The name of the file to access. A wild card pattern can be used.

file-ext The file extension, including the dot (.) may be empty.

exists Sets checking for existence of the file.

4-98 Preliminary e Libraries

Page 235: Prelim e Lib

files.close() Predefined Routines

struct f_str {!file_list: list of string;AppendFileToList(ex_file: string) is {

var f1: string;f1 = files.add_file_type(ex_file, ".e", FALSE);file_list.add(f1);

};};extend sys {

fi: f_str;run() is also {

fi.AppendFileToList("ex_file");};

};

See Also

• files.file_exists() on page 4-116

4.11.4 files.close()

Purpose

Close a file

Category

Method

Syntax

files.close(file: file-descriptor)

Syntax example:

files.close(f_desc);

Parameter

file The file descriptor of the file to be closed.

e Libraries Preliminary 4-99

Page 236: Prelim e Lib

Predefined Routines files.close()

on

edhetents

o

ne.

Description

Flushes the file buffer and closes the file specified byfile-descriptor. The file mustpreviously have been opened usingfiles.open() on page 4-102. When no furtheractivity is planned for a file, it should be closed to prevent unintentional operationsits contents.

Example

The WrAndFlush() user-defined method in the following example opens a file nam“ex_file.txt” as the m_file variable, writes a line to the file, and then closes the file. TRFile() user-defined method then opens the same file for reading and reads its coninto the m_string variable.

Thefiles.flush() routine writes the “AaBaCa 0123” string to the disk immediately, sthat the read routine can read it. If there were nofiles.close() routine (orfiles.flush()routine) following the write, the data would not be in disk file when the read was do

struct f_s_1 {WrAndFlush(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "w", "Text file");files.write(m_file, "AaBaCa 0123");files.close(m_file);

};RFile(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "r", "Text file");var r_chk: bool;var m_string: string;r_chk = files.read(m_file, m_string);if r_chk then {print m_string}

else {out("file not read")};};

};extend sys {

f_si_1: f_s_1;run() is also {

f_si_1.WrAndFlush("ex_file.txt");f_si_1.RFile("ex_file.txt");

};};

See Also

• files.open() on page 4-102

4-100 Preliminary e Libraries

Page 237: Prelim e Lib

files.flush() Predefined Routines

hen

ake

ede’sing

• files.flush() on page 4-101

4.11.5 files.flush()

Purpose

Flush file buffers

Category

Method

Syntax

files.flush(file: file-descriptor)

Syntax example:

files.flush(a_file);

Parameter

Description

Flushes all the operating system buffers associated withfile to the disk.

File data is buffered in memory and only written to disk at certain times, such as wthe file is closed. This routine causes data to be written to the disk immediately,instead of later when the file is closed.

This can be useful if two processes are using the same disk file, for example, to msure that the current data from one process is written to the file before the otherprocess reads from the file.

Example

The WrAndFlush() user-defined method in the following example opens a file nam“ex_file.txt” as the m_file variable, writes a line to the file, and then flushes the filbuffer to disk. The RFile() user-defined method then opens the same file for readand reads its contents into the m_string variable.

file The file descriptor of the file to flush.

e Libraries Preliminary 4-101

Page 238: Prelim e Lib

Predefined Routines files.open()

o

ne.

Thefiles.flush() routine writes the “AaBaCa 0123” string to the disk immediately, sthat the read routine can read it. If there were nofiles.flush() routine (orfile.close()routine) following the write, the data would not be in disk file when the read was do

struct f_s_2 {WrAndFlush(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "w", "Text file");files.write(m_file, "AaBaCa 0123");files.flush(m_file);

};RFile(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "r", "Text file");var r_chk: bool;var m_string: string;r_chk = files.read(m_file, m_string);if r_chk then {print m_string}

else {out("file not read")};};

};extend sys {

f_si_2: f_s_2;run() is also {

f_si_2.WrAndFlush("ex_file.txt");f_si_2.RFile("ex_file.txt");

};};

See Also

• files.open() on page 4-102

• files.flush() on page 4-101

4.11.6 files.open()

Purpose

Open a file for reading or writing or both

Category

Method

4-102 Preliminary e Libraries

Page 239: Prelim e Lib

files.open() Predefined Routines

g to

Syntax

files.open(file-name: string, mode: string, file-role: string): file

Syntax example:

var m_file: file;m_file = files.open("a_file.txt", "r", "Text File");

Parameters

Description

Opens the file for reading, writing, both reading and writing, or append, accordinmode (r, w, rw, a) and returns the file descriptor of the file. Thefile-role is a descriptionof the file, for example, “source file”.

Example 1

The following example opens a file named “/users/a_file.txt” in write mode as filevariable m_file, writes a line to the file, and then closes the file.

struct f_3_str {RdWrFile(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "w", "Text file");files.write(m_file, "HEADER");files.close(m_file);

};};

file-name The name of the file to open.

mode The read/write mode for the file. The mode may be one of thefollowing.

r - open the file for reading.

w - open the file for writing (overwrite the existing contents)

rw - open the file for reading and writing (add to the end of theexisting contents)

a - open the file for appending (add to the end of the existingcontents)

file-role A text description used in error messages about the file.

e Libraries Preliminary 4-103

Page 240: Prelim e Lib

Predefined Routines files.read()

extend sys {fi_3: f_3_str;run() is also {

fi_3.RdWrFile("/users/a_file.txt");};

};

See Also

• files.add_file_type() on page 4-98

• files.close() on page 4-99

• files.write() on page 4-107

4.11.7 files.read()

Purpose

Read an ASCII line from a file

Category

Method

Syntax

files.read(file: file-descriptor, string-var: *string): bool

Syntax example:

r_b = files.read(f_desc, m_string);

Parameters

file The file descriptor of the file that contains the text to read.

string-var A variable into which the ASCII text will be read.

4-104 Preliminary e Libraries

Page 241: Prelim e Lib

files.read() Predefined Routines

le

ple,

ones it

Description

Reads a line of text from a file into a string variable ine. The file must have beenopened withfiles.open()on page 4-102. The line from the file is read into the variabwithout the final \n newline character.

The routine returns TRUE on success. If the method cannot read a line (for examif the end of the file is reached), it returns FALSE.

Example

The following example opens a file named “a_file.txt” as variable m_f, reads linesby one from the file into a variable named “m_string”, and displays each string areads it.

struct f_s_3 {RFile(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "r", "Text file");var r_chk: bool;var m_string: string;r_chk = files.read(m_file, m_string);out("The first line is: ", m_string);while files.read(m_file, m_string) {

out("The next line is: ", m_string);};files.close(m_file);

};};extend sys {

f_si_3: f_s_3;run() is also {

f_si_3.RFile("ex_file.txt");};

};

See Also

• for each line in file on page 8-17 in theeLanguage Reference Manual

• files.open() on page 4-102

• files.read_lob() on page 4-106

• files.read_ascii_struct() on page 4-134

• files.read_binary_struct() on page 4-135

e Libraries Preliminary 4-105

Page 242: Prelim e Lib

Predefined Routines files.read_lob()

uste

f,

4.11.8 files.read_lob()

Purpose

Read from a binary file into a list of bits

Category

Method

Syntax

files.read_lob(file: file-descriptor, size-in-bits: int): list of bit

Syntax example:

var m_file: file = files.open("a_file.dat", "r", "Data");var b_l: list of bit;b_l = files.read_lob(m_file, 32);

Parameters

Description

Reads data from a binary file into a list of bits and returns the list of bits. The file malready have been opened withfiles.open() on page 4-102. To read an entire file, usUNDEF as thesize-in-bits.

Example 1

The following example opens a file named “a_file.dat” with the file descriptor m_and reads the first 16 bits from the file into a list of bits named “b_list”.

struct f_4 {b_list: list of bit;RdLOB(ex_file: string) is {

var m_f: file = files.open(ex_file, "r", "Data");b_list = files.read_lob(m_f, 16);files.close(m_f);

};

file The file descriptor of the file to read from.

size-in-bits The number of bits to read. Should be a multiple of 8.

4-106 Preliminary e Libraries

Page 243: Prelim e Lib

files.write() Predefined Routines

};extend sys {

fi_4: f_4;run() is also {

fi_4.RdLOB("a_file.dat");};

};

See Also

• files.close() on page 4-99

• files.open() on page 4-102

• files.write_lob() on page 4-109

4.11.9 files.write()

Purpose

Write a string to file

Category

Method

Syntax

files.write(file: file-descriptor, text: string)

Syntax example:

files.write(m_file, "Test Procedure");

Parameters

file The file descriptor of the file to write into.

text The text to write to the file.

e Libraries Preliminary 4-107

Page 244: Prelim e Lib

Predefined Routines files.write()

ally

To

file.e

Description

Adds a string to the end of an existing, open file. A new-line \n is added automaticat the end of the string. The file must already have been opened usingfiles.open() onpage 4-102. If the file is not open, an error message is issued.

If the file is opened in write mode (w), this routine overwrites the existing contents.avoid overwriting the existing file, open it in append mode (a).

Note

The >> concatenation operator can be used to append information to the end of aFor example, the followingset logcommand concatenates information logged for thcurrent test onto the end of the previously written file named “test_a.elog”.

set log >> test_a.elog

Example

The following example opens a file named “/users/a_file.txt” in write mode as filevariable m_file, writes two lines to the file, and then closes the file.

struct f_s_5 {WrFile(ex_file: string) is {

var m_file: file;m_file = files.open(ex_file, "w", "Text file");files.write(m_file, "FILE 1");files.write(m_file, "Test 1");files.close(m_file);

};};extend sys {

f_si_5: f_s_5;run() is also {

f_si_5.WrFile("/users/a_file.txt");};

};

See Also

• files.close() on page 4-99

• files.open() on page 4-102

4-108 Preliminary e Libraries

Page 245: Prelim e Lib

files.write_lob() Predefined Routines

the

2”

4.11.10 files.write_lob()

Purpose

Write a list of bits to a binary file

Category

Method

Syntax

files.write_lob(file: file-descriptor, bit-list: list of bit)

Syntax example:

var m_file: file = files.open("a_f.dat", "w", "My data");var b_l: list of bit;files.write_lob(m_file, b_l);

Parameters

Description

Writes all the bits in the bit list (whose size should be a multiple of 8) to the end offile specified byfile. The file must already have been opened withfiles.open() onpage 4-102.

Lists of bits are always written in binary format.

Example

The following example opens a file named “a_file.dat” as file descriptor m_f_1 inwrite mode (w). Thefiles.write_lob() routine writes the contents of a list of bitsnamed “b_list” into the file.

Thefiles.read_lob() routine reads the contents of the file into a variable named “b_as a list of bits, which is then printed.

file The file descriptor of the file to write into.

bit-list A list of bits to write to the file. The size of the list must be a multipleof 8 bits.

e Libraries Preliminary 4-109

Page 246: Prelim e Lib

Predefined Routines General File Routines

struct f_5_str {RdWrLOB(ex_file: string) is {

var b_list: list of bit = {1; 0; 1; 1; 0; 1 ;1; 1};var m_f_1: file = files.open(ex_file, "w", "Data");files.write_lob(m_f_1, b_list);files.close(m_f_1);

var b_2: list of bit;var m_f_2: file = files.open(ex_file, "r", "Data");b_2 = files.read_lob(m_f_2, 8);print b_2 using radix=bin,

list_starts_on_right=FALSE;};

};extend sys {

fi_5: f_5_str;run() is also {

fi_5.RdWrLOB("a_file.dat");};

};

See Also

• files.close() on page 4-99

• files.open() on page 4-102

• files.read_lob() on page 4-106

4.11.11 General File Routines

This sections contains descriptions of the following routines.

• files.file_age() on page 4-111

• files.file_append() on page 4-113

• files.file_copy() on page 4-114

• files.file_delete() on page 4-115

• files.file_exists() on page 4-116

• files.file_extension() on page 4-118

• files.file_is_dir() on page 4-119

4-110 Preliminary e Libraries

Page 247: Prelim e Lib

files.file_age() Predefined Routines

• files.file_is_link() on page 4-121

• files.file_is_readable() on page 4-122

• files.file_is_regular() on page 4-123

• files.file_is_temp() on page 4-125

• files.file_is_text() on page 4-126

• files.file_rename() on page 4-128

• files.file_size() on page 4-129

• files.new_temp_file() on page 4-130

• files.write_string_list() on page 4-132

See Also

• “File Routines” on page 4-96

• “Low-Level File Routines” on page 4-97

• “Reading and Writing Structs” on page 4-133

4.11.12 files.file_age()

Purpose

Get a file’s modification date

Category

Method

Syntax

files.file_age(file-name: string): int

Syntax example:

var f_data: int;f_data = files.file_age("f.txt");

e Libraries Preliminary 4-111

Page 248: Prelim e Lib

Predefined Routines files.file_age()

totne

hee

Parameter

Description

Returns the modification date of the file as an integer. This routine can be used compare the modification dates of files. The integer returned by the routine is norecognizable as a date, but is a unique number derived from the file’s modificatiodate. If the modification date includes the time of day, the time is factored into thnumber the routine returns. Newer files produce larger numbers than older files.

Example

In the following example, thefiles.file_age() routine derives a number from themodification date of a file whose variable is my_f. The routine is called twice in trun() method in thesys extension, once for each of two files. The age numbers arprinted and compared to find the largest.

struct f_6_str {FAge(ex_file: string): int is {

var my_f: string;var my_age: int;my_f = files.add_file_type(ex_file, "", TRUE);my_age = files.file_age(my_f);outf("file name: %s, age: %d\n", ex_file, my_age);return my_age;

}};extend sys {

fi_6: f_6_str;run() is also {

var my_age_1: int = fi_6.FAge("f_1.e");var my_age_2: int = fi_6.FAge("f_2.e");var oldest: int = max(my_age_1, my_age_2);print oldest;

};};

See Also

• files.add_file_type() on page 4-98

file-name The file whose age is to be found.

4-112 Preliminary e Libraries

Page 249: Prelim e Lib

files.file_append() Predefined Routines

file.e

4.11.13 files.file_append()

Purpose

Append files

Category

Method

Syntax

files.file_append(from-file-name: string, to-file-name: string)

Syntax example:

files.file_append(f_1, f_2);

Parameters

Description

Adds the contents of the file namedfrom-file-name to the end of the file namedto-file-name. If neither of the files exists, an error is issued.

Note

The >> concatenation operator can be used to append information to the end of aFor example, the followingset logcommand concatenates information logged for thcurrent test onto the end of the previously written file named test_a.elog.

set log >> test_a.elog

Example

The following example appends the contents of f_2.txt to the end of f_1.txt.

struct f_7_str {FAppend(ex_file_1: string, ex_file_2: string) is {

var my_f_1: string;

from-file-name The name of the file that will be appended to the to-file.

to-file-name The name of the file to which the from-file will be appended.

e Libraries Preliminary 4-113

Page 250: Prelim e Lib

Predefined Routines files.file_copy()

my_f_1 = files.add_file_type(ex_file_1, ".txt",TRUE);

var my_f_2: string;my_f_2 = files.add_file_type(ex_file_2, ".txt",

TRUE);files.file_append(my_f_1, my_f_2);

}};extend sys {

fi_7: f_7_str;run() is also {

fi_7.FAppend("f_2.txt", "f_1.txt");};

};

See Also

• files.add_file_type() on page 4-98

4.11.14 files.file_copy()

Purpose

Create a copy of a file

Category

Method

Syntax

files.file_copy(from-file-name: string, to-file-name: string)

Syntax example:

files.file_copy("file_1.txt", "tmp_file.txt");

Parameters

from-file-name The name of the file to copy.

to-file-name The name of the copy of the file.

4-114 Preliminary e Libraries

Page 251: Prelim e Lib

files.file_delete() Predefined Routines

Description

Makes a copy of the file namedfrom-file-name, with the nameto-file-name. If a filealready exists with theto-file-name, the contents of that file are replaced by thecontents of the file namedfrom-file-name. If the file namedfrom-file-name does notexist, an error is issued.

Example

The following example copies the contents of f_1.txt into f_1.bak.

struct f_str_8 {FCp(ex_file_1: string, ex_file_2:string) is {

files.file_copy(ex_file_1, ex_file_2);};

};extend sys {

fi_8: f_str_8;run() is also {

fi_8.FCp("f_1.txt", "f_1.bak");};

};

See Also

• files.file_rename() on page 4-128

4.11.15 files.file_delete()

Purpose

Delete a file

Category

Method

Syntax

files.file_delete(file-name: string)

Syntax example:

e Libraries Preliminary 4-115

Page 252: Prelim e Lib

Predefined Routines files.file_exists()

files.file_delete("run_1.log");

Parameter

Description

Deletes a specified file.

Example

The following example deletes the f_1.txt file.

struct f_str_9 {FDel(ex_file: string) is {

var my_f_1: string;my_f_1 = files.add_file_type(ex_file, ".txt", TRUE);files.file_delete(my_f_1);

};};extend sys {

fi_9: f_str_9;run() is also {

fi_9.FDel("f_1.txt");};

};

See Also

• files.file_exists() on page 4-116

4.11.16 files.file_exists()

Purpose

Check if a file exists

Category

Method

file-name The file to be deleted.

4-116 Preliminary e Libraries

Page 253: Prelim e Lib

files.file_exists() Predefined Routines

ify.

Syntax

files.file_exists(file-name: string): bool

Syntax example:

var f_e: bool;f_e = files.file_exists("file_1.e");

Parameter

Description

Checks if thefile-name exists in the file system. Returns TRUE if the file exists orissues an error if it does not exist. Also returns TRUE if the file is a directory. Theroutine does not check whether the file is readable or not.

Note

This routine only checks for the existence of a file with the exact name you specFor a routine that can check for multiple similarly named files, seefiles.add_file_type() on page 4-98.

Example

The following example prints “file f_1.txt exists” if there is a file named “f_1.txt” inthe current directory. If the file does not exist, an error is issued.

struct f_str_10 {FEx(ex_file: string) is {

var my_f_1: string;my_f_1 = files.add_file_type(ex_file, ".txt", TRUE);var f_exists: bool;f_exists = files.file_exists(my_f_1);if f_exists then {outf("file %s exists\n", my_f_1)};

};};extend sys {

fi_10: f_str_10;run() is also {

fi_10.FEx("f_1.txt");};

};

file-name The name of the file to be checked.

e Libraries Preliminary 4-117

Page 254: Prelim e Lib

Predefined Routines files.file_extension()

after

See Also

• files.add_file_type() on page 4-98

• files.file_is_dir() on page 4-119

• files.file_is_readable() on page 4-122

• files.file_is_regular() on page 4-123

• files.file_is_link() on page 4-121

• files.file_is_text() on page 4-126

4.11.17 files.file_extension()

Purpose

Get the extension of a file

Category

Method

Syntax

files.file_extension(file-name: string): string

Syntax example:

var f_ext: string;f_ext = files.file_extension("f_1.exa");

Parameter

Description

Returns a string containing the file extension, which is the sequence of charactersthe last period (.).

file-name The name of the file.

4-118 Preliminary e Libraries

Page 255: Prelim e Lib

files.file_is_dir() Predefined Routines

Example

The following example prints “get_ext = “.bak””.

struct f_str_11 {FExten(ex_file: string) is {

var get_ext: string;get_ext = files.file_extension(ex_file);print get_ext;

};};extend sys {

fi_11: f_str_11;run() is also {

fi_11.FExten("f_1.bak");};

};

See Also

• files.add_file_type() on page 4-98

• files.file_exists() on page 4-116

4.11.18 files.file_is_dir()

Purpose

Check if a file is a directory

Category

Method

Syntax

files.file_is_dir(file-name: string): bool

Syntax example:

var is_d: bool;is_d = files.file_is_dir("a_fil");

e Libraries Preliminary 4-119

Page 256: Prelim e Lib

Predefined Routines files.file_is_dir()

not

Parameter

Description

Returns TRUE if the file exists and is a directory. Returns FALSE if the file does exist or is not a directory.

Example

The following example prints TRUE if f_1 is a directory, or FALSE if f_1 does notexist or if it is not a directory.

struct f_str_12 {F_is_Dir(ex_file: string) is {

var is_dir: bool;is_dir = files.file_is_dir(ex_file);outf("%s is_dir = %s\n", ex_file, is_dir);

};};extend sys {

fi_12: f_str_12;run() is also {

fi_12.F_is_Dir("f_1");};

};

See Also

• files.file_exists() on page 4-116

• files.file_is_link() on page 4-121

• files.file_is_readable() on page 4-122)

• files.file_is_regular() on page 4-123

• files.file_is_temp() on page 4-125

• files.file_is_text() on page 4-126

file-name The name of the file to be checked.

4-120 Preliminary e Libraries

Page 257: Prelim e Lib

files.file_is_link() Predefined Routines

es

4.11.19 files.file_is_link()

Purpose

Check if a file is a symbolic link

Category

Method

Syntax

files.file_is_link(file-name: string): bool

Syntax example:

var is_l: bool;is_l = files.file_is_link("a_fil");

Parameter

Description

Returns TRUE if the file exists and is a symbolic link. Returns FALSE if the file donot exist or is not a symbolic link.

Example

The following example prints TRUE if f_1 is a symbolic link, or FALSE if f_1 doesnot exist or if it is not a symbolic link.

struct f_str_13 {F_is_Link(ex_file: string) is {

var is_link: bool;is_link = files.file_is_link(ex_file);outf("%s is_link = %s\n", ex_file, is_link);

};};extend sys {

fi_13: f_str_13;run() is also {

fi_13.F_is_Link("f_1");

file-name The name of the file to be checked.

e Libraries Preliminary 4-121

Page 258: Prelim e Lib

Predefined Routines files.file_is_readable()

};};

See Also

• files.file_exists() on page 4-116

• files.file_is_dir() on page 4-119

• files.file_is_readable() on page 4-122)

• files.file_is_regular() on page 4-123

• files.file_is_temp() on page 4-125

• files.file_is_text() on page 4-126

4.11.20 files.file_is_readable()

Purpose

Check if a file is readable

Category

Method

Syntax

files.file_is_readable(file-name: string): bool

Syntax example:

var is_rd: bool;is_rd = files.file_is_readable("a_fil");

Parameter

file-name The name of the file to be checked.

4-122 Preliminary e Libraries

Page 259: Prelim e Lib

files.file_is_regular() Predefined Routines

ot

es

Description

Returns TRUE if the file exists and is readable. Returns FALSE if the file does nexist or is not readable.

Example

The following example prints TRUE if f_1.dat is readable, or FALSE if f_1.dat donot exist or if it is not readable.

struct f_str_14 {F_is_Readable(ex_file: string) is {

var is_readable: bool;is_readable = files.file_is_readable(ex_file);outf("%s is_readable = %s\n", ex_file, is_readable);

};};extend sys {

fi_14: f_str_14;run() is also {

fi_14.F_is_Readable("f_1.dat");};

};

See Also

• files.file_exists() on page 4-116

• files.file_is_dir() on page 4-119

• files.file_is_link() on page 4-121)

• files.file_is_regular() on page 4-123

• files.file_is_temp() on page 4-125

• files.file_is_text() on page 4-126

4.11.21 files.file_is_regular()

Purpose

Check if a file is a regular file (not a directory or link)

e Libraries Preliminary 4-123

Page 260: Prelim e Lib

Predefined Routines files.file_is_regular()

not

ot

Category

Method

Syntax

files.file_is_regular(file-name: string): bool

Syntax example:

var is_rg: bool;is_rg = files.file_is_regular("a_fil");

Parameter

Description

Returns TRUE if the file exists and is a regular file. Returns FALSE if the file doesexist or if it is a directory or a symbolic link.

Example

The following example prints TRUE if f_1 is a regular file, or FALSE if f_1 does nexist or if it is a link or directory.

struct f_str_15 {F_is_Regular(ex_file: string) is {

var is_regular: bool;is_regular = files.file_is_regular(ex_file);outf("%s is_regular = %s\n", ex_file, is_regular);

};};extend sys {

fi_15: f_str_15;run() is also {

fi_15.F_is_Regular("f_1");};

};

See Also

• files.file_exists() on page 4-116

file-name The name of the file to be checked.

4-124 Preliminary e Libraries

Page 261: Prelim e Lib

files.file_is_temp() Predefined Routines

• files.file_is_dir() on page 4-119

• files.file_is_link() on page 4-121

• files.file_is_readable() on page 4-122)

• files.file_is_temp() on page 4-125

• files.file_is_text() on page 4-126

4.11.22 files.file_is_temp()

Purpose

Check if a file name starts with “/tmp”

Category

Method

Syntax

files.file_is_temp(file-name: string): bool

Syntax example:

var is_tmp: bool;is_tmp = files.file_is_temp("a_fil");

Parameter

Description

Returns TRUE if the file name starts with “/tmp”, otherwise returns FALSE.

Example

The following example prints “/tmp/f_1.dat is_temp = TRUE”.

struct f_str_16 {F_is_Temp(ex_file: string) is {

file-name The name of the file to be checked.

e Libraries Preliminary 4-125

Page 262: Prelim e Lib

Predefined Routines files.file_is_text()

var is_temp: bool;is_temp = files.file_is_temp(ex_file);outf("%s is_temp = %s\n", ex_file, is_temp);

};};extend sys {

fi_16: f_str_16;run() is also {

fi_16.F_is_Temp("/tmp/f_1.dat");};

};

See Also

• files.new_temp_file() on page 4-130

• files.file_exists() on page 4-116

• files.file_is_dir() on page 4-119

• files.file_is_link() on page 4-121

• files.file_is_readable() on page 4-122)

• files.file_is_regular() on page 4-123

• files.file_is_text() on page 4-126

4.11.23 files.file_is_text()

Purpose

Check if a file is a text file

Category

Method

Syntax

files.file_is_text(file-name: string): bool

Syntax example:

4-126 Preliminary e Libraries

Page 263: Prelim e Lib

files.file_is_text() Predefined Routines

le

s

var is_txt: bool;is_txt = files.file_is_text("a_fil");

Parameter

Description

Returns TRUE if the file is a text file (that is, if it contains more than 20% printabcharacters). Returns FALSE if the file does not exist or if it is a not a text file.

Example

The following example prints TRUE if f_1.dat is a text file, or FALSE if f_1.dat doenot exist or if it is not a text file.

struct f_str_17 {F_is_Text(ex_file: string) is {

var is_text: bool;is_text = files.file_is_text(ex_file);outf("%s is_text = %s\n", ex_file, is_text);

};};extend sys {

fi_17: f_str_17;run() is also {

fi_17.F_is_Text("f_1.dat");};

};

See Also

• files.file_exists() on page 4-116

• files.file_is_dir() on page 4-119

• files.file_is_link() on page 4-121

• files.file_is_readable() on page 4-122)

• files.file_is_regular() on page 4-123

• files.file_is_temp() on page 4-125

file-name The name of the file to be checked.

e Libraries Preliminary 4-127

Page 264: Prelim e Lib

Predefined Routines files.file_rename()

dat

4.11.24 files.file_rename()

Purpose

Rename a file

Category

Method

Syntax

files.file_rename(from-file-name: string, to-file-name: string)

Syntax example:

files.file_rename("f_1.exa", "b_1.exa");

Parameters

Description

Renames the file namedfrom-file-nameto to-file-name. If any files already exists withto-file-name, that file is overwritten by the contents of the file namedfrom-file-name.

If the file or directory is not writable, an error is issued.

Example

The following example changes the name of the f_1.dat file to f_old.dat. If the f_1.file does not exist, thefiles.add_file_type() routine issues an error.

struct f_str_18 {FRename(ex_file_1: string, ex_file_2:string) is {

var m_f: string;m_f = files.add_file_type(ex_file_1, "", TRUE);files.file_rename (m_f, ex_file_2);

};};extend sys {

from-file-name The file to rename.

to-file-name The new file name.

4-128 Preliminary e Libraries

Page 265: Prelim e Lib

files.file_size() Predefined Routines

is

fi_18: f_str_18;run() is also {

fi_18.FRename("f_1.dat", "f_old.dat");};

};

See Also

• files.add_file_type() on page 4-98

• files.file_copy() on page 4-114

4.11.25 files.file_size()

Purpose

Get the size of a file

Category

Method

Syntax

files.file_size(file-name: string): int

Syntax example:

var f_s: int;f_s = files.file_size("a_file.txt");

Parameter

Description

Returns the integer number of bytes in the file. If the file does not exist, an error issued.

file-name The name of the file.

e Libraries Preliminary 4-129

Page 266: Prelim e Lib

Predefined Routines files.new_temp_file()

Example

The following example gets and displays the number of bytes in the file named“f_1.dat”.

struct f_str_19 {FGetSize(ex_file: string) is {

var m_f: string;m_f = files.add_file_type(ex_file, "", TRUE);var f_size: int;f_size = files.file_size (m_f);outf("%s size is %d\n", m_f, f_size);

};};extend sys {

fi_19: f_str_19;run() is also {

fi_19.FGetSize("f_1.dat");};

};

See Also

• files.add_file_type() on page 4-98

• files.file_age() on page 4-111

4.11.26 files.new_temp_file()

Purpose

Create a unique temporary file name

Category

Method

Syntax

files.new_temp_file(): string

Syntax example:

var t_name: string;

4-130 Preliminary e Libraries

Page 267: Prelim e Lib

files.new_temp_file() Predefined Routines

file are

t_name = files.new_temp_file()

Parameters

None

Description

Computes a file name using the /tmp directory as the path to the file name. Eachname this routine produces contains the name of the current process, so namesunique across processes. Returns a string with a period at the end.

This routine only creates a file name. To create a file with this name, use thefiles.open() routine.

Example

The example below creates two file names in the /tmp directory and prints them.

struct f_str_20 {FMkTmp() is {

var t_name_1: string;t_name_1 = files.new_temp_file();print t_name_1;var t_name_2: string;t_name_2 = files.new_temp_file();print t_name_2;

};};extend sys {

fi_20: f_str_20;run() is also {

fi_20.FMkTmp();};

};

See Also

• files.file_is_temp() on page 4-125

• files.open() on page 4-102

e Libraries Preliminary 4-131

Page 268: Prelim e Lib

Predefined Routines files.write_string_list()

le,n.

4.11.27 files.write_string_list()

Purpose

Write a list of strings to a file

Category

Method

Syntax

files.write_string_list(file-name: string, strings: list of string)

Syntax example:

var s_list:= {"a string"; "another string"};files.write_string_list("a_file.txt", s_list);

Parameters

Description

Writes a list of strings into a file. Every string is written on a separate line in the fiwith \n appended to the end of the string. If the file already exists, it is overwritte

If the list of strings contains a NULL, an error is issued.

Example

The following example writes three lines of text into a file named “f_1.txt”.

struct f_str_21 {FWrStr(ex_file: string, str_list: list of string) is {

var m_f: string;m_f = files.add_file_type(ex_file, "", TRUE);files.write_string_list(ex_file, str_list);

};};extend sys {

file-name The file name to write into.

strings A list of strings to write to the file.

4-132 Preliminary e Libraries

Page 269: Prelim e Lib

Reading and Writing Structs Predefined Routines

fi_21: f_str_21;run() is also {

var fname:string;fname = "f_1.txt";var strlist: list of string;strlist = {"first line"; "second line"; "third

line"};fi_21.FWrStr(fname, strlist);

};};

See Also

• files.open() on page 4-102

• files.write() on page 4-107

• files.write_lob() on page 4-109

• files.write_ascii_struct() on page 4-137

• files.write_binary_struct() on page 4-139

4.11.28 Reading and Writing Structs

Structs inecan be read from files and written to files in either binary or ASCII format.

The routines that read structs from files and write structs to files are listed below anddescribed in this section.

• files.read_ascii_struct() on page 4-134

• files.read_binary_struct() on page 4-135

• files.write_ascii_struct() on page 4-137

• files.write_binary_struct() on page 4-139

See Also

• “File Routines” on page 4-96

• “General File Routines” on page 4-110

• “Low-Level File Routines” on page 4-97

e Libraries Preliminary 4-133

Page 270: Prelim e Lib

Predefined Routines files.read_ascii_struct()

s_stand

her

4.11.29 files.read_ascii_struct()

Purpose

Read ASCII file data into a struct

Category

Method

Syntax

files.read_ascii_struct(file-name: string, struct: struct-type): struct

Syntax example:

var a_str: s_struct;a_str = files.read_ascii_struct("a_s.out",

"s_struct").as_a(s_struct);

Parameters

Description

Reads the ASCII contents offile-nameinto a struct of typestruct, and returns a struct.The struct being read must be cast to the correct data type (seeas_a() on page 4-25).If the file does not exist, an error is issued.

Example

The following example creates a variable named “str” to hold an instance of the struct type, reads ASCII contents of a file named “a_s.out” into the struct variable,prints the contents.

struct s_st {len: int;hdr: string;b_l: list of bool;

};

file-name The name of the file to read from. The file may have been created eitwith files.write_ascii_struct() or in a similar format with an editor.

struct The struct type to read data into.

4-134 Preliminary e Libraries

Page 271: Prelim e Lib

files.read_binary_struct() Predefined Routines

struct r_st {r_file() is {

var str: s_st;str = files.read_ascii_struct("a_s.out",

"s_st").as_a(s_st);print str;

};run() is also {

r_file();};

};extend sys {

ri: r_st;};

See Also

• files.read() on page 4-104

• files.read_lob() on page 4-106

• files.file_is_readable() on page 4-122

• files.read_binary_struct() on page 4-135

• files.write_ascii_struct() on page 4-137

4.11.30 files.read_binary_struct()

Purpose

Read the contents of a binary file into a struct

Category

Method

Syntax

files.read_binary_struct(file-name: string, struct: struct-type,check-version: bool): struct

Syntax example:

e Libraries Preliminary 4-135

Page 272: Prelim e Lib

Predefined Routines files.read_binary_struct()

a

in

s_standetruct

ted

tho

var b_str: s_struct;b_str = files.read_binary_struct("b.out", "s_struct",

TRUE).as_a(s_struct);

Parameters

Description

Reads the binary contents offile-nameinto a struct of the specified type, and returnsstruct. The struct being read must be cast to the correct data type (seeas_a() onpage 4-25).

If check-version is FALSE, the routine can run even if the order of fields in the filestruct is different from the order of fields in the currently runningemodule. Ifcheck-version is TRUE, an error is issued if the struct definition has been changedany way since the struct was written to the file.

Example

The following example creates a variable named “str” to hold an instance of the struct type, reads binary contents of a file named “b_s.out” into the struct variable,prints the contents. Thecheck-versionparameter is set to TRUE to issue an error if thb_s.out file struct does not exactly match the s_st definition. The b_s.out binary sfile was created previously byfiles.write_binary_struct() on page 4-139.

struct s_st {len: int;hdr: string;b_l: list of bool;

};struct r_st {

r_file() is {var str: s_st;str = files.read_binary_struct("b_s.out", "s_st",

TRUE).as_a(s_st);print str;

};

file-name The name of the file to read from. The file must have been creaby files.write_binary_struct() on page 4-139.

struct The struct type to read data into.

check-version Set to TRUE to compare the contents of the file being read withe definition of the struct in the currently running module. Set tFALSE to allow minor changes.

4-136 Preliminary e Libraries

Page 273: Prelim e Lib

files.write_ascii_struct() Predefined Routines

run() is also {r_file();

};};extend sys {

ri: r_st;};

See Also

• files.read() on page 4-104

• files.read_lob() on page 4-106

• files.file_is_readable() on page 4-122

• files.read_ascii_struct() on page 4-134

• files.write_ascii_struct() on page 4-137

4.11.31 files.write_ascii_struct()

Purpose

Write the contents of a struct to a file in ASCII format

Category

Method

Syntax

files.write_ascii_struct(file-name: string, struct: struct, comment: string,indent: bool, depth: int, max-list-items: int)

Syntax example:

files.write_ascii_struct("a_file.dat", a_str, "my_struct",TRUE, 2, 10);

e Libraries Preliminary 4-137

Page 274: Prelim e Lib

Predefined Routines files.write_ascii_struct()

er of

Parameters

Description

Recursively writes the contents of thestruct to thefile-name in ASCII format. If thestruct contains other structs, those structs are also written to the file. If the numbhierarchical levels contained in thestruct is greater than the specifieddepth, levelsbelow thedepth level are represented by ellipses (...) in the ASCII file.

If the file already exists, it is overwritten.

Example

In the following example, there are three levels of hierarchy under thesys struct: thew_st struct contains a s_st struct, which contains a list of dat_s structs. The ss_iinstance of the s_st struct is written to an ASCII file with these options:

• The comment “My ASCII struct” is placed at the top of the file.

• Indentation of the struct’s fields is TRUE.

• Only the highest hierarchical level of structs is written (depth = 1).

• The first three items in lists are written.

struct dat_s {dat_l: list of uint;keep dat_l.size() == 5;

};struct s_st {

ds_l: list of dat_s;keep ds_l.size() == 6;len: int;hdr: string;b_l: list of bool;

};struct w_st {

file-name The name of the file to write into.

struct The name of the struct instance to write to the file.

comment A string for a comment at the beginning of the file.

indent Boolean selector for indentation to the struct’s field depth.

depth The number of levels of nested structs to write.

max-list-items For lists, how many items from each list to write.

4-138 Preliminary e Libraries

Page 275: Prelim e Lib

files.write_binary_struct() Predefined Routines

ss_i: s_st;wr_file() is {

files.write_ascii_struct("a_s.out", ss_i,"My ASCII struct", TRUE, 1, 3);

};run() is also {

wr_file();};

};extend sys {

wi: w_st;};

See Also

• files.write() on page 4-107

• files.write_lob() on page 4-109

• files.read_ascii_struct() on page 4-134

• files.write_binary_struct() on page 4-139

4.11.32 files.write_binary_struct()

Purpose

Write the contents of a struct to a file in binary format

Category

Method

Syntax

files.write_binary_struct(file-name: string, struct: struct)

Syntax example:

files.write_binary_struct("b_file.dat", b_str);

e Libraries Preliminary 4-139

Page 276: Prelim e Lib

Predefined Routines files.write_binary_struct()

ady

t’s

Parameters

Description

Recursively writes the contents of thestruct to thefile-name in binary format. If thestruct contains other structs, those structs are also written to the file. If the file alreexists, it is overwritten.

Example

The following example creates a struct instance named “str” and writes the struccontents in binary format to a file named “b_s.out”.

struct s_st {len: int;hdr: string;b_l: list of bool;

};struct w_st {

wr_file() is {var str := a new s_st with {

.len = 1;

.hdr = "top";

.b_l = { TRUE; FALSE; TRUE };};files.write_binary_struct("b_s.out", str);

};run() is also {

wr_file();};

};extend sys {

wi: w_st;};

See Also

• files.write() on page 4-107

• files.write_lob() on page 4-109

• files.read_binary_struct() on page 4-135

file-name The name of the file to write structs into.

struct The name of the struct instance to write to the file.

4-140 Preliminary e Libraries

Page 277: Prelim e Lib

Calling Predefined Routines Predefined Routines

• files.write_ascii_struct() on page 4-137

4.12 Calling Predefined Routines

4.12.1 routine()

Purpose

Call a predefined routine

Category

Action

Syntax

routine-name([param, …])

Syntax example:

var s := str_join(slist," - ");

Parameters

Description

Calls a predefined routine passing it the specified parameters.

Example

This example shows how to call a predefined routine.

routine-name The name of the routine.

param A list of zero or more parameters separated by commas, oneparameter for each parameter in the parameter list of the routinedefinition. Parameters are passed by their relative position in thelist, so the name of the parameter being passed does not have tomatch the name of the parameter in the routine definition. Theparentheses around the parameter list are required even if theparameter list is empty.

e Libraries Preliminary 4-141

Page 278: Prelim e Lib

Predefined Routines routine()

<'extend sys { m1() is {

var slist: list of string = {"first";"second";"third"}; var s := str_join(slist," - "); print s; };};'>

See Also

• “Predefined Routines Overview” on page 4-1

4-142 Preliminary e Libraries

Page 279: Prelim e Lib

ucts

tate to

5 Modeling State Machines

This chapter contains descriptions of how to create state machines and of the constrused in them. It contains the following sections.

• “State Machine Overview” on page 5-1

• “State Machine Constructs” on page 5-2

• “Sample State Machine” on page 5-9

• “Using State Machines” on page 5-10

See Also

• “Invoking Methods” on page 6-18 in thee Language Reference Manual

• “e Data Types” on page 3-2 in thee Language Reference Manual

5.1 State Machine OverviewThee languagestate machine action provides constructs for modeling state machines.

A state machine definition consists of thestate machineaction followed by a state holderexpression and a block that specifies the ways the state machine can get from one sanother (seestate machine on page 5-2).

e Libraries Preliminary 5-1

Page 280: Prelim e Lib

Modeling State Machines State Machine Constructs

the

rom

State machines can be defined only within time-consuming methods (TCMs). Whenexecution of a TCM reaches astate machine action, the appropriate series of statetransitions occurs, and then the state machine exits. At this point the TCM continues fthe action following thestate machine action.

See Also

• “State Machine Constructs” on page 5-2

• “Sample State Machine” on page 5-9

• “Using State Machines” on page 5-10

5.2 State Machine ConstructsTheestate machine constructs are used to define state machines and the transitionsbetween their states. This section contains descriptions of the following constructs.

• state machine on page 5-2

• state => state on page 5-5

• * => state on page 5-6

• state action on page 5-8

5.2.1 state machine

Purpose

Define a state machine

Category

Action

Syntax

state machinestate-holder-exp [until final-state]{(state-transition | state) {action; …}; …}

Syntax example:

5-2 Preliminary e Libraries

Page 281: Prelim e Lib

state machine Modeling State Machines

hethe

atith the

ble.

ck

is

n

is

!c_proc: [st, dn];s_m()@sys.clk is {

state machine c_proc until dn {*=> st {wait rise('top.rst'); wait [2]*cycle};st => dn {out("going to dn"); wait [3]*cycle;};

};};

Parameters

Description

Defines a state machine using an enumeratedstate-holder-expto hold the current stateof the machine.

The state machine must be defined in a time-consuming method (TCM). When tstate machineaction is reached, the state machine starts, in the first state listed inenumerated state holder expression type definition.

During the execution of thestate machine action the current state is stored in thestate-holder-exp.

If the optionaluntil final-stateexit condition is used, the state machine runs until thstate is reached. The final state must be one of the enumerated values declared wstate machine name.

state-holder-exp Stores the current state of the state machine. This can be a variain the current TCM, a field undersys, or any assignable expressionIt typically is an enumerated type field of the struct in which theTCM is defined.

final-state The state at which the state machine terminates.

state-transition A state transition, which occurs when the associated action blofinishes. Seestate => stateon page 5-5 and* => stateon page 5-6.

state A state. When this state is entered, the associated action blockinvoked. Seestate action on page 5-8.

action; … One of the following:

• An action block which, upon completion, causes the transitioto occur, if the state-transition syntax is used.

• An action block that is to be performed when the given stateentered, if the state syntax is used.

e Libraries Preliminary 5-3

Page 282: Prelim e Lib

Modeling State Machines state machine

, or,

tehat

s theatess ane”

efterThe

is

If the until clause is not used, the state machine runs until the TCM is terminatedif the state machine is in anall of or first of action, it runs until theall of or first ofaction completes (see “Terminating a State Machine” on page 5-11).

Thestate-transitionblock is a list of the allowed transitions between states of the stamachine. Each state transition contains an action block that defines conditions tcause the transition to occur. Typically, the action block contains a singlewait untilaction. However, it can contain any block of actions. For example,

x => y {wait until @named_event_1; wait until @named_event_2};

The transition only occurs after both events happen, in order.

The action block can contain a regular method, as in the following.

x => y {wait until change(p_clk); me.packet.bb_operations()};

Oncechange(p_clk) happens, the method executes immediately, and then thetransition occurs.

Example

In the following example, the struct field expression used for the state machine i“status” field declaration. The state machine name is “status”, and its possible stare “start” and “done”. The state machine is defined in the “sm_meth()” TCM. It hafinal state of “done”, meaning the state machine terminates when it enters the “dostate.

Since the “start” field is listed first in the list of states, that is the initial state for thstate machine. The state changes from “start” to “done” two “sys.smclk” cycles ait enters the “start” state. Upon entering the “done” state, the state machine exits.out() action is executed after the state machine exits.

struct smp_state_machine{!status: [start, done];sm_meth() @sys.smclk is {

state machine status until done {start => done {wait [2]*cycle};

};out("The status state machine is done");

};};

A more complex state machine is shown below. The name of the state machine “arbiter_state”, and it is declared with states “idle”, “busy”, “grant”, and “reject”.

5-4 Preliminary e Libraries

Page 283: Prelim e Lib

state => state Modeling State Machines

onhine

This state machine has no “until finish-state” exit condition, so it runs until it the“watcher()” TCM is terminated.

The “* => idle” syntax means “from any other state to the idle state”. The conditifor this transition is that 10 cycles of “sys.pclk” have elapsed since the state macentered the entered any state.

struct bus {!arbiter_state: [idle, busy, grant, reject];watcher() @sys.pclk is {

wait [3]*cycle;state machine arbiter_state {

idle => busy {wait @sys.req};busy => grant {wait [2]*cycle};busy => reject {wait @sys.bad_pkt};* => idle {wait [10]*cycle};

};};

};

See Also

• “State Machine Overview” on page 5-1

• state => state on page 5-5

• * => state on page 5-6

• state action on page 5-8

5.2.2 state => state

Purpose

One-to-one state transition

Category

State transition

Syntax

current-state=>next-state{action; …}

e Libraries Preliminary 5-5

Page 284: Prelim e Lib

Modeling State Machines * => state

rtsk

the

ins

Syntax example:

begin => run {wait [2]*cycle; out("Run state entered")};

Parameters

Description

Specifies how a transition occurs from one state to another. The action block staexecuting when the state machine enters the current state. When the action bloccompletes, the transition to the next state occurs.

Example

The example below shows a definition of a transition for the “initial” state to the“running” state. If the 'top.start' HDL signal changes while the state machine is in“initial” state, the state changes to “running”.

initial => running {wait until change('top.start')@sim};

See Also

• “State Machine Overview” on page 5-1

• state machine on page 5-2

• * => state on page 5-6

• state action on page 5-8

5.2.3 * => state

Purpose

Any-to-one state transition

current-state The state from which the transition starts.

next-state The state to which the transition changes.

action; … The sequence of actions that precede the transition. It usually contaat least one time-consuming action.

5-6 Preliminary e Libraries

Page 285: Prelim e Lib

* => state Modeling State Machines

ethe

”nal

s at

Category

State transition

Syntax

*=>next-state{action; …}

Syntax example:

* => pause {wait @sys.restart; out("Entering pause state");};

Parameters

Description

Specifies how a transition occurs from any defined state to a particular state. Thaction block starts executing when the state machine enters a new state. When action block completes, the transition to the next state occurs.

Example

The example below shows a definition of a transition for any state to the “runningstate. From any state, if the 'top.start' HDL signal rises and later the 'top.hold' sigfalls, the state changes to “running”.

* => running { wait until rise('top.start')@pclk;wait until fall('top.hold')@pclk };

See Also

• “State Machine Overview” on page 5-1

• state machine on page 5-2

• state => state on page 5-5

• state action on page 5-8

next-state The state to which the transition changes.

action; … The sequence of actions that precede the transition. It usually containleast one time-consuming action.

e Libraries Preliminary 5-7

Page 286: Prelim e Lib

Modeling State Machines state action

e

t

5.2.4 state action

Purpose

Execute actions upon entering a state, with no state transition

Category

State action block

Syntax

current-state{action; …}

Syntax example:

* => run {out("* to run"); wait cycle};run {out("In run state"); wait cycle; out("Still in run");};run => done {out("run to done"); wait cycle};

Parameters

Description

Specifies an action block that is executed when a specific state is entered. Notransition occurs when the action block completes. The state machine stays in thcurrent state until some other transition takes place.

Example

The last two lines in the following example contain an action block that is to beexecuted when the state machine enters the “running” state. The “while TRUE …”action means that as long as the state machine is in the “running” state, theout()action is executed every cycle.

state machine sm_1 until done {initial => running { wait until rise('top.a') };initial => done { wait until change('top.r1');

wait until rise('top.r2') };

current-state The state for which the action block is to be executed.

action; … The sequence of actions that is executed upon entering the currenstate. It usually contains at least one time-consuming action.

5-8 Preliminary e Libraries

Page 287: Prelim e Lib

Sample State Machine Modeling State Machines

in the

ins

ne”

running => initial { wait until rise('top.b') };running {

out("Entered running state");while TRUE {wait cycle; out("still running");}

};};

See Also

• “State Machine Overview” on page 5-1

• state machine on page 5-2

• state => state on page 5-5

• * => state on page 5-6

5.3 Sample State MachineThe following example shows a single state machine. The state machine is declared“sm_1” field, with possible states named “initial”, “running”, and “done”.

struct exa_1_state_machine {!sm_1: [initial, running, done];tcm_1()@sys.sm_clk is {

wait [10]*cycle;state machine sm_1 until done {

initial => running { wait until rise('top.a') };initial => done { wait until change('top.r1');

wait until rise('top.r2') };running => done {wait until fall('top.b')};running {while TRUE {out("Running"); wait cycle}};

};out("tcm_1 finished");

};};

The “sm_1” state machine is defined in the “tcm_1()” TCM. Note that the TCM contaother actions besides the state machine. There is a 10-cyclewait before the state machinestarts, and anout() that is executed after the state machine is finished.

The “until done” clause means that the state machine will run until it reaches the “dostate.

e Libraries Preliminary 5-9

Page 288: Prelim e Lib

Modeling State Machines Using State Machines

itionethe

n

o

The transition definitions are as follows:

See Also

• “State Machine Overview” on page 5-1

• “State Machine Constructs” on page 5-2

• “Using State Machines” on page 5-10

5.4 Using State MachinesThis section contains the following topics.

• “Initializing a State Machine” on page 5-10

• “Terminating a State Machine” on page 5-11

• “Rules for State Transitions” on page 5-12

• “Nested State Machines” on page 5-13

• “Parallel State Machines” on page 5-14

5.4.1 Initializing a State Machine

State machines start by default in the first state specified in the enumerated type definof thestate-holder-exp(see “State Machine Overview” on page 5-1). In the following, thstarting state for state machine “sm_2” is “initial” because that is the first state listed in“sm_2” type definition.

struct exa_2_state_machine{!sm_2: [initial, running, done];tcm_2()@sys.sm_clk is {

initial => running A rise of the 'top.a' HDL signal causes a transition from“initial” to “running”.

initial => done A change in the 'top.r1' signal followed eventually by a rise ithe 'top.r2' signal causes a transition from “initial” to “done”.

running => done A fall of the 'top.b' signal causes a transition from “running” t“done”.

running When the state machine enters the “running” state,continuously execute the “{out(“Running”); wait cycle};”action block until the state changes.

5-10 Preliminary e Libraries

Page 289: Prelim e Lib

Terminating a State Machine Modeling State Machines

rtingtherine

M

state machine sm_2 until done {// ...

};};

};

If the state machine is entered several times in the same TCM, it is initialized to the stastate each time it is entered. A state machine can be re-entered if it is nested in anostate machine or if it is enclosed in a loop. Conditional initialization of the state machcan be performed within the state machine as shown in the following.

struct exa_2_state_machine{!sm_2: [initial, init_cond, init_no_cond, running, done];tcm_2()@sys.sm_clk is {

state machine sm_2 until done {initial => init_cond {sync true(cond);};initial => init_no_cond {sync true(not cond);};// ...

};};

};

See Also

• “State Machine Overview” on page 5-1

5.4.2 Terminating a State Machine

You can terminate a state machine in any of the following ways.

• Specify a final state in anuntil clause.

• Enclose the state machine within afirst of action.

• Terminate the TCM using thequit() method.

A state machine defined as follows will exit when it reaches the “done” state. The TCcontinues execution.

struct exa_3_state_machine{!sm_3: [initial, running, done];tcm_3()@sys.tclk is {

state machine sm_3 until done {// ...

};// ...

};

e Libraries Preliminary 5-11

Page 290: Prelim e Lib

Modeling State Machines Rules for State Transitions

Msrale

};

The following state machine is enclosed in afirst of action. The other thread of thefirst ofaction terminates afterwait [MAXN ] * cycle. If the state machine runs for MAXN cycles,thewait thread finishes and the TCM terminates.

struct exa_4_state_machine {!sm_4: [initial, running, done];tcm_4()@sys.tclk is {

first of {{wait [MAXN]*cycle;};{state machine sm_4 {

// ...};

};// ...

};};

};

Thequit() method of the struct can be used in another TCM to terminate all active TCand their state machines. This method cannot be used to terminate only one of seveactive TCMs, nor can it terminate a state machine while allowing the TCM to continuexecuting. In the following example, a TCM insys calls thequit() method of the“exa_4_state_machine” instance, which terminates the “tcm_4()” TCM and the statemachine.

struct exa_4_state_machine{!sm_4: [initial, running, done];tcm_4()@sys.tclk is {

state machine sm_4 {// ...

};};

};

See Also

• “State Machine Overview” on page 5-1

5.4.3 Rules for State Transitions

• A transition takes place when its action block finishes.

5-12 Preliminary e Libraries

Page 291: Prelim e Lib

Nested State Machines Modeling State Machines

hese

it isnd

s

canowing

• If there are several contending transitions (for example, several transitions with tsamecurrent-state), their action blocks are executed in parallel. The transition whoaction block finishes first is the one that occurs.

• When the action blocks for two transitions can complete during the same cycle, not possible to determine which transition will prevail. One will occur successfully athe other will not occur.

• Action blocks can take time, but transitions themselves take no time.

If the state machine specifies:

x => y {sync true('cpu.clock' == 1)};y => z {sync true('alu.clock' == 1)};

and both ‘cpu.clock’ and ‘alu.clock’ are high within the same cycle, the two transitionboth occur within the same cycle.

See Also

• “State Machine Overview” on page 5-1

5.4.4 Nested State Machines

A state machine is just an action like all others, so it can appear anywhere an actionappear. This makes nested and parallel state machines possible. For example, the follcontains a state machine named “run_to_finish” nested within another state machinenamed “sm_5”.

struct exa_5_state_machine {!sm_5: [begin, run, finish];run_to_finish: [s_b1, s_b2, s_b3];tcm_5() @sys.pclk is {

state machine sm_5 until finish {begin => run {wait [2]*cycle};run => finish {

state machine run_to_finish until s_b3 {s_b1 => s_b2 {wait [2]*cycle};s_b2 => s_b1 {wait [3]*cycle};s_b2 => s_b3 {wait @sys.s_reset};

};};* => begin {wait @sys.reset};

};};

};

e Libraries Preliminary 5-13

Page 292: Prelim e Lib

Modeling State Machines Parallel State Machines

its,

lessting

ch

Whenever the “sm_5” state machine enters the “run” state, it starts the nested“run_to_finish” state machine. When that machine finally reaches its “s_b3” state it exand the “sm_5” state machine enters its “finish” state.

If “sys.reset” becomes TRUE, the “sm_5” state machine enters its “begin” state regardof the current state of the “run_to_finish” state machine. This is an example of preempa state machine from the outside.

See Also

• “State Machine Overview” on page 5-1

5.4.5 Parallel State Machines

An example of parallel state machines is shown below.

struct exa_6_state_machine {!sm_6a: [x1, x2, x3];!sm_6b: [y1, y2];tcm_6() @sys.sclk is {

all of {state machine sm_6a until x3 {

// ...};state machine sm_6b until y2 {

// ...};

};out("sm_6a and sm_6b state machines are both done");

};};

The two state machines in the example above are entered at the same time, and eaproceeds independently of the other. Because they are started in anall of construct, bothstate machines must exit before theout() action can be executed.

In the following example, the two state machines are started in afirst of rather thanall ofconstruct.

struct exa_6_2_state_machine {!sm_6a_2: [x1, x2, x3];!sm_6b_2: [y1, y2];tcm_6_2() @sys.sclk is {

first of {state machine sm_6a_2 until x3 {

// ...

5-14 Preliminary e Libraries

Page 293: Prelim e Lib

Parallel State Machines Modeling State Machines

ing.

};state machine sm_6b_2 until y2 {

//...};

};out("either sm_6a_2 or sm_6b_2 state machine is done");

};};

Parallel state machines can be nested within another state machine, as in the follow

a => b {all of {

state machine x until end_x { . . .};state machine y until end_y { . . .};

};};

See Also

• “State Machine Overview” on page 5-1

e Libraries Preliminary 5-15

Page 294: Prelim e Lib

Modeling State Machines Parallel State Machines

5-16 Preliminary e Libraries

Page 295: Prelim e Lib

Index

3

3

Symbols=> Seeimplication operator, state

transition syntax, yield temporalexpression

>> file concatenation operator 4-113

Aabs() arithmetic routine syntax 4-15absolute value routine 4-15actions

routine 4-141state machine 5-2state transitions 5-8

all_values() expression syntax 4-35and

of list items 3-72any-state => state transition syntax 5-6append() string routine syntax 4-59appendf() string routine

formats 4-88syntax 4-60

as_a() type casting operator syntax 4-25average, of list items 3-73

Bbase 10 log routine 4-19base 2 log routine 4-18bin() string routine syntax 4-61

binary filesreading 4-106, 4-136writing 4-109, 4-140

bitsBoolean operators 4-23

bitwise_and() pseudo-method syntax 4-2bitwise_nand() pseudo-method syntax

4-23bitwise_nor() pseudo-method syntax 4-23bitwise_or() pseudo-method syntax 4-23bitwise_xnor() pseudo-method syntax 4-2bitwise_xor() pseudo-method syntax 4-23Boolean

bitwise AND 4-24bitwise OR 4-24bitwise XOR 4-24

CC routines, bypassing type checking for

2-29C style formatting mask 4-88casting

explicit 4-25commands

operating system 4-89, 4-90, 4-91concatenation.See packingcopy predefined method syntax 2-5copy, of expression

shallow 2-5

e Libraries Preliminary Index-1

Page 296: Prelim e Lib

Index

CRC functions for lists 3-79cyclic redundancy checks.SeeCRC

Ddata types

casting 4-25date_time() OS routine syntax 4-95dec() string routine syntax 4-62declared_type() pseudo-method syntax

2-24deep_compare() predefined routine syntax

4-5deep_compare_physical() predefined

routine syntax 4-10deep_copy() predefined routine syntax 4-2div_round_up() arithmetic routine syntax

4-22division

rounding up 4-22do_pack() predefined method

syntax 4-49do_print() predefined method syntax 2-6do_unpack() predefined method

syntax 4-53documentation

document conventions 1-2documentation syntax notation 1-3

Ee_path() predefined method syntax 2-15environment variables

UNIX, getting 4-94even value routine 4-17even() arithmetic routine syntax 4-17exponential routine 4-20expressions

all_values() 4-35converting to strings 4-82declared type descriptor for, getting

2-24type descriptor for, getting 2-26

Ffield() pseudo-method syntax 2-28fields

physicalpacking 4-49unpacking 4-55

type descriptors 2-28values

initializing 2-8FIFO ordered resource sharing 2-31files

append mode 4-103appending 4-113

See alsoconcatenatingbuffers, flushing 4-100, 4-101check

if directory 4-119if link 4-121if readable 4-122if regular 4-123if temporary 4-125if text 4-126

closing 4-99concatenating 4-113

See alsofiles appendingcopying 4-114deleting 4-115descriptors 4-97existence, checking 4-116extensions, getting 4-118global struct 4-96modification dates, getting 4-111names

getting 4-98renaming 4-128

opening 4-102read modes 4-103reading

ASCII 4-104ASCII structs 4-134binary structs 4-135lists of bits 4-106

Index-2 Preliminary e Libraries

Page 297: Prelim e Lib

Index

1

renaming 4-128size, getting 4-129temporary, creating 4-130types, checking 4-119, 4-121, 4-123,

4-125, 4-126write modes 4-103writing

ASCII 4-107ASCII structs 4-137binary 4-109binary structs 4-139lists of bits 4-109lists of strings 4-132

files.add_file_type() routine syntax 4-98files.close() routine syntax 4-99files.file_age() routine syntax 4-111files.file_append() routine syntax 4-113files.file_copy() routine syntax 4-114files.file_delete() routine syntax 4-115files.file_exists() routine syntax 4-116files.file_extension() routine syntax 4-118files.file_is_dir() routine syntax 4-119files.file_is_link() routine syntax 4-121files.file_is_readable() routine syntax

4-122files.file_is_regular() routine syntax 4-123files.file_is_temp() routine syntax 4-125files.file_is_text() routine syntax 4-126files.file_rename() routine syntax 4-128files.file_size() routine syntax 4-129files.flush() routine syntax 4-101files.new_temp_file() routine syntax 4-130files.open() routine syntax 4-102files.read() routine syntax 4-104files.read_ascii_struct() routine syntax

4-134files.read_binary_struct() routine syntax

4-135files.read_lob() routine syntax 4-106files.write() routine syntax 4-107files.write_ascii_struct() routine syntax

4-137

files.write_binary_struct() routine syntax4-139

files.write_lob() routine syntax 4-109files.write_string_list() routine syntax

4-132format string for appendf() and outf() 4-88full_hdl_path() predefined method syntax

2-14

Gget_all_units() routine syntax 4-36get_enclosing_unit() predefined method

syntax 2-19get_parent_unit() predefined method

syntax 2-16get_symbol() OS routine syntax 4-94get_unit() predefined method syntax 2-18global.files struct 4-96

Hhdl_path() predefined method syntax 2-1hex() string routine syntax 4-64

Iilog10() arithmetic routine syntax 4-19ilog2() arithmetic routine syntax 4-18infinite integer, and packing 4-39init() predefined method syntax 2-7integers

unbounded, and packing 4-39ipow() arithmetic routine syntax 4-20isqrt() arithmetic routine syntax 4-21

Kkeyed lists

pseudo-methods 3-85restrictions on 3-90

e Libraries Preliminary Index-3

Page 298: Prelim e Lib

Index

Lline number in source, finding 2-30list functions 3-1list.add(item) pseudo-method syntax 3-4list.add(list) pseudo-method syntax 3-5list.add0(item) pseudo-method syntax 3-7list.add0(list) pseudo-method syntax 3-8list.all() pseudo-method syntax 3-67list.all_indices() pseudo-method syntax

3-70list.and_all() pseudo-method syntax 3-72list.apply() pseudo-method syntax 3-26list.average() pseudo-method syntax 3-73list.clear() pseudo-method syntax 3-9list.count() pseudo-method syntax 3-29list.crc_32() pseudo-method syntax 3-81list.crc_32_flip() pseudo-method syntax

3-84list.crc_8() pseudo-method syntax 3-80list.delete() pseudo-method syntax 3-11list.exists() pseudo-method syntax 3-30list.fast_delete() pseudo-method syntax

3-13list.field specification syntax 3-32list.first() pseudo-method syntax 3-33list.first_index() pseudo-method syntax

3-34list.get_indices() pseudo-method syntax

3-36list.has() pseudo-method syntax 3-37list.insert(index, item) pseudo-method

syntax 3-14list.insert(index, list) pseudo-method

syntax 3-16list.is_a_permutation() pseudo-method

syntax 3-39list.is_empty() pseudo-method syntax 3-40list.key() pseudo-method syntax 3-86list.key_exists() pseudo-method syntax

3-89list.key_index() pseudo-method syntax

3-87

list.last() pseudo-method syntax 3-42list.last_index() pseudo-method syntax

3-44list.max() pseudo-method syntax 3-45list.max_index() pseudo-method syntax

3-47list.max_value() pseudo-method syntax

3-48list.min() pseudo-method syntax 3-50list.min_index() pseudo-method syntax

3-52list.min_value() pseudo-method syntax

3-53list.or_all() pseudo-method syntax 3-75list.pop() pseudo-method syntax 3-17list.pop0() pseudo-method syntax 3-18list.product() pseudo-method syntax 3-76list.push() pseudo-method syntax 3-19list.push0() pseudo-method syntax 3-21list.resize() pseudo-method syntax 3-22list.reverse() pseudo-method syntax 3-55list.size() pseudo-method syntax 3-56list.sort() pseudo-method syntax 3-57list.sort_by_field() pseudo-method syntax

3-59list.split() pseudo-method syntax 3-61list.sum() pseudo-method syntax 3-78list.top() pseudo-method syntax 3-63list.top0() pseudo-method syntax 3-64list.unique() pseudo-method syntax 3-65lists

add all items 3-78adding items.Seeinserting itemsand all items 3-72average of all items 3-73of bits

reading from files 4-106writing to files 4-109

checkingfor index 3-30for items 3-37, 3-40for key 3-89

Index-4 Preliminary e Libraries

Page 299: Prelim e Lib

Index

permutations 3-39counting items 3-29CRC pseudo-methods 3-79CRC32 function 3-81

flipping bits 3-84CRC8 function 3-80deleting

all items 3-9items 3-11, 3-13, 3-17, 3-18repeated items 3-65

fieldsgetting contents of 3-32

getting maximum values 3-45, 3-47,3-48

getting minimum values 3-50, 3-52,3-53

getting size of 3-56getting specific items 3-33, 3-34,

3-42, 3-44, 3-63, 3-64, 3-67,3-70

getting specific items by key 3-86,3-87

getting sublists 3-36initializing 2-8, 3-22inserting

items 3-4, 3-7, 3-14, 3-19, 3-21lists 3-5, 3-8, 3-16

keyed 3-85restrictions 3-90

logic operations for 3-72mathematical functions 3-72mathematical operators 3-72methods.Seepseudo-methodsmodifying 3-3

all items 3-26multiply all items 3-76or all items 3-75pseudo-methods 3-2removing items.See deleting itemsresizing 3-22reversing items 3-55size

changing 3-22sorting

by expression value 3-57by field value 3-59

specifying a field 3-32splitting 3-61sublist pseudo-methods 3-67

lock() predefined TCM syntax 2-31locker predefined struct 2-31logarithms

base 10 4-19base 2 4-18

Mmathematical functions

list pseudo-methods 3-72max() arithmetic routine syntax 4-14maximum value routine 4-14methods

starting 2-3, 2-10min() arithmetic routine syntax 4-12minimum value routine 4-12module in source, finding 2-30modules

line number in, finding 2-30

Oodd value routine 4-16odd() arithmetic routine syntax 4-16operating system commands

collecting results of 4-92, 4-93executing 4-89, 4-90, 4-91

operatorsas_a() type cast 4-25

orof all list items 3-75

OS.Seeoperating systemout() output routine syntax 4-84outf() output routine syntax 4-85output

displaying 4-84

e Libraries Preliminary Index-5

Page 300: Prelim e Lib

Index

formatted 4-85output_from() OS routine syntax 4-92output_from_check() OS routine syntax

4-93outputf() output routine formats 4-88

Ppack() pseudo-method syntax 4-38packing

do_pack() 4-49do_unpack() 4-53options

packing.global_default 4-49,4-53

packing.high 4-38, 4-42, 4-49,4-53

packing.high_big_endian 4-49,4-53

packing.low 4-38, 4-42, 4-49,4-53

packing.low_big_endian 4-49,4-53

pack() 4-38swap() 4-47unpack() 4-42

packing.global_default 4-49, 4-53packing.high 4-38, 4-42, 4-49, 4-53packing.high_big_endian 4-49, 4-53packing.low 4-38, 4-42, 4-49, 4-53packing.low_big_endian 4-49, 4-53physical fields

packing 4-49unpacking 4-55

power routine 4-20predefined methods

copy() 2-5do_pack() 4-49do_print() 2-6do_unpack() 4-53for units

e_path() 2-15full_hdl_path() 2-14

get_parent_unit() 2-16hdl_path() 2-11

get_enclosing_unit 2-19get_unit 2-18init() 2-7lock() 2-31overview of 2-1print_line() 2-8quit() 2-9release() 2-31run() 2-10set_unit 2-23for structs 2-4sys.init() 2-2sys.run() 2-3try_enclosing_unit 2-21

predefined routinesabs() 4-15append() 4-59appendf() 4-60bin() 4-61data_time() 4-95dec() 4-62deep_compare() 4-5deep_compare_physical() 4-10deep_copy() 4-2div_round_up() 4-22even() 4-17files.add_file_type() 4-98files.close() 4-99files.file_age() 4-111files.file_append() 4-113files.file_copy() 4-114files.file_delete() 4-115files.file_exists() 4-116files.file_extension() 4-118files.file_is_dir() 4-119files.file_is_link() 4-121files.file_is_readable() 4-122files.file_is_regular() 4-123files.file_is_temp() 4-125files.file_is_text() 4-126

Index-6 Preliminary e Libraries

Page 301: Prelim e Lib

Index

files.file_rename() 4-128files.file_size() 4-129files.flush() 4-101files.new_temp_file() 4-130files.open() 4-102files.read() 4-104files.read_ascii_struct() 4-134files.read_binary_struct() 4-135files.read_lob() 4-106files.write() 4-107files.write_ascii_struct() 4-137files.write_binary_struct() 4-139files.write_lob() 4-109files.write_string_list() 4-132get_all_units() 4-36get_symbol() 4-94hex() 4-64ilog10() 4-19ilog2() 4-18ipow() 4-20isqrt() 4-21max() 4-14min() 4-12odd() 4-16out() 4-84outf() 4-85output_from() 4-92output_from_check() 4-93quote 4-65reductions 4-23, 4-24spawn() 4-89spawn_check() 4-90str_chop() 4-66str_empty() 4-67str_exactly() 4-68str_insensitive() 4-69str_join() 4-70str_len() 4-71str_lower() 4-72str_match() 4-73str_pad() 4-75str_replace() 4-76

str_split() 4-78str_split_all() 4-79str_sub() 4-80str_upper() 4-81system() 4-91to_string() 4-82

predefined structslocker 2-31

print_line() predefined method syntax 2-8printing

struct information 2-6, 2-8product of all list items 3-76pseudo-methods 3-1

bitwise_and() 4-23bitwise_nand() 4-23bitwise_nor() 4-23bitwise_or() 4-23bitwise_xnor() 4-23bitwise_xor() 4-23declared_type() 2-24defined 2-23field() 2-28list.add(item) 3-4list.add(list) 3-5list.add0(item) 3-7list.add0(list) 3-8list.all() 3-67list.all_indices() 3-70list.and_all() 3-72list.apply() 3-26list.average() 3-73list.clear() 3-9list.count() 3-29list.crc_32() 3-81list.crc_32_flip() 3-84list.crc_8() 3-80list.delete() 3-11list.exists() 3-30list.fast_delete() 3-13list.field 3-32list.first() 3-33list.first_index() 3-34

e Libraries Preliminary Index-7

Page 302: Prelim e Lib

Index

0

list.get_indices() 3-36list.has() 3-37list.insert(index, item) 3-14list.insert(index, list) 3-16list.is_a_permutation() 3-39list.is_empty() 3-40list.key() 3-86list.key_exists() 3-89list.key_index() 3-87list.last() 3-42list.last_index() 3-44list.max() 3-45list.max_index() 3-47list.max_value() 3-48list.min() 3-50list.min_index() 3-52list.min_value() 3-53list.or_all() 3-75list.pop() 3-17list.pop0() 3-18list.product() 3-76list.push() 3-19list.push0() 3-21list.resize() 3-22list.reverse() 3-55list.size() 3-56list.sort() 3-57list.split() 3-61list.sum() 3-78list.top() 3-63list.top0() 3-64list.unique() 3-65pack() 4-38sort_by_field() 3-59source_location() 2-30swap() 4-47type() 2-26unpack() 4-42unsafe() 2-29using 3-2

Qqueues, emulating with top0() and pop0()

3-64quit() predefined method

syntax 2-9quote() string routine syntax 4-65quotes, adding to strings 4-65

Rrelease() predefined TCM syntax 2-31resource sharing 2-31routine action syntax 4-141routines

calling 4-141parameters 4-141See alsopredefined routines

run() predefined methodsyntax 2-10

Sscalar

typesaccessing all values of 4-35

scalar typesaccessing all values 4-35

semaphore methods 2-31set_unit() predefined method syntax 2-23shallow copy, of expression 2-5shared resources 2-31source files

line number in module, finding 2-30module in, finding 2-30

source_location() pseudo-method syntax2-30

spawn() OS routine syntax 4-89spawn_check() OS command routine 4-9state => state transition syntax 5-5state action block syntax 5-8state machine action syntax 5-2state machines

Index-8 Preliminary e Libraries

Page 303: Prelim e Lib

Index

defining 5-2example 5-9initializing 5-10nested 5-13parallel 5-14state holder expression 5-3terminating 5-4, 5-11transition block 5-4transitions 5-12

any-state-to-state 5-6state-to-state 5-5

state transition syntax*=> state 5-6state => state 5-5

states.Seestate machinesstr_chop() string routine syntax 4-66str_empty() string routine syntax 4-67str_exactly() string routine syntax 4-68str_insensitive() string routine syntax 4-69str_join() string routine syntax 4-70str_len() string routine syntax 4-71str_lower() string routine syntax 4-72str_match() string routine syntax 4-73str_pad() string routine syntax 4-75str_replace() string routine syntax 4-76str_split() string routine syntax 4-78str_split_all() string routine syntax 4-79str_sub() string routine syntax 4-80str_upper() string routine syntax 4-81strings

appending 4-59binary representation 4-61decimal representation 4-62formatted 4-60hexadecimal representation 4-64lists of 4-70

casechanging to lowercase 4-72changing to uppercase 4-81

case sensitivity, changing 4-69changing length of 4-68checking if empty 4-67

concatenating 4-59binary representation 4-61decimal representation 4-62formatted 4-60hexadecimal representation 4-64lists of 4-70

converting expressions to 4-82extracting substrings 4-80length, getting 4-71matching 4-73operations 4-57padding with blanks 4-75quoting 4-65replacing substrings 4-76splitting 4-78, 4-79truncating 4-66writing to files 4-107, 4-132

structsfile descriptor 4-97initializing 2-7instances, deactivating 2-9predefined

locker 2-31predefined methods for 2-4printing information about 2-6reading from files 4-133writing to files 4-133

sublists, creating 3-67sum, of all list items 3-78swap() pseudo-method syntax 4-47syntax notation for e constructs 1-3sys.init() predefined method syntax 2-2sys.run() predefined method

syntax 2-3system calls 4-89, 4-90, 4-91, 4-92, 4-93system() OS routine syntax 4-91

TTCMs

controlling execution of 2-31sharing resources 2-31starting 2-3, 2-10

e Libraries Preliminary Index-9

Page 304: Prelim e Lib

Index

threadsterminating 2-9

testcommand

predefined methods called by 2-4threads

terminatingat end of tick 2-9

to_string() string routine syntax 4-82transitions

See alsostate machines transitionstry_enclosing_unit() predefined method

syntax 2-21type casting

between scalars and lists of scalars4-26

between strings and scalars or lists ofscalars 4-28

between structs, struct subtypes, andlists of structs 4-29

type conversionbetween scalars and lists of scalars

4-26between strings and scalars or lists of

scalars 4-28between structs, struct subtypes, and

lists of structs 4-29type() pseudo-method syntax 2-26

Uunbounded integer, and packing 4-39units

displaying instances of a unit 4-36UNIX environment variables, getting 4-94unpack() pseudo-method syntax 4-42unsafe() pseudo-method syntax 2-29until option

state machine action 5-3user-defined

methodsstarting 2-3, 2-10

Index-10 Preliminary e Libraries