Skip to content

Commit

Permalink
PR #283: System calls such as $display and $sformat fail if encrypted
Browse files Browse the repository at this point in the history
This patch recognizes a SystemTFIdentifier and turns off encryption for that token. Otherwise the obfuscated Verilog cannot be compiled if it contains such calls.

GitHub PR #283

Copybara import of the project:

  - 095fae5 System calls such as  and  fail if encrypted by Jonathan Kimmitt <[email protected]>
  - 04a1b60 Correct testcases for unencrypted  tasks (fixes #282) by Jonathan Kimmitt <[email protected]>

Closes #283
fixes #282

PiperOrigin-RevId: 309820780
  • Loading branch information
jonathankimmitt authored and hzeller committed May 4, 2020
1 parent dec5e6a commit 2c98e20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 5 additions & 1 deletion verilog/transform/obfuscate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,13 @@ static void ObfuscateVerilogCodeInternal(absl::string_view content,
case verilog_tokentype::PP_Identifier:
*output << (*subst)(token.text);
break;
// Preserve all $ID calls, including system task/function calls, and VPI
// calls
case verilog_tokentype::SystemTFIdentifier:
*output << token.text;
break;
// The following identifier types start with a special character that
// needs to be preserved.
case verilog_tokentype::SystemTFIdentifier:
case verilog_tokentype::MacroIdentifier:
case verilog_tokentype::MacroCallId:
// TODO(fangism): verilog_tokentype::EscapedIdentifier
Expand Down
6 changes: 3 additions & 3 deletions verilog/transform/obfuscate_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ TEST(ObfuscateVerilogCodeTest, PreloadedSubstitutions) {
"`ifdef AAA\n`elsif CCC\n`else\n`endif\n"},
{"`define ccc bbb+aaa\n", "`define CCC BBB+AAA\n"},
{"`define ccc `bbb+`aaa\n", "`define CCC `BBB+`AAA\n"},
{"task bbb;\n $aaa;\nendtask\n", "task BBB;\n $AAA;\nendtask\n"},
{"task bbb;\n $aaa();\nendtask\n", "task BBB;\n $AAA();\nendtask\n"},
{"task bbb;\n $aaa;\nendtask\n", "task BBB;\n $aaa;\nendtask\n"},
{"task bbb;\n $aaa();\nendtask\n", "task BBB;\n $aaa();\nendtask\n"},
{"task bbb;\n $aaa($ccc());\nendtask\n",
"task BBB;\n $AAA($CCC());\nendtask\n"},
"task BBB;\n $aaa($ccc());\nendtask\n"},
{"function aaa()\nreturn bbb^ccc;\nendfunction\n",
"function AAA()\nreturn BBB^CCC;\nendfunction\n"},
{"function aaa()\nreturn bbb(ccc);\nendfunction\n",
Expand Down

0 comments on commit 2c98e20

Please sign in to comment.