Skip to content Skip to footer

Programming Language Interface (PLI)

Programming Language Interface (PLI) is an interface which makes it possible for many programming languages to be integrated and communicate with one another. PLI acts as a bridge between different programming languages, facilitating interoperability and enabling developers to take advantage of several languages in a single application. In this article, we will explore more details about PLI along with its characteristics, advantages, and application examples.

Introduction  

PLI offers a platform for the smooth interaction of languages with various syntaxes, data types, and execution models. PLI guarantees the efficient and dependable flow of data and code by establishing a set of guidelines and procedures. An application-program interface (API) to Verilog is provided by a programming language interface. A PLI is a system that uses Verilog code to call a C function. The PLI used to link the applications containing C/C++ functions with compiler, so that they can run concurrently mixed HDL designs. The application’s C/C++ functions can be called by compiler during simulation by using the PLI to read and writing functional models, calculating delays and simulation values and getting design information in the compiler executable and these functions can be called by compiler while the simulation is running. In Verilog, the construct that calls a PLI routine is typically referred to as a “system task” or “system function” if it is a component of a simulator and as a “user-defined task” or “user-defined function” if it is written by the user.

PLI Usage: 

Some of the examples of PLI usage are mentioned below: 

  • PLI allows Verilog code to call C/C++ function. 
  • PLI allows users to extend Python by writing C/C++ code. 
  • PLI allows Java programs to call code written in C/C++ and vice versa. 
  • It provides an API that allows C++ to interact with MATLAB’S mathematical and numerical calculating capabilities.

The Basic steps for creating a PLI routine:  

  • To access the data inside VCS, write the C/C++ functions of the application calling TF and ACC routines operations. 
  • Connect user-defined system tasks or system functions to C/C+ functions.  
  • When VCS compiles the system tasks or system functions into Verilog source code, it will invoke these functions. 
  • Enter the user-defined system tasks and functions in the Verilog source code. 
  • Compile and simulate the design by including the C/C++ source files. 

Basic example of coding: 

Verilog Code: 

module test_PLI;  

reg [7:0] data; 

initial  

begin  

         data = 8’hC8;  

         $display(“Calling PLI     function”);  

         $pli_read_signal();  

         #10;  

         $finish;  

end 

endmodule 

C Lang Code: 

#include <stdio.h>  

#include <veriuser.h>  

#include <vxl_veriuser.h> 

PLI_INT32 pli_read_signal_calltf(PLI_BYTE8*user_data) {        // Function to read a signal 

               pliHandle signal;  

               plivalue value; 

signal = pli_handle_by_name(“test_PLI.data”, NULL);                // Get handle to the signal 

if (signal == NULL) { 

pli_printf(“Error: Cannot find signal”); 

return 0;  

value.format = pliIntVal;                                                          // Read the value of the signal 

pli_get_value(signal, &value); 

pli_printf(Value of ‘test_PLI.data’ = %0d\n”, value. value.integer);  

return 0; 

Output: 

>> Calling PLI function 

>> Value of ‘test_PLI.data’ = 200

Advantages of PLI: 

Some of the advantages of PLI mentioned below: 

  • PLI encourages code reusability. 
  • PLI allows us to optimize performance where it is most required. 
  • PLI enables efficient utilization of system resources. 
  • PLI enables Language Integration to combine the strengths of different programming languages. 
  • Selecting the best programming language for a given task is made flexible by PLI.

Challenges of PLI: 

  • PLI might introduce overhead in Performance. 
  • PLI can require careful considerations of error handling, memory management, and data type compatibility. 
  • PLI might have limitations in terms of the extent of interoperability between languages. 

Conclusion: 

PLI offers a standardized collection of data types, functions, and protocols that make cross-linguistic code execution and communication easier. The integration and interoperability of many programming languages are made possible in large part by PLI. Language integration, code reuse, performance improvement, and ecosystem flexibility are just a few advantages that PLI provides. For developers looking to utilize the advantages of several languages in a single application, PLI is a powerful tool. 

Leave a comment