Internals: Real1: properly lex doubles
This commit is contained in:
parent
a007458cb8
commit
59c3c536c7
|
|
@ -1624,7 +1624,7 @@ public:
|
|||
void ignoreOverlap(bool flag) { m_ignoreOverlap = flag; }
|
||||
};
|
||||
|
||||
class AstSFormatF : public AstNode {
|
||||
struct AstSFormatF : public AstNode {
|
||||
// Convert format to string, generally under a AstDisplay or AstSFormat
|
||||
// Also used as "real" function for /*verilator sformat*/ functions
|
||||
string m_text;
|
||||
|
|
|
|||
|
|
@ -306,12 +306,12 @@ V3Number& V3Number::setSingleBits(char value) {
|
|||
}
|
||||
|
||||
V3Number& V3Number::setAllBits0() {
|
||||
for (int i=0; i<words(); i++) { m_value[i] = m_valueX[i]=0; }
|
||||
return *this;
|
||||
for (int i=0; i<words(); i++) { m_value[i] = m_valueX[i]=0; }
|
||||
return *this;
|
||||
}
|
||||
V3Number& V3Number::setAllBits1() {
|
||||
for (int i=0; i<words(); i++) { m_value[i]= ~0; m_valueX[i] = 0; }
|
||||
return *this;
|
||||
for (int i=0; i<words(); i++) { m_value[i]= ~0; m_valueX[i] = 0; }
|
||||
return *this;
|
||||
}
|
||||
V3Number& V3Number::setAllBitsX() {
|
||||
for (int i=0; i<words(); i++) { m_value[i]=m_valueX[i] = ~0; }
|
||||
|
|
|
|||
|
|
@ -254,6 +254,7 @@ public:
|
|||
void verilatorCmtLintSave();
|
||||
void verilatorCmtLintRestore();
|
||||
void verilatorCmtBad(const char* text);
|
||||
double parseDouble(const char* text, size_t length);
|
||||
void pushBeginKeywords(int state) { m_inBeginKwd++; m_lastVerilogState=state; }
|
||||
bool popBeginKeywords() { if (m_inBeginKwd) { m_inBeginKwd--; return true; } else return false; }
|
||||
int lastVerilogState() { return m_lastVerilogState; }
|
||||
|
|
|
|||
|
|
@ -812,11 +812,11 @@ word [a-zA-Z0-9_]+
|
|||
return yaINTNUM;
|
||||
}
|
||||
[0-9][_0-9]*(\.[_0-9]+)([eE][-+]?[_0-9]+)? {
|
||||
FL; yylval.cdouble = 0; /* Only for delays, not used yet */
|
||||
FL; yylval.cdouble = PARSEP->parseDouble(yytext, yyleng);
|
||||
return yaFLOATNUM;
|
||||
}
|
||||
[0-9][_0-9]*(\.[_0-9]+)?([eE][-+]?[_0-9]+) {
|
||||
FL; yylval.cdouble = 0; /* Only for delays, not used yet */
|
||||
FL; yylval.cdouble = PARSEP->parseDouble(yytext, yyleng);
|
||||
return yaFLOATNUM;
|
||||
}
|
||||
[0-9][_0-9]*(\.[_0-9]+)?(fs|ps|ns|us|ms|s|step) {
|
||||
|
|
@ -949,6 +949,20 @@ word [a-zA-Z0-9_]+
|
|||
%%
|
||||
int V3ParseImp::stateVerilogRecent() { return STATE_VERILOG_RECENT; }
|
||||
|
||||
double V3ParseImp::parseDouble(const char* textp, size_t length) {
|
||||
char* strgp = new char[strlen(textp)+1];
|
||||
char* dp=strgp;
|
||||
for (const char* sp=textp; sp<(textp+length);) {
|
||||
if (*sp != '_') *dp++ = *sp++;
|
||||
else sp++;
|
||||
}
|
||||
char* endp = strgp;
|
||||
double d = strtod(strgp, &endp);
|
||||
if ((endp-strgp) != length) { yyerrorf("Syntax error parsing real: %s",strgp); }
|
||||
delete strgp;
|
||||
return d;
|
||||
}
|
||||
|
||||
int V3ParseImp::lexToken() {
|
||||
// called from lexToBison, has a "this"
|
||||
// Fetch next token from prefetch or real lexer
|
||||
|
|
|
|||
Loading…
Reference in New Issue