@@ -30,6 +30,7 @@ Greenpak4NetlistEntity::~Greenpak4NetlistEntity()
30
30
31
31
Greenpak4Netlist::Greenpak4Netlist (string fname, string constraint_file)
32
32
: m_topModule(NULL )
33
+ , m_constraintFname(constraint_file)
33
34
, m_parseOK(true )
34
35
{
35
36
// Read the netlist
@@ -94,19 +95,6 @@ Greenpak4Netlist::Greenpak4Netlist(string fname, string constraint_file)
94
95
json_object_put (object);
95
96
json_tokener_free (tok);
96
97
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);
110
98
}
111
99
112
100
Greenpak4Netlist::~Greenpak4Netlist ()
@@ -120,12 +108,60 @@ Greenpak4Netlist::~Greenpak4Netlist()
120
108
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
121
109
// Parsing stuff
122
110
111
+ void Greenpak4Netlist::LoadConstraints ()
112
+ {
113
+ // Read the constraint file (if we have one)
114
+ if (m_constraintFname == " " )
115
+ return ;
116
+ FILE* fp = fopen (m_constraintFname.c_str (), " r" );
117
+ if (fp == NULL )
118
+ {
119
+ LogError (" Failed to open constraint file %s\n " , m_constraintFname.c_str ());
120
+ m_parseOK = false ;
121
+ return ;
122
+ }
123
+ LoadConstraints (fp);
124
+ fclose (fp);
125
+ }
126
+
123
127
/* *
124
128
@brief Parsing for a PCF file
125
129
*/
126
130
void Greenpak4Netlist::LoadConstraints (FILE* fp)
127
131
{
132
+ char line[1024 ];
133
+ while (NULL != fgets (line, sizeof (line), fp))
134
+ LoadConstraint (line);
135
+ }
136
+
137
+ void Greenpak4Netlist::LoadConstraint (const char * line)
138
+ {
139
+ // Remove leading spaces
140
+ while (isspace (line[0 ]))
141
+ line++;
142
+
143
+ // Skip empty lines and comments
144
+ if (line[0 ] == ' \0 ' )
145
+ return ;
146
+ if (line[0 ] == ' #' )
147
+ return ;
148
+
149
+ // Parse the constraint
150
+ char target[512 ];
151
+ char name[512 ];
152
+ char value[512 ];
153
+ if (3 != sscanf (line, " set_%511s %511s %511s" , name, target, value))
154
+ {
155
+ LogError (" Ignoring malformed constraint %s\n " , line);
156
+ return ;
157
+ }
158
+
159
+ // Convert the name to uppercase
160
+ for (int i=0 ; i<512 && name[i]; i++)
161
+ name[i] = toupper (name[i]);
128
162
163
+ // Apply it
164
+ m_topModule->AddWireAttribute (target, name, value);
129
165
}
130
166
131
167
/* *
0 commit comments