-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.js
34 lines (31 loc) · 1.04 KB
/
main.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
const hoist=require('./src/hoist.js');
const useAnalysis=require('./src/useAnalysis.js');
const funcDeclSort=require('./src/funcDeclSort.js');
const identifierAnalysis=require('./src/identifierAnalysis.js');
const compile=require('./src/compile.js');
const fs=require('fs');
const acorn=require('acorn');
const jspb=require('google-protobuf');
if (process.argv.length!=4) {
console.log('Usage: node main.js input.js output.fuzzil.protofbuf');
process.exit(139);
}
const jsPath=process.argv[2];
const outPath=process.argv[3];
const js=fs.readFileSync(jsPath);
let ast;
try {
ast=acorn.parse(js, {ecmaVersion: 2022});
} catch {
console.log('Acorn parse error');
process.exit(139);
}
hoist.hoist(ast);
useAnalysis.useAnalysis(ast);
funcDeclSort.funcDeclSort(ast);
identifierAnalysis.identifierAnalysis(ast);
const fuzzilProgram = compile.compile(ast);
const bwriter = new jspb.BinaryWriter();
proto.fuzzilli.protobuf.Program.serializeBinaryToWriter(fuzzilProgram, bwriter);
const buff=bwriter.getResultBuffer();
fs.writeFileSync(outPath, Buffer.from(buff));