mirror of
https://github.com/verilator/verilator.git
synced 2025-01-07 15:17:36 +00:00
Internals: Convert to use common string convert routine
This commit is contained in:
parent
09b7ba1317
commit
8c6adeb85a
@ -248,14 +248,24 @@ void _VL_VINT_TO_STRING(int obits, char* destoutp, WDataInP sourcep) {
|
||||
while (isspace(*(destp-1)) && destp>destoutp) *--destp = '\0'; // Drop trailing spaces
|
||||
}
|
||||
|
||||
IData VL_FGETS_IXQ(int sbits, void* strgp, QData fpq) {
|
||||
void _VL_STRING_TO_VINT(int obits, void* destp, int srclen, const char* srcp) {
|
||||
// Convert C string to Verilog format
|
||||
int bytes = VL_BYTES_I(obits);
|
||||
char* op = ((char*)(destp));
|
||||
if (srclen > bytes) srclen = bytes; // Don't overflow destination
|
||||
int i;
|
||||
for (i=0; i<srclen; i++) { *op++ = srcp[srclen-1-i]; }
|
||||
for (; i<bytes; i++) { *op++ = 0; }
|
||||
}
|
||||
|
||||
IData VL_FGETS_IXQ(int obits, void* destp, QData fpq) {
|
||||
FILE* fp = VL_CVT_Q_FP(fpq);
|
||||
if (!fp) return 0;
|
||||
|
||||
// The string needs to be padded with 0's in unused spaces in front of
|
||||
// any read data. This means we can't know in what location the first
|
||||
// character will finally live, so we need to copy. Yuk.
|
||||
IData bytes = VL_BYTES_I(sbits);
|
||||
IData bytes = VL_BYTES_I(obits);
|
||||
char buffer[bytes];
|
||||
|
||||
// We don't use fgets, as we must read \0s.
|
||||
@ -268,11 +278,7 @@ IData VL_FGETS_IXQ(int sbits, void* strgp, QData fpq) {
|
||||
if (c=='\n') break;
|
||||
}
|
||||
|
||||
// Convert to Verilog format
|
||||
char* op = ((char*)(strgp));
|
||||
IData i;
|
||||
for (i=0; i<got; i++) { *op++ = buffer[got-1-i]; }
|
||||
for (; i<bytes; i++) { *op++ = 0; }
|
||||
_VL_STRING_TO_VINT(obits, destp, got, buffer);
|
||||
return got;
|
||||
}
|
||||
|
||||
|
@ -200,21 +200,6 @@ inline const char* VL_VALUE_FORMATTED_I(int obits, char fmt, bool drop0, IData l
|
||||
|
||||
/// File I/O
|
||||
extern IData VL_FGETS_IXQ(int sbits, void* strgp, QData fpq);
|
||||
inline IData VL_FGETS_IIQ(int, int bits, int, CData& strg, QData fpq) {
|
||||
return VL_FGETS_IXQ(bits, &strg, fpq);
|
||||
}
|
||||
inline IData VL_FGETS_IIQ(int, int bits, int, SData& strg, QData fpq) {
|
||||
return VL_FGETS_IXQ(bits, &strg, fpq);
|
||||
}
|
||||
inline IData VL_FGETS_IIQ(int, int bits, int, IData& strg, QData fpq) {
|
||||
return VL_FGETS_IXQ(bits, &strg, fpq);
|
||||
}
|
||||
inline IData VL_FGETS_IQQ(int, int bits, int, QData& strg, QData fpq) {
|
||||
return VL_FGETS_IXQ(bits, &strg, fpq);
|
||||
}
|
||||
inline IData VL_FGETS_IWQ(int, int bits, int, WDataOutP strgp, QData fpq) {
|
||||
return VL_FGETS_IXQ(bits, strgp, fpq);
|
||||
}
|
||||
|
||||
extern QData VL_FOPEN_WI(int fnwords, WDataInP ofilename, IData mode);
|
||||
extern QData VL_FOPEN_QI(QData ofilename, IData mode);
|
||||
|
@ -2721,7 +2721,7 @@ struct AstFGetS : public AstNodeBiop {
|
||||
virtual void accept(AstNVisitor& v, AstNUser* vup=NULL) { v.visit(this,vup); }
|
||||
virtual void numberOperate(V3Number& out, const V3Number& lhs, const V3Number& rhs) { V3ERROR_NA; }
|
||||
virtual string emitVerilog() { return "%k$fgets(%l,%r)"; }
|
||||
virtual string emitC() { return "VL_FGETS_%nq%lq%rq(%nw,%lw,%rw, %P, %li, %ri)"; }
|
||||
virtual string emitC() { return "VL_FGETS_%nqX%rq(%lw, %P, &(%li), %ri)"; }
|
||||
virtual bool cleanOut() {return false;}
|
||||
virtual bool cleanLhs() {return true;} virtual bool cleanRhs() {return true;}
|
||||
virtual bool sizeMattersLhs() {return false;} virtual bool sizeMattersRhs() {return false;}
|
||||
|
Loading…
Reference in New Issue
Block a user