Home
  • Products
  • Solutions
  • Support
  • Company
  • Products
  • Solutions
  • Support
  • Company
Community System, PCB, & Package Design  BoardSurfers: A Deep Dive Into the Print Functions in S…

Author

Kirti Sikri
Kirti Sikri

Community Member

Blog Activity
Options
  • Subscriptions

    Never miss a story from System, PCB, & Package Design . Subscribe for in-depth analysis and articles.

    Subscribe by email
  • More
  • Cancel
spb22.1
BoardSurfers
22.1
PCB design
Allegro PCB Editor
SKILL

BoardSurfers: A Deep Dive Into the Print Functions in SKILL

2 May 2023 • 8 minute read

logoThe ability to display the output is a crucial aspect of programming languages. The print functions enable programmers to display output in the form of text, numbers, and other data at the console or store it in a file, which helps in debugging, testing, and completing a program. Cadence SKILL is an interactive and robust functional programming language that seamlessly integrates into various Cadence applications across domains, including IC and PCB. With its rich APIs, SKILL is an effective extension language that enables you to customize and extend the design environment.

In SKILL programming, the print functions are just as important as they are in any other programming language. In Allegro platform products that lack an integrated development environment (IDE), the print functions are even more crucial because they offer valuable insights into the code behavior. SKILL provides a range of print functions, including print, println, printf, fprintf, and others to print the output. This post delves into the various print functions and how you can use them effectively.

Displaying Output on the Console

You use the print, println, and printf functions to display the output data on the console. The following table provides a brief description of each of these functions:

Function

Description

print

·        Displays data in the default format

·        Displays a single data value

println

·        Displays data in the default format

·        Displays a single data value

·        A newline character follows the data value

printf

·        Displays formatted output

·        Displays multiple data values

The following illustration shows the difference between the  print, printf, and println functions:

 print functions in Cadence SKILL

Writing Output to a File

To write the output to a file, an optional output port parameter is used with the print and println functions, and a mandatory port parameter is used with the fprintf function. The  print and println write the data in the default format, whereas the fprintf function writes formatted data.

The first argument of the fprintf function is an output port associated with the file.

To write data to a file:

  1. Enter outfile to open the output port on a file.
  2. Enter print, println, or fprintf to write using the output port.
  3. Enter close to close the file.

Examples

  1. The following sample code writes the numbers 1, 2, and 3 to the file file_print.txt using the println function:
printPort = outfile( "file_print.txt" )
for( i 1 3
println( list( "Writing Number using println:" i) printPort )
)
close( printPort )

 sample_code 

  1. The following code writes the numbers 1, 2, and 3 to the file file_print.txt using fprintf function:
printPort1 = outfile( "file_fprintf.txt" )
for( i 1 3
fprintf( myPort "Number: %d\n" i )
)
close( myPort )

SKILL fprintf example code

Key Print Functions in SKILL

To print accurate output, it is essential to understand the key print function supported in SKILL.

pprint

The pprint function is useful for printing a long list in multiple lines to make the text more readable. Therefore, this type of printing is called pretty printing. The print function prints the list on one line, while pprint prints it out in multiple lines. 

 SKILL pprint example

printlev

The printlev function prints a list with a limited number of elements and levels of nesting. Lists are usually printed in their entirety, regardless of the number of elements they have or how deeply nested they are. The printlev function requires the following arguments specifying the maximum level and length to print:

Argument

Description

g_value

Any SKILL value

x_level

Level of nesting that you want to print. Lists nested deeper than the maximum level specified are abbreviated as “&”.

x_length

Specifies the length (or a maximum number of elements) you want to print. List elements beyond the maximum number specified are abbreviated as “...”.

p_outputPort

Prints to the output port just like fprintf. By default, the output is displayed on the screen.

Examples

List = '(1 2 (3 (4 (5))) 6)' is a deeply nested list with four elements. The first 2 elements as 1 and 2 , fourth element as 6, and the third element is a list, (3 (4 (5))), where the first element is 3, second element is a list (4 (5)) and the second element again a list with just one element (5).

