arnaucube
arnaucube/circomPublic Self-hosted repository
Verbose and error if main is not defined
Jordi Baylina jordi@baylina.cat
Wed, 24 Oct 2018 20:27:34 +0200
commit

5e58584a014912635d5f22006c6579e63cf20d3f

parent

cb9a5b536e587f3a94ba78c65070a2fef6ac9de5

2 files changed, 23 insertions(+), 7 deletions(-)

jump to
M cli.js → cli.js

@@ -34,6 +34,7 @@ .usage("circom [input source circuit file] -o [output definition circuit file]")

.alias("o", "output") .help("h") .alias("h", "help") + .alias("v", "verbose") .epilogue(`Copyright (C) 2018 0kims association This program comes with ABSOLUTELY NO WARRANTY; This is free software, and you are welcome to redistribute it

@@ -41,24 +42,34 @@ under certain conditions; see the COPYING file in the official

repo directory at https://github.com/iden3/circom `) .argv; + +let inputFile; if (argv._.length == 0) { - console.log("File to compile not specified"); - process.exit(1); -} else if (argv._.length > 1) { + inputFile = "circuit.circom"; +} else if (argv._.length == 1) { + inputFile = argv._[0]; +} else { console.log("Only one circuit at a time is permited"); process.exit(1); } -const fullFileName = path.resolve(process.cwd(), argv._[0]); +const fullFileName = path.resolve(process.cwd(), inputFile); const outName = argv.output ? argv.output : "circuit.json"; compiler(fullFileName).then( (cir) => { fs.writeFileSync(outName, JSON.stringify(cir, null, 1), "utf8"); process.exit(0); }, (err) => { - console.log(err); - console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`); - console.error(JSON.stringify(err.ast, null, 1)); +// console.log(err); + if (err.pos) { + console.error(`ERROR at ${err.errFile}:${err.pos.first_line},${err.pos.first_column}-${err.pos.last_line},${err.pos.last_column} ${err.errStr}`); + } else { + console.log(err.message); + if (argv.verbose) console.log(err.stack); + } + if (err.ast) { + console.error(JSON.stringify(err.ast, null, 1)); + } process.exit(1); });
M src/compiler.js → src/compiler.js

@@ -62,7 +62,12 @@ filePath: fullFilePath,

fileName: fullFileName }; + exec(ctx, ast); + + if (!ctx.components["main"]) { + throw new Error("A main component must be defined"); + } classifySignals(ctx); reduceConstants(ctx);