-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
37 lines (32 loc) · 949 Bytes
/
index.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
'use strict'
const fs = require('fs');
const hasbin = require('hasbin')
const execSync = require('child_process').execSync;
if (!hasbin.sync('dot')) {
console.log('Please install graphviz dot.')
process.exit(0)
}
const input = process.argv[2]
if (!input) {
console.error('You forgot to pass file argument.')
process.exit(0)
}
const parser = require('./parser')
const mapTupleToString = t => `"${t[0]}" -> "${t[1]}"`
parser(input, tuples => {
const stream = fs.openSync('callgraph.dot', 'w');
const callsString = tuples.map(mapTupleToString).join(`\n`)
const data = `
digraph test{
overlap=scalexy;
${callsString}
}`
fs.writeSync(stream, data);
// const unshown = calls
// .filter(tuple => !filterTuple(tuple))
// .map(mapTupleToString)
// .join(`\n`)
// console.log('unshown calls', unshown)
execSync('dot -Tpng -o callgraph.png callgraph.dot')
console.log("Success! Check callgraph.png")
})