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");
}
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;
}
#endif
+ memhasher_off();
if (call_abort)
abort();
{
static unsigned int hashidx_count = 0;
hashidx_ = hashidx_count++;
+
+ // log("#memtrace# %p\n", this);
+ memhasher();
}
bool RTLIL::Cell::hasPort(RTLIL::IdString portname) const
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;
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);