BigArray in code

This commit is contained in:
Jordi Baylina
2020-07-30 05:04:15 +02:00
parent 0e1a1bcc23
commit 1e2fb12631
4 changed files with 15 additions and 9 deletions

View File

@@ -484,6 +484,7 @@ class BuilderC {
code.push("// Constants");
code.push(`FrElement _constants[${self.constants.length}] = {`);
for (let i=0; i<self.constants.length; i++) {
if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildConstants ${i}/${this.constants.length}`);
code.push((i>0 ? "," : " ") + "{" + number2Code(self.constants[i]) + "}");
}
code.push("};");
@@ -561,6 +562,7 @@ class BuilderC {
code.push("// Components");
code.push(`Circom_Component _components[${this.components.length}] = {`);
for (let i=0; i<this.components.length; i++) {
if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildComponents ${i}/${this.components.length}`);
const c = this.components[i];
const sep = i>0 ? " ," : " ";
code.push(`${sep}{${c.hashMapName}, ${c.entryTableName}, ${c.functionName}, ${c.nInSignals}, ${c.newThread}}`);
@@ -573,6 +575,7 @@ class BuilderC {
code.push(`u32 _mapIsInput[${this.mapIsInput.length}] = {`);
let line = "";
for (let i=0; i<this.mapIsInput.length; i++) {
if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildMapIsInput ${i}/${this.mapIsInput.length}`);
line += i>0 ? ", " : " ";
line += toHex(this.mapIsInput[i]);
if (((i+1) % 64)==0) {
@@ -596,6 +599,7 @@ class BuilderC {
code.push(`int _wit2sig[${this.wit2sig.length}] = {`);
let line = "";
for (let i=0; i<this.wit2sig.length; i++) {
if ((this.verbose)&&(i%1000000 ==0)) console.log(`_buildWit2Sig ${i}/${this.wit2sig.length}`);
line += i>0 ? "," : " ";
line += this.wit2sig[i];
if (((i+1) % 64) == 0) {
@@ -628,7 +632,7 @@ class BuilderC {
build() {
const code=[];
const code=new BigArray();
this._buildHeader(code);
this._buildSizes(code);
this._buildConstants(code);

View File

@@ -26,8 +26,10 @@ class _BigArray {
}
return this;
}
push (element) {
this.setElement (this.length, element);
push () {
for (let i=0; i<arguments.length; i++) {
this.setElement (this.length, arguments[i]);
}
}
getElement(idx) {
idx = parseInt(idx);

View File

@@ -116,7 +116,7 @@ function buildCode(ctx) {
const fnComponents = [];
for (let i=0; i<ctx.components.length; i++) {
if (ctx.verbose && (i%1000 ==0)) console.log(`buildCode component: ${i}/${ctx.components.length}`);
if (ctx.verbose && (i%100000 ==0)) console.log(`buildCode component: ${i}/${ctx.components.length}`);
const {h, instanceDef} = hashComponentCall(ctx, i);
const fName = ctx.components[i].template+"_"+h;
if (!fDefined[fName]) {
@@ -166,7 +166,7 @@ function buildCode(ctx) {
function buildComponentsArray(ctx) {
for (let i=0; i< ctx.components.length; i++) {
if (ctx.verbose && (i%10000 ==0)) console.log(`buildComponentsArray component: ${i}/${ctx.components.length}`);
if (ctx.verbose && (i%1000000 ==0)) console.log(`buildComponentsArray component: ${i}/${ctx.components.length}`);
let newThread;
if (ctx.newThreadTemplates) {
if (ctx.newThreadTemplates.test(ctx.components[i].template)) {
@@ -204,7 +204,7 @@ function buildMapIsInput(ctx) {
let map = [];
let acc = 0;
for (i=0; i<ctx.signals.length; i++) {
if (ctx.verbose && (i%100000 ==0)) console.log(`buildMapIsInput signal: ${i}/${ctx.signals.length}`);
if (ctx.verbose && (i%1000000 ==0)) console.log(`buildMapIsInput signal: ${i}/${ctx.signals.length}`);
if (ctx.signals[i].o & ctx.IN) {
acc = acc | (1 << (i%32) );
}
@@ -231,7 +231,7 @@ function buildWit2Sig(ctx) {
ctx.totals[ctx.stINTERNAL];
const arr = Array(NVars);
for (let i=0; i<ctx.signals.length; i++) {
if (ctx.verbose && (i%100000 ==0)) console.log(`buildWit2Sig signal: ${i}/${ctx.signals.length}`);
if (ctx.verbose && (i%1000000 ==0)) console.log(`buildWit2Sig signal: ${i}/${ctx.signals.length}`);
const outIdx = ctx.signals[i].id;
if (ctx.signals[i].e>=0) continue; // If has an alias, continue..
assert(typeof outIdx != "undefined", `Signal ${i} does not have index`);

View File

@@ -1,4 +1,4 @@
const BigArray = require("./bigArray");
const Readable = require("stream").Readable;
module.exports = function streamFromArrayTxt(ma) {
@@ -22,7 +22,7 @@ module.exports = function streamFromArrayTxt(ma) {
function getFirstIdx(ma) {
if (!Array.isArray(ma)) return [];
if (typeof ma.push !== "function" ) return [];
return [0, ...getFirstIdx(ma[0])];
}