From 198fc963ca713b3798ce9fce1872b41df8448fe8 Mon Sep 17 00:00:00 2001
From: Miodrag Milanovic <mmicko@gmail.com>
Date: Mon, 29 Apr 2024 08:18:04 +0200
Subject: [PATCH] Add new DFF types, and added "-nodffe" option

---
 techlibs/nanoxplore/synth_nanoxplore.cc | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/techlibs/nanoxplore/synth_nanoxplore.cc b/techlibs/nanoxplore/synth_nanoxplore.cc
index e34ae212e..1f6bc658c 100644
--- a/techlibs/nanoxplore/synth_nanoxplore.cc
+++ b/techlibs/nanoxplore/synth_nanoxplore.cc
@@ -73,6 +73,9 @@ struct SynthNanoXplorePass : public ScriptPass
 		log("    -nocy\n");
 		log("        do not map adders to CY cells\n");
 		log("\n");
+		log("    -nodffe\n");
+		log("        do not use flipflops with L in output netlist\n");
+		log("\n");
 		log("    -norfram\n");
 		log("        do not use Register File RAM cells in output netlist\n");
 		log("\n");
@@ -97,7 +100,7 @@ struct SynthNanoXplorePass : public ScriptPass
 	}
 
 	string top_opt, json_file, family;
-	bool flatten, abc9, nocy, norfram, nobram, nodsp, iopad, no_rw_check;
+	bool flatten, abc9, nocy, nodffe, norfram, nobram, nodsp, iopad, no_rw_check;
 	std::string postfix;
 
 	void clear_flags() override
@@ -108,6 +111,7 @@ struct SynthNanoXplorePass : public ScriptPass
 		flatten = true;
 		abc9 = false;
 		nocy = false;
+		nodffe = false;
 		norfram = false;
 		nobram = false;
 		nodsp = false;
@@ -160,6 +164,10 @@ struct SynthNanoXplorePass : public ScriptPass
 				nocy = true;
 				continue;
 			}
+			if (args[argidx] == "-nodffe") {
+				nodffe = true;
+				continue;
+			}
 			if (args[argidx] == "-norfram") {
 				norfram = true;
 				continue;
@@ -294,7 +302,14 @@ struct SynthNanoXplorePass : public ScriptPass
 
 		if (check_label("map_ffs"))
 		{
-			run("dfflegalize -cell $_DFF_?P?_ 0 -cell $_SDFF_?P?_ 0 -cell $_DLATCH_?_ x"); //-cell $_ALDFF_?P_ 0
+			std::string dfflegalize_args = " -cell $_DFF_?_ 0 -cell $_DFF_?P?_ 0 -cell $_SDFF_?P?_ 0";
+			if (help_mode) {
+				dfflegalize_args += " [-cell $_DFFE_PP_ 0 -cell $_DFFE_NN_ 0 -cell $_DFFE_?P?P_ 0 -cell $_SDFFE_?P?P_ 0]";
+			} else if (!nodffe) {
+				dfflegalize_args += " -cell $_DFFE_PP_ 0 -cell $_DFFE_NN_ 0 -cell $_DFFE_?P?P_ 0 -cell $_SDFFE_?P?P_ 0";
+			}
+			dfflegalize_args += " -cell $_DLATCH_?_ x";
+			run("dfflegalize" + dfflegalize_args,"($_*DFFE_* only if not -nodffe)");
 			run("techmap -map +/nanoxplore/latches_map.v");
 			run("techmap -map +/nanoxplore/cells_map.v");
 			run("opt_expr -undriven -mux_undef");