-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.js
52 lines (43 loc) · 1.33 KB
/
table.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs')
const path = require('path')
const jetpack = require('fs-jetpack')
const parse = require('./parse')
const query = require('./query')
const print = require('./print')
const process_ = require('./process')
class Table {
constructor(system, state) {
this.system = system
this.path_ = path.join(process.cwd(), 'build', 'table.json')
this.index = {}
this.counter = 4096
this.cached = state
}
find_function_id(module_, function_) {
let key = module_ + '/' + function_
if (this.index[key] === undefined) {
let document = process_.find_document(this.system, module_)
if (document) {
let func = process_.find_function(document, function_)
if (func) {
if (this.cached.index_table[key] === undefined) {
this.cached.index_table[key] = this.cached.id_table++
}
let id = this.index[key] = this.cached.index_table[key]
let tree = parse(`\n\t(elem (i32.const ${id}) ${function_})`)[0]
query.append(document.tree[0], tree)
}
}
}
return this.index[key]
}
find_function(module_, function_) { // find a new location for this function
let key = module_ + '/' + function_
let document = process_.find_document(this.system, module_)
if (document) {
let func = process_.find_function(document, function_)
return func
}
}
}
module.exports = Table