Skip to content

Commit a6acac4

Browse files
committed
hash table for ids
1 parent 2ebcf2a commit a6acac4

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

bin/build.js

+9-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ const objection = lut => arg => arg.split(/\s+/).reduce((res, key) => {
2525
}, {});
2626

2727
const properties = {
28-
command: 'i8',
29-
type: 'i8',
28+
definitions: 'ptr',
29+
output: 'ptr',
30+
id_sum: 'i32',
3031
size: 'i32',
31-
time: 'i64', // current simulation time
3232
trigger: 'ptr',
3333
triee: 'ptr', // trigger event emitter
3434
lifee: 'ptr', // life cycle event emmiter
@@ -43,13 +43,16 @@ const properties = {
4343
tmpStr2: 'ptr',
4444
stackPointer: 'i32',
4545
id: 'ptr',
46-
napi_env: 'ptr'
46+
napi_env: 'ptr',
47+
time: 'i64', // current simulation time
48+
command: 'i8',
49+
type: 'i8'
4750
};
4851

4952
const spaces = [' ', '\n', '\r', '\t'];
5053
const lineSpaces = [' ', '\t'];
5154

52-
const generate = (cb) => {
55+
const generate = (/* cb */) => {
5356
// const llparseDot = require('llparse-dot');
5457

5558
const prj = 'vcd_parser';
@@ -303,7 +306,7 @@ const generate = (cb) => {
303306
// const dot = new llparseDot.Dot();
304307
// fs.writeFileSync(prj + '.dot', dot.build(declaration));
305308

306-
cb();
309+
// cb();
307310
};
308311

309312
generate(gyp);

lib/command-handler.js

+28-1
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,42 @@ const handleUpScope = (info /* , str */) => {
1414
// console.log(['upscope', str]);
1515
};
1616

17+
const updateIdTable = ($, link) => {
18+
if ($.ido[link] !== undefined) { // old Id
19+
return;
20+
}
21+
22+
// polynomial rolling hash function
23+
let hash = 0;
24+
let poly = 1;
25+
for (let i = 0; i < link.length; i++) {
26+
const c = link.charCodeAt(i) - 33 + 1; // ! .. ~ (94 digits)
27+
hash = (hash + poly * c) & 0xfff;
28+
poly = (poly * 97) & 0xfff; // 89, 97
29+
}
30+
31+
$.ido[link] = [$.nextId, hash];
32+
33+
// add entry to the Hash Table object
34+
if ($.hashTable[hash] === undefined) {
35+
$.hashTable[hash] = {};
36+
}
37+
38+
$.hashTable[hash][link] = $.nextId;
39+
$.nextId += 1;
40+
};
41+
1742
const handleVar = (info, str) => {
1843
// reg 3 ( r_reg [2:0]
1944
// 0 1 2 3+
2045
const eroj = str.split(/\s+/);
46+
const link = eroj[2];
47+
updateIdTable(info, link);
2148
const ero = {
2249
kind: 'var',
2350
type: eroj[0],
2451
size: parseInt(eroj[1]),
25-
link: eroj[2],
52+
link,
2653
name: eroj.slice(3).join('')
2754
};
2855
{

0 commit comments

Comments
 (0)