• Skip to main content
  • Skip to search
  • Skip to footer
Cadence Home
  • This search text may be transcribed, used, stored, or accessed by our third-party service providers per our Cookie Policy and Privacy Policy.

  1. Community Forums
  2. Custom IC Design
  3. $fscanf and $fget do not work when any portion of Verilog...

Stats

  • Replies 0
  • Subscribers 131
  • Views 39
  • Members are here 0

$fscanf and $fget do not work when any portion of Verilog-A file is encrypted

ConradJ
ConradJ 3 hours ago

$fscanf and $fget appear to return empty strings if any portion of the Verilog-A file is encrypted, but work fine if the encrypted portion is removed.

This Verilog-A code reads in data from an external file and prints some information to the spectre log. The file example.txt contains the phrase "You should see this".


// VerilogA for VerilogA_Bug_Example, ReadFile, veriloga

`include "constants.vams"
`include "disciplines.vams"

module ReadFile;

parameter string file_location="/home/USER/example.txt";
integer myChanDesc;
string temp;

// pragma protect
// pragma protect begin
    analog function real doNothing;
        input x;
        real x;

        begin
            doNothing = x;
        end 
    endfunction
// pragma protect end

analog begin

    @(initial_step) begin
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        myChanDesc = $fopen(file_location, "r");
        $strobe("Channel Descriptor: %d", myChanDesc); 
        $strobe("Path: %s", $cds_get_resolved_path( myChanDesc )); 
        $fgets(temp, myChanDesc);
        $strobe("First Line: %s", temp); 
        $strobe("Non-zero if end-of-line: %d", $feof(myChanDesc));
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    end

end

endmodule


The above code correctly returns the following when run in a transient simulation by Spectre APS:

Channel Descriptor: 2
Path: /home/jensenct/txt.txt
First Line: You should see this

Non-zero if end-of-line: 0

After running the below command to encrypt the "doNothing" function the below code is produced. (Note the encrypted blob was removed for security reasons).

/apps/cadence/SPECTRE231/tools.lnx86/bin/64bit/xmprotect -language vlog verilog.va


// VerilogA for VerilogA_Bug_Example, ReadFile, veriloga

`include "constants.vams"
`include "disciplines.vams"

module ReadFile;

parameter string file_location="/home/USER/example.txt";
integer myChanDesc;
string temp;

//pragma protect begin_protected
//pragma protect encrypt_agent="NCPROTECT"
//pragma protect encrypt_agent_info="Encrypted using API"
//pragma protect key_keyowner=Cadence Design Systems.
//pragma protect key_keyname=prv(CDS_RSA_KEY_VER_2)
//pragma protect key_method=RSA
//pragma protect key_block
removed for security
//pragma protect end_key_block

//pragma protect digest_block
removed for security
//pragma protect end_digest_block
//pragma protect data_block
removed for security
//pragma protect end_data_block
//pragma protect digest_block
removed for security
//pragma protect end_digest_block
//pragma protect end_protected

analog begin

    @(initial_step) begin
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        myChanDesc = $fopen(file_location, "r");
        $strobe("Channel Descriptor: %d", myChanDesc); 
        $strobe("Path: %s", $cds_get_resolved_path( myChanDesc )); 
        $fgets(temp, myChanDesc);
        $strobe("First Line: %s", temp); 
        $strobe("Non-zero if end-of-line: %d", $feof(myChanDesc));
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        $strobe("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
    end

end

endmodule


Which incorrectly returns the following when run using the same test bench:

Channel Descriptor: 2
Path: /home/USER/example.txt
First Line: 
Non-zero if end-of-line: 0

Running $ftell after trying to read several lines still returns 0. This issue also appears to impact $fscanf. 

  • Cancel
  • Sign in to reply

Community Guidelines

The Cadence Design Communities support Cadence users and technologists interacting to exchange ideas, news, technical information, and best practices to solve problems and get the most from Cadence technology. The community is open to everyone, and to provide the most value, we require participants to follow our Community Guidelines that facilitate a quality exchange of ideas and information. By accessing, contributing, using or downloading any materials from the site, you agree to be bound by the full Community Guidelines.

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

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