Skip to content

Commit abc969e

Browse files
committed
Quicker export of sighashes
1 parent c6e0872 commit abc969e

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

compiler/sighashes.nim

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
## Computes hash values for routine (proc, method etc) signatures.
1111

12-
import ast, md5
12+
import ast, md5, tables
1313
from hashes import Hash
1414
from astalgo import debug
1515
from types import typeToString, preferDesc
@@ -255,6 +255,11 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
255255
for i in 0..<t.len: c.hashType(t.sons[i], flags)
256256
if tfNotNil in t.flags and CoType notin flags: c &= "not nil"
257257

258+
259+
when defined(debugSigHashesText):
260+
import tables
261+
var savedSigHashes = initTable[string, string]()
262+
258263
when defined(debugSigHashes):
259264
import db_sqlite
260265

@@ -274,10 +279,39 @@ proc hashType*(t: PType; flags: set[ConsiderFlag] = {CoType}): SigHash =
274279
md5Init c
275280
hashType c, t, flags+{CoOwnerSig}
276281
md5Final c, result.Md5Digest
282+
when defined(debugSigHashesText):
283+
let r = $result
284+
if not savedSigHashes.hasKey(r):
285+
savedSigHashes[r] = typeToString(t)
286+
277287
when defined(debugSigHashes):
278288
db.exec(sql"INSERT OR IGNORE INTO sighashes(type, hash) VALUES (?, ?)",
279289
typeToString(t), $result)
280290

291+
292+
when defined(debugSigHashesText):
293+
import db_sqlite, osproc
294+
295+
proc saveSigHashes {.noconv.} =
296+
var s = ""
297+
for key, value in savedSigHashes:
298+
s.add(key & "\t" & value & "\n")
299+
writeFile("sighashes.csv", s)
300+
301+
302+
let db = open(connection="sighashes.db", user="araq", password="",
303+
database="sighashes")
304+
db.exec(sql"DROP TABLE IF EXISTS sighashes")
305+
db.exec sql"""CREATE TABLE sighashes(
306+
hash varchar(5000) not null,
307+
type varchar(5000) not null,
308+
unique (hash, type))"""
309+
310+
db.exec(sql"CREATE INDEX sighashes_hash ON sighashes (hash)")
311+
312+
discard execProcess("/bin/bash -c \"echo -e \\\".separator '\t' \n.import sighashes.csv sighashes\\\" | sqlite3 sighashes.db\"")
313+
addQuitProc(saveSigHashes)
314+
281315
proc hashProc*(s: PSym): SigHash =
282316
var c: MD5Context
283317
md5Init c

0 commit comments

Comments
 (0)