Added memhasher (yosys -M)
This commit is contained in:
parent
445686cba3
commit
8773fd5897
4 changed files with 56 additions and 2 deletions
|
@ -151,8 +151,11 @@ int main(int argc, char **argv)
|
|||
printf(" -m module_file\n");
|
||||
printf(" load the specified module (aka plugin)\n");
|
||||
printf("\n");
|
||||
printf(" -M\n");
|
||||
printf(" will slightly randomize allocated pointer addresses. for debugging\n");
|
||||
printf("\n");
|
||||
printf(" -A\n");
|
||||
printf(" will call abort() at the end of the script. useful for debugging\n");
|
||||
printf(" will call abort() at the end of the script. for debugging\n");
|
||||
printf("\n");
|
||||
printf(" -V\n");
|
||||
printf(" print version information and exit\n");
|
||||
|
@ -174,10 +177,13 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
int opt;
|
||||
while ((opt = getopt(argc, argv, "AQTVSm:f:Hh:b:o:p:l:qv:tds:c:")) != -1)
|
||||
while ((opt = getopt(argc, argv, "MAQTVSm:f:Hh:b:o:p:l:qv:tds:c:")) != -1)
|
||||
{
|
||||
switch (opt)
|
||||
{
|
||||
case 'M':
|
||||
memhasher_on();
|
||||
break;
|
||||
case 'A':
|
||||
call_abort = true;
|
||||
break;
|
||||
|
@ -407,6 +413,7 @@ int main(int argc, char **argv)
|
|||
}
|
||||
#endif
|
||||
|
||||
memhasher_off();
|
||||
if (call_abort)
|
||||
abort();
|
||||
|
||||
|
|
|
@ -1766,6 +1766,9 @@ RTLIL::Cell::Cell() : module(nullptr)
|
|||
{
|
||||
static unsigned int hashidx_count = 0;
|
||||
hashidx_ = hashidx_count++;
|
||||
|
||||
// log("#memtrace# %p\n", this);
|
||||
memhasher();
|
||||
}
|
||||
|
||||
bool RTLIL::Cell::hasPort(RTLIL::IdString portname) const
|
||||
|
|
|
@ -55,6 +55,43 @@ RTLIL::Design *yosys_design = NULL;
|
|||
Tcl_Interp *yosys_tcl_interp = NULL;
|
||||
#endif
|
||||
|
||||
bool memhasher_active = false;
|
||||
uint32_t memhasher_rng;
|
||||
std::vector<void*> memhasher_store;
|
||||
|
||||
void memhasher_on()
|
||||
{
|
||||
memhasher_rng += time(NULL) << 16 ^ getpid();
|
||||
memhasher_store.resize(0x10000);
|
||||
memhasher_active = true;
|
||||
}
|
||||
|
||||
void memhasher_off()
|
||||
{
|
||||
for (auto p : memhasher_store)
|
||||
if (p) free(p);
|
||||
memhasher_store.clear();
|
||||
memhasher_active = false;
|
||||
}
|
||||
|
||||
void memhasher_do()
|
||||
{
|
||||
memhasher_rng ^= memhasher_rng << 13;
|
||||
memhasher_rng ^= memhasher_rng >> 17;
|
||||
memhasher_rng ^= memhasher_rng << 5;
|
||||
|
||||
int size, index = (memhasher_rng >> 4) & 0xffff;
|
||||
switch (memhasher_rng & 7) {
|
||||
case 0: size = 16; break;
|
||||
case 1: size = 256; break;
|
||||
case 2: size = 1024; break;
|
||||
case 3: size = 4096; break;
|
||||
default: size = 0;
|
||||
}
|
||||
if (index < 16) size *= 16;
|
||||
memhasher_store[index] = realloc(memhasher_store[index], size);
|
||||
}
|
||||
|
||||
std::string stringf(const char *fmt, ...)
|
||||
{
|
||||
std::string string;
|
||||
|
|
|
@ -169,6 +169,13 @@ template<> struct hash_ops<const RTLIL::Module*> : hash_obj_ops {};
|
|||
template<> struct hash_ops<const RTLIL::Design*> : hash_obj_ops {};
|
||||
template<> struct hash_ops<const RTLIL::Monitor*> : hash_obj_ops {};
|
||||
|
||||
void memhasher_on();
|
||||
void memhasher_off();
|
||||
void memhasher_do();
|
||||
|
||||
extern bool memhasher_active;
|
||||
inline void memhasher() { if (memhasher_active) memhasher_do(); }
|
||||
|
||||
std::string stringf(const char *fmt, ...) YS_ATTRIBUTE(format(printf, 1, 2));
|
||||
std::string vstringf(const char *fmt, va_list ap);
|
||||
int readsome(std::istream &f, char *s, int n);
|
||||
|
|
Loading…
Add table
Reference in a new issue