Never miss a story from System, PCB, & Package Design . Subscribe for in-depth analysis and articles.
The 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.
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:
· Displays data in the default format
· Displays a single data value
· A newline character follows the data value
· Displays formatted output
· Displays multiple data values
The following illustration shows the difference between the print, printf, and println functions:
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:
To print accurate output, it is essential to understand the key print function supported in SKILL.
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. 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:
Any SKILL value
Level of nesting that you want to print. Lists nested deeper than the maximum level specified are abbreviated as “&”.
Specifies the length (or a maximum number of elements) you want to print. List elements beyond the maximum number specified are abbreviated as “...”.
Prints to the output port just like fprintf. By default, the output is displayed on the screen.
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:
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.
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.
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 :
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:
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:
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:
The printstruct prints the contents of the association table as shown in the following image:
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:
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:
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.
For any feedback or any topics you want us to include in our blogs, write to us at email@example.com.
Subscribe to stay updated about our upcoming blogs.
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.