The following table shows some examples of printing a nested list using printlev:

Case

Code

If the level of nesting is x_level=100 and the maximum number of elements to print is x_length=2, only first two elements 1 and 2 are printed.

 printlev(List 100 2)output is (1 2 ...)                                              
If the level of nesting is x_level=3  and the maximum number of elements to print is x_length=100, all the elements are printed. However, because the level of nesting is set to 3, elements of the list at a deeper level, (5)  appears as &. printlev(List 3 100)output is (1 2 (3 (4 &)) 6)

If the level of nesting is x_level=3  and the maximum number of elements to print is x_length = 3, only the first three elements 1,2 and  (3 (4 (5))) are printed. However, as the level of nesting is set to 3, only 3 and 4 are printed; the deeper element 5 is not printed; only & is printed.

printlev(List 3 3) output is (1 2 (3 (4 &)) ...)
 

Now, a question for you.

What do you think would be the output for printlev(List 3 4) and printlev(List 4 3)?  You can find the answers at the end of the post.

The following image illustrates a few examples of the usage of printlev :

SKILL printlev example code
 

defstruct

In SKILL programming, defstruct is a named structure that is a collection of one or more variables. The variables can be of different types and are grouped under a single name for easy handling. They are the equivalent of structs in the C language. The  defstruct function also creates a constructor function, make_name, where the name is the structure name supplied to defstruct. The constructor function takes keyword arguments, one for each slot in the structure.

In the following example defstruct defines a structure called point with x and y coordinates, the function make_point creates the variable of type point with arguments ?x and ?y:

defstruct(point x y)
defstruct(bbox ll ur)
p1 = make_point(?x 100 ?y 200)
p2 = make_point(?x 0 ?y 0)
b1 = make_bbox()
b1->ll = p1
b1->ur = p2

printstruct

For debugging, the printstruct function prints the contents of a structure in an easily readable form. It recursively prints nested structures.

The SKILL code for defining and using the structure, point, and a bounding box which accepts the lower-left and upper-right values, is as follows:

printstruct(b1)

SKILL printstruct example code

printstruct for Association Table

SKILL provides an association table as a collection of key or value pairs, called dictionary or hash table. An example of an association table is as follows:

myTable = makeTable("atable1" 0)
myTable[1] = "blue" 
myTable["two"] = '(r e d) 
myTable["three"] = 'green 
 

The printstruct prints the contents of the association table as shown in the following image:

 SKILL printstruct example code 2

drain

While reading or writing, the APIs do not directly write data to the output display or disk. Instead, the data is stored in RAM, unless it is full or you explicitly free up (flush) the memory. In the C programming language, fflush() is typically used to clear the output buffer and move the buffered data to the display screen or the disk, if output is specified as the file output stream. The equivalent SKILL function is drain, and its usage is as follows:

drain()
drain(poport) 

Now, it's time to disclose the solution to the query about the printlev function that was asked earlier. 

 For List = '(1 2 (3 (4 (5))) 6)', the answer is as follows:

SKILL printlev code example 2

Conclusion

In summary, using print functions is crucial for SKILL programmers working in the PCB domain. The effective utilization of print functions can improve the proficiency of the developers in creating and debugging complex programs, leading to more streamlined and productive design workflows.

Contact Us

For any feedback or any topics you want us to include in our blogs, write to us at pcbbloggers@cadence.com.

Subscribe to stay updated about our upcoming blogs. 

About BoardSurfers

The BoardSurfers series provides solutions to the various tasks related to the creation and management of PCB design using the Allegro platform products. The name and logo of this series are designed to resonate with the vision of making the design and manufacturing tasks enjoyable, just like surfing the waves. Regular, new blog posts by experts cover every aspect of the PCB design process, such as library management, schematic design, constraint management, stackup design, placement, routing, artwork, verification, and much more.


© 2023 Cadence Design Systems, Inc. All Rights Reserved.

  • Terms of Use
  • Privacy
  • Cookie Policy
  • US Trademarks
  • Do Not Sell or Share My Personal Information