Skip to content

Commit

Permalink
hash table for ids
Browse files Browse the repository at this point in the history
  • Loading branch information
drom committed Jan 6, 2025
1 parent 2ebcf2a commit a6acac4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
15 changes: 9 additions & 6 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ const objection = lut => arg => arg.split(/\s+/).reduce((res, key) => {
}, {});

const properties = {
command: 'i8',
type: 'i8',
definitions: 'ptr',
output: 'ptr',
id_sum: 'i32',
size: 'i32',
time: 'i64', // current simulation time
trigger: 'ptr',
triee: 'ptr', // trigger event emitter
lifee: 'ptr', // life cycle event emmiter
Expand All @@ -43,13 +43,16 @@ const properties = {
tmpStr2: 'ptr',
stackPointer: 'i32',
id: 'ptr',
napi_env: 'ptr'
napi_env: 'ptr',
time: 'i64', // current simulation time
command: 'i8',
type: 'i8'
};

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

const generate = (cb) => {
const generate = (/* cb */) => {
// const llparseDot = require('llparse-dot');

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

cb();
// cb();
};

generate(gyp);
Expand Down
29 changes: 28 additions & 1 deletion lib/command-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,42 @@ const handleUpScope = (info /* , str */) => {
// console.log(['upscope', str]);
};

const updateIdTable = ($, link) => {
if ($.ido[link] !== undefined) { // old Id
return;
}

// polynomial rolling hash function
let hash = 0;
let poly = 1;
for (let i = 0; i < link.length; i++) {
const c = link.charCodeAt(i) - 33 + 1; // ! .. ~ (94 digits)
hash = (hash + poly * c) & 0xfff;
poly = (poly * 97) & 0xfff; // 89, 97
}

$.ido[link] = [$.nextId, hash];

// add entry to the Hash Table object
if ($.hashTable[hash] === undefined) {
$.hashTable[hash] = {};
}

$.hashTable[hash][link] = $.nextId;
$.nextId += 1;
};

const handleVar = (info, str) => {
// reg 3 ( r_reg [2:0]
// 0 1 2 3+
const eroj = str.split(/\s+/);
const link = eroj[2];
updateIdTable(info, link);
const ero = {
kind: 'var',
type: eroj[0],
size: parseInt(eroj[1]),
link: eroj[2],
link,
name: eroj.slice(3).join('')
};
{
Expand Down

0 comments on commit a6acac4

Please sign in to comment.