yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Yosys::LibertyParser Struct Reference

#include <libparse.h>

+ Collaboration diagram for Yosys::LibertyParser:

Public Member Functions

 LibertyParser (std::istream &f)
 
 ~LibertyParser ()
 
int lexer (std::string &str)
 
LibertyAstparse ()
 
void error ()
 

Data Fields

std::istream & f
 
int line
 
LibertyAstast
 

Detailed Description

Definition at line 42 of file libparse.h.

Constructor & Destructor Documentation

Yosys::LibertyParser::LibertyParser ( std::istream &  f)
inline

Definition at line 47 of file libparse.h.

47 : f(f), line(1), ast(parse()) {}
LibertyAst * parse()
Definition: libparse.cc:167
std::istream & f
Definition: libparse.h:44
LibertyAst * ast
Definition: libparse.h:46
Yosys::LibertyParser::~LibertyParser ( )
inline

Definition at line 48 of file libparse.h.

48 { if (ast) delete ast; }
LibertyAst * ast
Definition: libparse.h:46

Member Function Documentation

void LibertyParser::error ( )

Definition at line 232 of file libparse.cc.

233 {
234  log_error("Syntax error in line %d.\n", line);
235 }
void log_error(const char *format,...)
Definition: log.cc:204

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int LibertyParser::lexer ( std::string &  str)

Definition at line 87 of file libparse.cc.

88 {
89  int c;
90 
91  do {
92  c = f.get();
93  } while (c == ' ' || c == '\t' || c == '\r');
94 
95  if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.') {
96  str = c;
97  while (1) {
98  c = f.get();
99  if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.')
100  str += c;
101  else
102  break;
103  }
104  f.unget();
105  // fprintf(stderr, "LEX: identifier >>%s<<\n", str.c_str());
106  return 'v';
107  }
108 
109  if (c == '"') {
110  str = c;
111  while (1) {
112  c = f.get();
113  if (c == '\n')
114  line++;
115  str += c;
116  if (c == '"')
117  break;
118  }
119  // fprintf(stderr, "LEX: string >>%s<<\n", str.c_str());
120  return 'v';
121  }
122 
123  if (c == '/') {
124  c = f.get();
125  if (c == '*') {
126  int last_c = 0;
127  while (c > 0 && (last_c != '*' || c != '/')) {
128  last_c = c;
129  c = f.get();
130  if (c == '\n')
131  line++;
132  }
133  return lexer(str);
134  } else if (c == '/') {
135  while (c > 0 && c != '\n')
136  c = f.get();
137  line++;
138  return lexer(str);
139  }
140  f.unget();
141  // fprintf(stderr, "LEX: char >>/<<\n");
142  return '/';
143  }
144 
145  if (c == '\\') {
146  c = f.get();
147  if (c == '\r')
148  c = f.get();
149  if (c == '\n')
150  return lexer(str);
151  f.unget();
152  return '\\';
153  }
154 
155  if (c == '\n') {
156  line++;
157  return ';';
158  }
159 
160  // if (c >= 32 && c < 255)
161  // fprintf(stderr, "LEX: char >>%c<<\n", c);
162  // else
163  // fprintf(stderr, "LEX: char %d\n", c);
164  return c;
165 }
std::istream & f
Definition: libparse.h:44
int lexer(std::string &str)
Definition: libparse.cc:87

+ Here is the caller graph for this function:

LibertyAst * LibertyParser::parse ( )

Definition at line 167 of file libparse.cc.

168 {
169  std::string str;
170 
171  int tok = lexer(str);
172 
173  while (tok == ';')
174  tok = lexer(str);
175 
176  if (tok == '}' || tok < 0)
177  return NULL;
178 
179  if (tok != 'v')
180  error();
181 
182  LibertyAst *ast = new LibertyAst;
183  ast->id = str;
184 
185  while (1)
186  {
187  tok = lexer(str);
188 
189  if (tok == ';')
190  break;
191 
192  if (tok == ':' && ast->value.empty()) {
193  tok = lexer(ast->value);
194  if (tok != 'v')
195  error();
196  continue;
197  }
198 
199  if (tok == '(') {
200  while (1) {
201  std::string arg;
202  tok = lexer(arg);
203  if (tok == ',')
204  continue;
205  if (tok == ')')
206  break;
207  if (tok != 'v')
208  error();
209  ast->args.push_back(arg);
210  }
211  continue;
212  }
213 
214  if (tok == '{') {
215  while (1) {
216  LibertyAst *child = parse();
217  if (child == NULL)
218  break;
219  ast->children.push_back(child);
220  }
221  break;
222  }
223 
224  error();
225  }
226 
227  return ast;
228 }
std::string id
Definition: libparse.h:32
std::vector< std::string > args
Definition: libparse.h:33
LibertyAst * parse()
Definition: libparse.cc:167
std::string value
Definition: libparse.h:32
#define NULL
LibertyAst * ast
Definition: libparse.h:46
int lexer(std::string &str)
Definition: libparse.cc:87
std::vector< LibertyAst * > children
Definition: libparse.h:34

+ Here is the call graph for this function:

Field Documentation

LibertyAst* Yosys::LibertyParser::ast

Definition at line 46 of file libparse.h.

std::istream& Yosys::LibertyParser::f

Definition at line 44 of file libparse.h.

int Yosys::LibertyParser::line

Definition at line 45 of file libparse.h.


The documentation for this struct was generated from the following files: