mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-13 04:28:18 +00:00
spaces -> tabs
This commit is contained in:
parent
9d9cc8a314
commit
1f7f54e68e
|
@ -87,12 +87,12 @@ int LibertyParser::lexer(std::string &str)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
// eat whitespace
|
// eat whitespace
|
||||||
do {
|
do {
|
||||||
c = f.get();
|
c = f.get();
|
||||||
} while (c == ' ' || c == '\t' || c == '\r');
|
} while (c == ' ' || c == '\t' || c == '\r');
|
||||||
|
|
||||||
// search for identifiers, numbers, plus or minus.
|
// search for identifiers, numbers, plus or minus.
|
||||||
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.') {
|
if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || ('0' <= c && c <= '9') || c == '_' || c == '-' || c == '+' || c == '.') {
|
||||||
str = c;
|
str = c;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -114,8 +114,8 @@ int LibertyParser::lexer(std::string &str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it wasn't an identifer, number of array range,
|
// if it wasn't an identifer, number of array range,
|
||||||
// maybe it's a string?
|
// maybe it's a string?
|
||||||
if (c == '"') {
|
if (c == '"') {
|
||||||
str = "";
|
str = "";
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -130,7 +130,7 @@ int LibertyParser::lexer(std::string &str)
|
||||||
return 'v';
|
return 'v';
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it wasn't a string, perhaps it's a comment or a forward slash?
|
// if it wasn't a string, perhaps it's a comment or a forward slash?
|
||||||
if (c == '/') {
|
if (c == '/') {
|
||||||
c = f.get();
|
c = f.get();
|
||||||
if (c == '*') { // start of '/*' block comment
|
if (c == '*') { // start of '/*' block comment
|
||||||
|
@ -153,7 +153,7 @@ int LibertyParser::lexer(std::string &str)
|
||||||
return '/'; // a single '/' charater.
|
return '/'; // a single '/' charater.
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for a backslash
|
// check for a backslash
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
c = f.get();
|
c = f.get();
|
||||||
if (c == '\r')
|
if (c == '\r')
|
||||||
|
@ -164,14 +164,14 @@ int LibertyParser::lexer(std::string &str)
|
||||||
return '\\';
|
return '\\';
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for a new line
|
// check for a new line
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
line++;
|
line++;
|
||||||
return 'n';
|
return 'n';
|
||||||
}
|
}
|
||||||
|
|
||||||
// anything else, such as ';' will get passed
|
// anything else, such as ';' will get passed
|
||||||
// through as literal items.
|
// through as literal items.
|
||||||
|
|
||||||
// if (c >= 32 && c < 255)
|
// if (c >= 32 && c < 255)
|
||||||
// fprintf(stderr, "LEX: char >>%c<<\n", c);
|
// fprintf(stderr, "LEX: char >>%c<<\n", c);
|
||||||
|
@ -202,8 +202,8 @@ LibertyAst *LibertyParser::parse()
|
||||||
{
|
{
|
||||||
tok = lexer(str);
|
tok = lexer(str);
|
||||||
|
|
||||||
// allow both ';' and new lines to
|
// allow both ';' and new lines to
|
||||||
// terminate a statement.
|
// terminate a statement.
|
||||||
if ((tok == ';') || (tok == 'n'))
|
if ((tok == ';') || (tok == 'n'))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -220,11 +220,11 @@ LibertyAst *LibertyParser::parse()
|
||||||
ast->value += str;
|
ast->value += str;
|
||||||
tok = lexer(str);
|
tok = lexer(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// In a liberty file, all key : value pairs should end in ';'
|
// In a liberty file, all key : value pairs should end in ';'
|
||||||
// However, there are some liberty files in the wild that
|
// However, there are some liberty files in the wild that
|
||||||
// just have a newline. We'll be kind and accept a newline
|
// just have a newline. We'll be kind and accept a newline
|
||||||
// instead of the ';' too..
|
// instead of the ';' too..
|
||||||
if ((tok == ';') || (tok == 'n'))
|
if ((tok == ';') || (tok == 'n'))
|
||||||
break;
|
break;
|
||||||
else
|
else
|
||||||
|
@ -240,48 +240,48 @@ LibertyAst *LibertyParser::parse()
|
||||||
continue;
|
continue;
|
||||||
if (tok == ')')
|
if (tok == ')')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// FIXME: the AST needs to be extended to store
|
// FIXME: the AST needs to be extended to store
|
||||||
// these vector ranges.
|
// these vector ranges.
|
||||||
if (tok == '[')
|
if (tok == '[')
|
||||||
{
|
{
|
||||||
// parse vector range [A] or [A:B]
|
// parse vector range [A] or [A:B]
|
||||||
std::string arg;
|
std::string arg;
|
||||||
tok = lexer(arg);
|
tok = lexer(arg);
|
||||||
if (tok != 'v')
|
if (tok != 'v')
|
||||||
{
|
{
|
||||||
// expected a vector array index
|
// expected a vector array index
|
||||||
error("Expected a number.");
|
error("Expected a number.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fixme: check for number A
|
// fixme: check for number A
|
||||||
}
|
}
|
||||||
tok = lexer(arg);
|
tok = lexer(arg);
|
||||||
// optionally check for : in case of [A:B]
|
// optionally check for : in case of [A:B]
|
||||||
// if it isn't we just expect ']'
|
// if it isn't we just expect ']'
|
||||||
// as we have [A]
|
// as we have [A]
|
||||||
if (tok == ':')
|
if (tok == ':')
|
||||||
{
|
{
|
||||||
tok = lexer(arg);
|
tok = lexer(arg);
|
||||||
if (tok != 'v')
|
if (tok != 'v')
|
||||||
{
|
{
|
||||||
// expected a vector array index
|
// expected a vector array index
|
||||||
error("Expected a number.");
|
error("Expected a number.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// fixme: check for number B
|
// fixme: check for number B
|
||||||
tok = lexer(arg);
|
tok = lexer(arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// expect a closing bracket of array range
|
// expect a closing bracket of array range
|
||||||
if (tok != ']')
|
if (tok != ']')
|
||||||
{
|
{
|
||||||
error("Expected ']' on array range.");
|
error("Expected ']' on array range.");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tok != 'v')
|
if (tok != 'v')
|
||||||
error();
|
error();
|
||||||
ast->args.push_back(arg);
|
ast->args.push_back(arg);
|
||||||
|
@ -314,10 +314,10 @@ void LibertyParser::error()
|
||||||
|
|
||||||
void LibertyParser::error(const std::string &str)
|
void LibertyParser::error(const std::string &str)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Syntax error in liberty file on line " << line << ".\n";
|
ss << "Syntax error in liberty file on line " << line << ".\n";
|
||||||
ss << " " << str << "\n";
|
ss << " " << str << "\n";
|
||||||
log_error("%s", ss.str().c_str());
|
log_error("%s", ss.str().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
@ -330,32 +330,32 @@ void LibertyParser::error()
|
||||||
|
|
||||||
void LibertyParser::error(const std::string &str)
|
void LibertyParser::error(const std::string &str)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "Syntax error in liberty file on line " << line << ".\n";
|
ss << "Syntax error in liberty file on line " << line << ".\n";
|
||||||
ss << " " << str << "\n";
|
ss << " " << str << "\n";
|
||||||
printf("%s", ss.str().c_str());
|
printf("%s", ss.str().c_str());
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**** BEGIN: http://svn.clifford.at/tools/trunk/examples/check.h ****/
|
/**** BEGIN: http://svn.clifford.at/tools/trunk/examples/check.h ****/
|
||||||
|
|
||||||
#define CHECK_NV(result, check) \
|
#define CHECK_NV(result, check) \
|
||||||
do { \
|
do { \
|
||||||
auto _R = (result); \
|
auto _R = (result); \
|
||||||
if (!(_R check)) { \
|
if (!(_R check)) { \
|
||||||
fprintf(stderr, "Error from '%s' (%ld %s) in %s:%d.\n", \
|
fprintf(stderr, "Error from '%s' (%ld %s) in %s:%d.\n", \
|
||||||
#result, (long int)_R, #check, __FILE__, __LINE__); \
|
#result, (long int)_R, #check, __FILE__, __LINE__); \
|
||||||
abort(); \
|
abort(); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
#define CHECK_COND(result) \
|
#define CHECK_COND(result) \
|
||||||
do { \
|
do { \
|
||||||
if (!(result)) { \
|
if (!(result)) { \
|
||||||
fprintf(stderr, "Error from '%s' in %s:%d.\n", \
|
fprintf(stderr, "Error from '%s' in %s:%d.\n", \
|
||||||
#result, __FILE__, __LINE__); \
|
#result, __FILE__, __LINE__); \
|
||||||
abort(); \
|
abort(); \
|
||||||
} \
|
} \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
/**** END: http://svn.clifford.at/tools/trunk/examples/check.h ****/
|
/**** END: http://svn.clifford.at/tools/trunk/examples/check.h ****/
|
||||||
|
|
Loading…
Reference in a new issue