circom/utils/mergesymbols.js
utils/mergesymbols.jsRaw
1const fs = require("fs");
2
3const argv = require("yargs")
4 .usage("mergesymbols -i [input_file] -o [output_file] -s [symbols file]")
5 .alias("i", "input")
6 .alias("o", "output")
7 .alias("s", "symbols")
8 .help("h")
9 .epilogue(`Copyright (C) 2018 0kims association
10 This program comes with ABSOLUTELY NO WARRANTY;
11 This is free software, and you are welcome to redistribute it
12 under certain conditions; see the COPYING file in the official
13 repo directory at https://github.com/iden3/circom `)
14 .demandOption(["i","o","s"])
15 .argv;
16
17const inFileName = argv.input;
18const outFile = argv.output;
19const symbolsFile = argv.symbols;
20
21let symbols;
22
23async function loadSymbols() {
24 symbols = {};
25 const symsStr = await fs.promises.readFile(symbolsFile,"utf8");
26 const lines = symsStr.split("\n");
27 for (let i=0; i<lines.length; i++) {
28 const arr = lines[i].split(",");
29 if (arr.length!=3) continue;
30 symbols[arr[0]] = arr[2];
31 }
32}
33
34
35async function run() {
36 const outLines = [];
37 await loadSymbols();
38 const inStr = await fs.promises.readFile(inFileName,"utf8");
39 const lines = inStr.split("\n");
40 for (let i=0; i<lines.length; i++) {
41 const arr = lines[i].split(" --> ");
42 if (arr.length!=2) continue;
43 outLines.push(symbols[arr[0]] + " --> " + arr[1]);
44 }
45 await fs.promises.writeFile(outFile,outLines.join("\n"), "utf8");
46}
47
48
49run().then(() => {
50 process.exit(0);
51});