mirror of
https://github.com/arnaucube/circom.git
synced 2026-02-07 03:06:42 +01:00
BigArray in code
This commit is contained in:
@@ -484,6 +484,7 @@ class BuilderC {
|
|||||||
code.push("// Constants");
|
code.push("// Constants");
|
||||||
code.push(`FrElement _constants[${self.constants.length}] = {`);
|
code.push(`FrElement _constants[${self.constants.length}] = {`);
|
||||||
for (let i=0; i<self.constants.length; i++) {
|
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((i>0 ? "," : " ") + "{" + number2Code(self.constants[i]) + "}");
|
||||||
}
|
}
|
||||||
code.push("};");
|
code.push("};");
|
||||||
@@ -561,6 +562,7 @@ class BuilderC {
|
|||||||
code.push("// Components");
|
code.push("// Components");
|
||||||
code.push(`Circom_Component _components[${this.components.length}] = {`);
|
code.push(`Circom_Component _components[${this.components.length}] = {`);
|
||||||
for (let i=0; i<this.components.length; i++) {
|
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 c = this.components[i];
|
||||||
const sep = i>0 ? " ," : " ";
|
const sep = i>0 ? " ," : " ";
|
||||||
code.push(`${sep}{${c.hashMapName}, ${c.entryTableName}, ${c.functionName}, ${c.nInSignals}, ${c.newThread}}`);
|
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}] = {`);
|
code.push(`u32 _mapIsInput[${this.mapIsInput.length}] = {`);
|
||||||
let line = "";
|
let line = "";
|
||||||
for (let i=0; i<this.mapIsInput.length; i++) {
|
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 += i>0 ? ", " : " ";
|
||||||
line += toHex(this.mapIsInput[i]);
|
line += toHex(this.mapIsInput[i]);
|
||||||
if (((i+1) % 64)==0) {
|
if (((i+1) % 64)==0) {
|
||||||
@@ -596,6 +599,7 @@ class BuilderC {
|
|||||||
code.push(`int _wit2sig[${this.wit2sig.length}] = {`);
|
code.push(`int _wit2sig[${this.wit2sig.length}] = {`);
|
||||||
let line = "";
|
let line = "";
|
||||||
for (let i=0; i<this.wit2sig.length; i++) {
|
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 += i>0 ? "," : " ";
|
||||||
line += this.wit2sig[i];
|
line += this.wit2sig[i];
|
||||||
if (((i+1) % 64) == 0) {
|
if (((i+1) % 64) == 0) {
|
||||||
@@ -628,7 +632,7 @@ class BuilderC {
|
|||||||
|
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
const code=[];
|
const code=new BigArray();
|
||||||
this._buildHeader(code);
|
this._buildHeader(code);
|
||||||
this._buildSizes(code);
|
this._buildSizes(code);
|
||||||
this._buildConstants(code);
|
this._buildConstants(code);
|
||||||
|
|||||||
@@ -26,8 +26,10 @@ class _BigArray {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
push (element) {
|
push () {
|
||||||
this.setElement (this.length, element);
|
for (let i=0; i<arguments.length; i++) {
|
||||||
|
this.setElement (this.length, arguments[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
getElement(idx) {
|
getElement(idx) {
|
||||||
idx = parseInt(idx);
|
idx = parseInt(idx);
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ function buildCode(ctx) {
|
|||||||
|
|
||||||
const fnComponents = [];
|
const fnComponents = [];
|
||||||
for (let i=0; i<ctx.components.length; i++) {
|
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 {h, instanceDef} = hashComponentCall(ctx, i);
|
||||||
const fName = ctx.components[i].template+"_"+h;
|
const fName = ctx.components[i].template+"_"+h;
|
||||||
if (!fDefined[fName]) {
|
if (!fDefined[fName]) {
|
||||||
@@ -166,7 +166,7 @@ function buildCode(ctx) {
|
|||||||
|
|
||||||
function buildComponentsArray(ctx) {
|
function buildComponentsArray(ctx) {
|
||||||
for (let i=0; i< ctx.components.length; i++) {
|
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;
|
let newThread;
|
||||||
if (ctx.newThreadTemplates) {
|
if (ctx.newThreadTemplates) {
|
||||||
if (ctx.newThreadTemplates.test(ctx.components[i].template)) {
|
if (ctx.newThreadTemplates.test(ctx.components[i].template)) {
|
||||||
@@ -204,7 +204,7 @@ function buildMapIsInput(ctx) {
|
|||||||
let map = [];
|
let map = [];
|
||||||
let acc = 0;
|
let acc = 0;
|
||||||
for (i=0; i<ctx.signals.length; i++) {
|
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) {
|
if (ctx.signals[i].o & ctx.IN) {
|
||||||
acc = acc | (1 << (i%32) );
|
acc = acc | (1 << (i%32) );
|
||||||
}
|
}
|
||||||
@@ -231,7 +231,7 @@ function buildWit2Sig(ctx) {
|
|||||||
ctx.totals[ctx.stINTERNAL];
|
ctx.totals[ctx.stINTERNAL];
|
||||||
const arr = Array(NVars);
|
const arr = Array(NVars);
|
||||||
for (let i=0; i<ctx.signals.length; i++) {
|
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;
|
const outIdx = ctx.signals[i].id;
|
||||||
if (ctx.signals[i].e>=0) continue; // If has an alias, continue..
|
if (ctx.signals[i].e>=0) continue; // If has an alias, continue..
|
||||||
assert(typeof outIdx != "undefined", `Signal ${i} does not have index`);
|
assert(typeof outIdx != "undefined", `Signal ${i} does not have index`);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
const BigArray = require("./bigArray");
|
||||||
const Readable = require("stream").Readable;
|
const Readable = require("stream").Readable;
|
||||||
|
|
||||||
module.exports = function streamFromArrayTxt(ma) {
|
module.exports = function streamFromArrayTxt(ma) {
|
||||||
@@ -22,7 +22,7 @@ module.exports = function streamFromArrayTxt(ma) {
|
|||||||
|
|
||||||
|
|
||||||
function getFirstIdx(ma) {
|
function getFirstIdx(ma) {
|
||||||
if (!Array.isArray(ma)) return [];
|
if (typeof ma.push !== "function" ) return [];
|
||||||
return [0, ...getFirstIdx(ma[0])];
|
return [0, ...getFirstIdx(ma[0])];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user