Compile is similar to gnark's frontend.Compile. It compiles the given circuit and returns a pointer to CompileResult along with any error encountered during the compilation process.
(field *big.Int, circuit frontend.Circuit, opts ...frontend.CompileOption)
| 38 | // Compile is similar to gnark's frontend.Compile. It compiles the given circuit and returns |
| 39 | // a pointer to CompileResult along with any error encountered during the compilation process. |
| 40 | func Compile(field *big.Int, circuit frontend.Circuit, opts ...frontend.CompileOption) (*CompileResult, error) { |
| 41 | log := logger.Logger() |
| 42 | log.Info().Msg("compiling circuit") |
| 43 | |
| 44 | opt := frontend.CompileConfig{CompressThreshold: 0} |
| 45 | for _, o := range opts { |
| 46 | if err := o(&opt); err != nil { |
| 47 | log.Err(err).Msg("applying compile option") |
| 48 | return nil, fmt.Errorf("apply option: %w", err) |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | root := builder.NewRoot(field, opt) |
| 53 | schema.Walk(circuit, irwg.TVariable, func(f schema.LeafInfo, tInput reflect.Value) error { |
| 54 | if tInput.CanSet() { |
| 55 | if f.Visibility == schema.Unset { |
| 56 | return errors.New("can't set val " + f.FullName() + " visibility is unset") |
| 57 | } |
| 58 | if f.Visibility == schema.Secret { |
| 59 | tInput.Set(reflect.ValueOf(root.SecretVariable(f))) |
| 60 | } |
| 61 | return nil |
| 62 | } |
| 63 | return errors.New("can't set val " + f.FullName()) |
| 64 | }) |
| 65 | schema.Walk(circuit, irwg.TVariable, func(f schema.LeafInfo, tInput reflect.Value) error { |
| 66 | if tInput.CanSet() { |
| 67 | if f.Visibility == schema.Unset { |
| 68 | return errors.New("can't set val " + f.FullName() + " visibility is unset") |
| 69 | } |
| 70 | if f.Visibility == schema.Public { |
| 71 | tInput.Set(reflect.ValueOf(root.PublicVariable(f))) |
| 72 | } |
| 73 | return nil |
| 74 | } |
| 75 | return errors.New("can't set val " + f.FullName()) |
| 76 | }) |
| 77 | |
| 78 | err := circuit.Define(root) |
| 79 | if err != nil { |
| 80 | return nil, err |
| 81 | } |
| 82 | rc := root.Finalize() |
| 83 | _ = rc |
| 84 | //os.WriteFile("p1.txt", irsource.SerializeRootCircuit(rc), 0644) |
| 85 | irwg, lc, err := rust.Compile(rc) |
| 86 | if err != nil { |
| 87 | return nil, err |
| 88 | } |
| 89 | return &CompileResult{irs: rc, irwg: irwg, lc: lc}, nil |
| 90 | } |
| 91 | |
| 92 | // GetCircuitIr returns the intermediate representation (IR) of the compiled circuit as *ir.RootCircuit. |
| 93 | func (c *CompileResult) GetCircuitIr() *irsource.RootCircuit { |