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)
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)
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)
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