diff options
author | Keith Rothman <537074+litghost@users.noreply.github.com> | 2021-02-11 15:29:53 -0800 |
---|---|---|
committer | Keith Rothman <537074+litghost@users.noreply.github.com> | 2021-02-12 10:31:04 -0800 |
commit | c96d0f225c19059e2eb91b66934e7f01e5e5b43e (patch) | |
tree | ea489b7f23d322b05673692cbdef43d72ae9fe1d | |
parent | d987bd2997e51e1cbe0681b791adfc685753955c (diff) | |
download | nextpnr-c96d0f225c19059e2eb91b66934e7f01e5e5b43e.tar.gz nextpnr-c96d0f225c19059e2eb91b66934e7f01e5e5b43e.tar.bz2 nextpnr-c96d0f225c19059e2eb91b66934e7f01e5e5b43e.zip |
Refactor XDC parser into a little class for testing purposes.
Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
-rw-r--r-- | fpga_interchange/arch.cc | 11 | ||||
-rw-r--r-- | fpga_interchange/xdc.cc | 23 | ||||
-rw-r--r-- | fpga_interchange/xdc.h | 32 |
3 files changed, 52 insertions, 14 deletions
diff --git a/fpga_interchange/arch.cc b/fpga_interchange/arch.cc index 8fd4d9dc..9263f3c4 100644 --- a/fpga_interchange/arch.cc +++ b/fpga_interchange/arch.cc @@ -33,6 +33,7 @@ #include "router2.h" #include "timing.h" #include "util.h" +#include "xdc.h" NEXTPNR_NAMESPACE_BEGIN @@ -563,6 +564,16 @@ TimingClockingInfo Arch::getPortClockingInfo(const CellInfo *cell, IdString port void Arch::read_logical_netlist(const std::string &filename) {} void Arch::write_physical_netlist(const std::string &filename) const {} +void Arch::parse_xdc(const std::string &filename) { + TclInterp interp(getCtx()); + auto result = Tcl_EvalFile(interp.interp, filename.c_str()); + if(result != TCL_OK) { + log_error("Error in %s:%d => %s\n", filename.c_str(), + Tcl_GetErrorLine(interp.interp), + Tcl_GetStringResult(interp.interp)); + } +} + // ----------------------------------------------------------------------- #ifdef WITH_HEAP diff --git a/fpga_interchange/xdc.cc b/fpga_interchange/xdc.cc index ee1d1cab..ece662f8 100644 --- a/fpga_interchange/xdc.cc +++ b/fpga_interchange/xdc.cc @@ -18,9 +18,9 @@ * */ +#include "xdc.h" #include "log.h" #include "nextpnr.h" -#include <tcl.h> #include <string> NEXTPNR_NAMESPACE_BEGIN @@ -139,8 +139,8 @@ static int set_property( return TCL_OK; } -void Arch::parse_xdc(const std::string &filename) { - Tcl_Interp *interp = Tcl_CreateInterp(); +TclInterp::TclInterp(Context *ctx) { + interp = Tcl_CreateInterp(); NPNR_ASSERT(Tcl_Init(interp) == TCL_OK); Tcl_RegisterObjType(&port_object); @@ -149,23 +149,18 @@ void Arch::parse_xdc(const std::string &filename) { NPNR_ASSERT(Tcl_Eval(interp, "proc unknown args {\n" " set result [scan [lindex $args 0] \"%d\" value]\n" - " if { $result == 1 && [llength $args] == 1] } {\n" + " if { $result == 1 && [llength $args] == 1 } {\n" " return \\[$value\\]\n" " } else {\n" " uplevel 1 [list _original_unknown {*}$args]\n" " }\n" "}") == TCL_OK); - Tcl_CreateObjCommand(interp, "get_ports", get_ports, getCtx(), nullptr); - Tcl_CreateObjCommand(interp, "set_property", set_property, getCtx(), nullptr); - auto result = Tcl_EvalFile(interp, filename.c_str()); - if(result != TCL_OK) { - log_error("Error in %s:%d => %s\n", filename.c_str(), Tcl_GetErrorLine(interp), Tcl_GetStringResult(interp)); - } - Tcl_DeleteInterp(interp); - Tcl_Finalize(); + Tcl_CreateObjCommand(interp, "get_ports", get_ports, ctx, nullptr); + Tcl_CreateObjCommand(interp, "set_property", set_property, ctx, nullptr); } +TclInterp::~TclInterp() { + Tcl_DeleteInterp(interp); +} NEXTPNR_NAMESPACE_END - - diff --git a/fpga_interchange/xdc.h b/fpga_interchange/xdc.h new file mode 100644 index 00000000..b41c86f8 --- /dev/null +++ b/fpga_interchange/xdc.h @@ -0,0 +1,32 @@ +/* + * nextpnr -- Next Generation Place and Route + * + * Copyright (C) 2021 Symbiflow Authors + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + */ + +#include "nextpnr.h" +#include <tcl.h> + +NEXTPNR_NAMESPACE_BEGIN + +struct TclInterp { + TclInterp(Context *ctx); + ~TclInterp(); + + Tcl_Interp *interp; +}; + +NEXTPNR_NAMESPACE_END |