Skip to content

Commit 3c0011c

Browse files
committedFeb 15, 2017
WIP: Initial work on constraint file support. Not yet usable.
1 parent da9be6a commit 3c0011c

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
lines changed
 

‎doc/gp4-hdl.tex

+26-5
Original file line numberDiff line numberDiff line change
@@ -261,18 +261,39 @@ \subsection{\namestyle{Yosys} Verilog Inference Limitations for GreenPAK}
261261
\pagebreak
262262
\section{\namestyle{gp4par} HDL Constraints}
263263

264-
There is only one supported constraint entry format at this time, Verilog attributes. There is currently no support for
265-
adding constraints to netlist entities via external constraint files or command line arguments. The general format of a
266-
constraint with name \tokenstyle{FOO} and value 42 applied to the register \wirestyle{foobar} is shown in Figure
267-
\ref{constraint}.
264+
Constraints may be entered by Verilog attributes or an external Physical Constraints File (.pcf) file. In the event of
265+
a conflict, the PCF takes precedence over constraints in the Verilog. If two constraints in the same PCF file conflict,
266+
the later constraint takes precedence.
267+
268+
\subsection{Verilog attributes}
269+
270+
The general format of a constraint with name \tokenstyle{FOO} and value 42 applied to the register \wirestyle{foobar}
271+
is shown in Figure \ref{constraint-verilog}.
268272

269273
\begin{figure}[h]
270274
\begin{lstlisting}
271275
(* FOO=42 *)
272276
reg[3:0] foobar = 0;
273277
\end{lstlisting}
274278
\caption{Example Verilog attribute constraint}
275-
\label{constraint}
279+
\label{constraint-verilog}
280+
\end{figure}
281+
282+
\subsection{PCF constraints}
283+
284+
\namestyle{gp4par} PCF files used a syntax similar to that of the industry standard Synopsys Design Constraints (SDC).
285+
Only constraints are supported; arbitrary TCL cannot be used.
286+
287+
The general format of a constraint with name \tokenstyle{FOO} and value 42 applied to the register \wirestyle{foobar}
288+
is shown in Figure \ref{constraint-pcf}.
289+
290+
\begin{figure}[h]
291+
\begin{lstlisting}
292+
# set some random attribute
293+
set_foo foobar 42
294+
\end{lstlisting}
295+
\caption{Example PCF constraint}
296+
\label{constraint-pcf}
276297
\end{figure}
277298

278299
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

‎src/gp4par/main.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,9 @@ int main(int argc, char* argv[])
328328
void ShowUsage()
329329
{
330330
printf(// v 80th column
331-
"Usage: gp4par -p part -o bitstream.txt netlist.json\n"
331+
"Usage: gp4par [options] -p part -o bitstream.txt netlist.json\n"
332+
" -c <file>\n"
333+
" Reads placement constraints from <file>\n"
332334
" --debug\n"
333335
" Prints lots of internal debugging information.\n"
334336
" --disable-charge-pump\n"

‎src/greenpak4/Greenpak4Netlist.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Greenpak4NetlistEntity::~Greenpak4NetlistEntity()
2828
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2929
// Construction / destruction
3030

31-
Greenpak4Netlist::Greenpak4Netlist(std::string fname)
31+
Greenpak4Netlist::Greenpak4Netlist(string fname, string constraint_file)
3232
: m_topModule(NULL)
3333
, m_parseOK(true)
3434
{
@@ -94,6 +94,19 @@ Greenpak4Netlist::Greenpak4Netlist(std::string fname)
9494
json_object_put(object);
9595
json_tokener_free(tok);
9696
delete[] json_string;
97+
98+
//Read the constraint file (if we have one)
99+
if(constraint_file == "")
100+
return;
101+
fp = fopen(constraint_file.c_str(), "r");
102+
if(fp == NULL)
103+
{
104+
LogError("Failed to open constraint file %s\n", fname.c_str());
105+
m_parseOK = false;
106+
return;
107+
}
108+
LoadConstraints(fp);
109+
fclose(fp);
97110
}
98111

99112
Greenpak4Netlist::~Greenpak4Netlist()
@@ -107,6 +120,14 @@ Greenpak4Netlist::~Greenpak4Netlist()
107120
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
108121
// Parsing stuff
109122

123+
/**
124+
@brief Parsing for a PCF file
125+
*/
126+
void Greenpak4Netlist::LoadConstraints(FILE* fp)
127+
{
128+
129+
}
130+
110131
/**
111132
@brief Top-level parsing routine
112133

‎src/greenpak4/Greenpak4Netlist.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
class Greenpak4Netlist
3434
{
3535
public:
36-
Greenpak4Netlist(std::string fname);
36+
Greenpak4Netlist(std::string fname, std::string constraint_file = "");
3737
virtual ~Greenpak4Netlist();
3838

3939
Greenpak4NetlistModule* GetTopModule()
@@ -64,6 +64,7 @@ class Greenpak4Netlist
6464
//Init helpers
6565
void Load(json_object* object);
6666
void LoadModules(json_object* object);
67+
void LoadConstraints(FILE* fp);
6768

6869
std::string m_creator;
6970

‎tests/greenpak4/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function(add_greenpak4_bitstream name part)
6969
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt"
7070
COMMAND gp4par "--stdout-only"
7171
--usercode 41
72-
--quiet
72+
# --quiet
7373
--part ${part}
7474
--output "${CMAKE_CURRENT_BINARY_DIR}/${name}.txt"
7575
--logfile "${CMAKE_CURRENT_BINARY_DIR}/${name}-par.log"

‎tests/greenpak4/slg46620v/Location.v

+4-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
`default_nettype none
2020

21-
module Location(a, b, c, d, e);
21+
module Location(a, b, c, d, e, f);
2222

2323
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2424
// I/O declarations
@@ -41,6 +41,9 @@ module Location(a, b, c, d, e);
4141
(* LOC = "P16" *)
4242
input wire e;
4343

44+
//LOC'd by constraint file
45+
output wire f;
46+
4447
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4548
// Clock/reset stuff
4649

0 commit comments

Comments
 (0)
Please sign in to comment.