24 static bool read_next_line(
char *&buffer,
size_t &buffer_size,
int &line_count, FILE *f)
31 buffer_len += strlen(buffer + buffer_len);
32 while (buffer_len > 0 && (buffer[buffer_len-1] ==
' ' || buffer[buffer_len-1] ==
'\t' ||
33 buffer[buffer_len-1] ==
'\r' || buffer[buffer_len-1] ==
'\n'))
34 buffer[--buffer_len] = 0;
36 if (buffer_size-buffer_len < 4096) {
38 buffer = (
char*)realloc(buffer, buffer_size);
41 if (buffer_len == 0 || buffer[buffer_len-1] ==
'\\') {
42 if (buffer_len > 0 && buffer[buffer_len-1] ==
'\\')
43 buffer[--buffer_len] = 0;
45 if (fgets(buffer+buffer_len, buffer_size-buffer_len, f) ==
NULL)
60 module->
name =
"\\netlist";
63 size_t buffer_size = 4096;
64 char *buffer = (
char*)
malloc(buffer_size);
72 continue_without_read:
79 for (
auto &bit : lutptr->
bits)
81 bit = lut_default_state;
86 char *cmd = strtok(buffer,
" \t\r\n");
88 if (!strcmp(cmd,
".model"))
91 if (!strcmp(cmd,
".end")) {
97 if (!strcmp(cmd,
".inputs") || !strcmp(cmd,
".outputs")) {
99 while ((p = strtok(
NULL,
" \t\r\n")) !=
NULL) {
101 if (!strcmp(cmd,
".inputs"))
109 if (!strcmp(cmd,
".latch"))
111 char *d = strtok(
NULL,
" \t\r\n");
112 char *q = strtok(
NULL,
" \t\r\n");
126 if (!strcmp(cmd,
".gate"))
128 char *p = strtok(
NULL,
" \t\r\n");
134 while ((p = strtok(
NULL,
" \t\r\n")) !=
NULL) {
135 char *q = strchr(p,
'=');
136 if (q ==
NULL || !q[0] || !q[1])
146 if (!strcmp(cmd,
".names"))
150 while ((p = strtok(
NULL,
" \t\r\n")) !=
NULL) {
159 output_sig = input_sig.
extract(input_sig.
size()-1, 1);
160 input_sig = input_sig.
extract(0, input_sig.
size()-1);
162 if (input_sig.
size() == 0) {
167 for (
int i = 0; buffer[i]; i++) {
168 if (buffer[i] ==
' ' || buffer[i] ==
'\t')
170 if (i == 0 && buffer[i] ==
'.')
171 goto finished_parsing_constval;
172 if (buffer[i] ==
'0') {
178 if (buffer[i] ==
'1') {
187 finished_parsing_constval:
191 goto continue_without_read;
197 cell->
setPort(
"\\A", input_sig);
198 cell->
setPort(
"\\Y", output_sig);
210 char *
input = strtok(buffer,
" \t\r\n");
211 char *output = strtok(
NULL,
" \t\r\n");
213 if (input ==
NULL || output ==
NULL || (strcmp(output,
"0") && strcmp(output,
"1")))
216 int input_len = strlen(input);
220 for (
int i = 0; i < (1 << input_len); i++) {
221 for (
int j = 0; j < input_len; j++) {
224 char c2 = (i & (1 << j)) != 0 ?
'1' :
'0';
237 log_error(
"Syntax error in line %d!\n", line_count);
std::string stringf(const char *fmt,...)
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
void add(RTLIL::Module *module)
#define YOSYS_NAMESPACE_END
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
void log_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Const > parameters
static std::string escape_id(std::string str)
RTLIL::Design * abc_parse_blif(FILE *f, std::string dff_name)
void connect(const RTLIL::SigSig &conn)
static YOSYS_NAMESPACE_BEGIN bool read_next_line(char *&buffer, size_t &buffer_size, int &line_count, FILE *f)
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
#define YOSYS_NAMESPACE_BEGIN
RTLIL::SigSpec extract(const RTLIL::SigSpec &pattern, const RTLIL::SigSpec *other=NULL) const
std::vector< RTLIL::State > bits
void append(const RTLIL::SigSpec &signal)
std::pair< SigSpec, SigSpec > SigSig