diff --git a/zirgen/Dialect/Zll/IR/Codegen.h b/zirgen/Dialect/Zll/IR/Codegen.h index a168c6e6..ab6401cd 100644 --- a/zirgen/Dialect/Zll/IR/Codegen.h +++ b/zirgen/Dialect/Zll/IR/Codegen.h @@ -115,7 +115,6 @@ struct LanguageSyntax { virtual void emitClone(CodegenEmitter& cg, CodegenIdent value); virtual void emitTakeReference(CodegenEmitter& cg, EmitPart emitTarget); - virtual void fallbackEmitLiteral(CodegenEmitter& cg, mlir::Type ty, mlir::Attribute value) = 0; virtual void emitFuncDefinition(CodegenEmitter& cg, CodegenIdent funcName, llvm::ArrayRef> argNames, diff --git a/zirgen/Dialect/Zll/IR/CodegenEmitter.cpp b/zirgen/Dialect/Zll/IR/CodegenEmitter.cpp index 450389bd..d0df6a89 100644 --- a/zirgen/Dialect/Zll/IR/CodegenEmitter.cpp +++ b/zirgen/Dialect/Zll/IR/CodegenEmitter.cpp @@ -367,7 +367,9 @@ void CodegenEmitter::emitLiteral(mlir::Type ty, mlir::Attribute value) { if (succeeded(codegenType.emitLiteral(*this, value))) return; } - opts.lang->fallbackEmitLiteral(*this, ty, value); + llvm::errs() << "Don't know how to emit type " << ty << " with value " << value + << " (name = " << value.getAbstractAttribute().getName() << ")\n"; + abort(); } void CodegenEmitter::emitConstDef(CodegenIdent name, CodegenValue value) { diff --git a/zirgen/Dialect/Zll/IR/Types.cpp b/zirgen/Dialect/Zll/IR/Types.cpp index 870e7eef..9b878620 100644 --- a/zirgen/Dialect/Zll/IR/Types.cpp +++ b/zirgen/Dialect/Zll/IR/Types.cpp @@ -30,22 +30,6 @@ ValType::getTypeName(codegen::CodegenEmitter& cg) const { } } -mlir::LogicalResult ValType::emitLiteral(zirgen::codegen::CodegenEmitter& cg, - mlir::Attribute attr) const { - // Only emit a literal if it's a field element. - auto arrayAttr = llvm::dyn_cast(attr); - if (!arrayAttr) - return failure(); - - llvm::SmallVector macroParts; - llvm::append_range(macroParts, arrayAttr.asArrayRef()); - if (macroParts.size() == 1) - cg.emitInvokeMacro(cg.getStringAttr("makeVal"), macroParts); - else - cg.emitInvokeMacro(cg.getStringAttr("makeValExt"), macroParts); - return success(); -} - ExtensionField ValType::getExtensionField() const { if (getExtended()) return getField().getExtExtensionField(); diff --git a/zirgen/Dialect/Zll/IR/Types.td b/zirgen/Dialect/Zll/IR/Types.td index 687a9bc8..81fd4529 100644 --- a/zirgen/Dialect/Zll/IR/Types.td +++ b/zirgen/Dialect/Zll/IR/Types.td @@ -26,7 +26,7 @@ class ZllType traits = []> let mnemonic = typeMnemonic; } -def Val : ZllType<"Val", "val", [DeclareTypeInterfaceMethods]> { +def Val : ZllType<"Val", "val", [DeclareTypeInterfaceMethods]> { let summary = "An expression which results in a single field element"; let parameters = (ins "::zirgen::Zll::FieldAttr": $field, diff --git a/zirgen/Dialect/Zll/IR/test/emit-codegen.mlir b/zirgen/Dialect/Zll/IR/test/emit-codegen.mlir index 153c3f0e..87e9126c 100644 --- a/zirgen/Dialect/Zll/IR/test/emit-codegen.mlir +++ b/zirgen/Dialect/Zll/IR/test/emit-codegen.mlir @@ -7,15 +7,15 @@ func.func @add_with_0(%arg : !zll.val) -> !zll.val { %0 = zll.const 0 %1 = zll.add %0:, %arg: %2 = zll.isz %1: - // CPP-CHECK: Val {{.*}} = isz((MAKE_VAL(0) + arg0)) - // RUST-CHECK: let x1 : Val = isz((make_val!(0) + arg0)) + // CPP-CHECK: Val {{.*}} = isz((Val(0) + arg0)) + // RUST-CHECK: let x1 : Val = isz((Val::new(0) + arg0)) zll.if %2 : { // CPP-CHECK: if (to_size_t(x1)) { // RUST-CHECK: if is_nonzero(x1) { %three = zll.const 3 zll.eqz %three : - // CPP-CHECK: EQZ(MAKE_VAL(3), "Dialect/Zll/IR/test/emit-codegen.mlir:16") - // RUST-CHECK: eqz!(make_val!(3), "Dialect/Zll/IR/test/emit-codegen.mlir:16") + // CPP-CHECK: EQZ(Val(3), "Dialect/Zll/IR/test/emit-codegen.mlir:16") + // RUST-CHECK: eqz!(Val::new(3), "Dialect/Zll/IR/test/emit-codegen.mlir:16") } // CHECK: } return %2: !zll.val diff --git a/zirgen/Main/gen_zirgen.cpp b/zirgen/Main/gen_zirgen.cpp index 4ff765f2..66e43896 100644 --- a/zirgen/Main/gen_zirgen.cpp +++ b/zirgen/Main/gen_zirgen.cpp @@ -75,10 +75,7 @@ std::unique_ptr openOutput(StringRef filename) { return ofs; } -void emitDefs(ModuleOp mod, codegen::LanguageSyntax* lang, StringRef filename) { - codegen::CodegenOptions opts; - opts.lang = lang; - +void emitDefs(ModuleOp mod, const codegen::CodegenOptions& opts, StringRef filename) { auto os = openOutput(filename); zirgen::codegen::CodegenEmitter emitter(opts, os.get(), mod.getContext()); auto emitZhlt = Zhlt::getEmitter(mod, emitter); @@ -88,20 +85,14 @@ void emitDefs(ModuleOp mod, codegen::LanguageSyntax* lang, StringRef filename) { } } -void emitTypes(ModuleOp mod, codegen::LanguageSyntax* lang, StringRef filename) { - codegen::CodegenOptions opts; - opts.lang = lang; - +void emitTypes(ModuleOp mod, const codegen::CodegenOptions& opts, StringRef filename) { auto os = openOutput(filename); zirgen::codegen::CodegenEmitter emitter(opts, os.get(), mod.getContext()); emitter.emitTypeDefs(mod); } template -void emitOps(ModuleOp mod, codegen::LanguageSyntax* lang, StringRef filename) { - codegen::CodegenOptions opts; - opts.lang = lang; - +void emitOps(ModuleOp mod, const codegen::CodegenOptions& opts, StringRef filename) { auto os = openOutput(filename); zirgen::codegen::CodegenEmitter emitter(opts, os.get(), mod.getContext()); @@ -194,22 +185,21 @@ int main(int argc, char* argv[]) { return 1; } - static codegen::RustLanguageSyntax kRust; - static codegen::CppLanguageSyntax kCpp; - - emitDefs(*typedModule, &kRust, "defs.rs.inc"); - emitTypes(*typedModule, &kRust, "types.rs.inc"); - emitOps(*typedModule, &kRust, "validity_regs.rs.inc"); - emitOps(*typedModule, &kRust, "validity_taps.rs.inc"); - emitOps(*typedModule, &kRust, "layout.rs.inc"); - emitOps(*typedModule, &kRust, "steps.rs.inc"); - - emitDefs(*typedModule, &kCpp, "defs.cpp.inc"); - emitTypes(*typedModule, &kCpp, "types.h.inc"); - emitOps(*typedModule, &kCpp, "validity_regs.cpp.inc"); - emitOps(*typedModule, &kCpp, "validity_taps.cpp.inc"); - emitOps(*typedModule, &kCpp, "layout.cpp.inc"); - emitOps(*typedModule, &kCpp, "steps.cpp.inc"); + auto rustOpts = codegen::getRustCodegenOpts(); + emitDefs(*typedModule, rustOpts, "defs.rs.inc"); + emitTypes(*typedModule, rustOpts, "types.rs.inc"); + emitOps(*typedModule, rustOpts, "validity_regs.rs.inc"); + emitOps(*typedModule, rustOpts, "validity_taps.rs.inc"); + emitOps(*typedModule, rustOpts, "layout.rs.inc"); + emitOps(*typedModule, rustOpts, "steps.rs.inc"); + + auto cppOpts = codegen::getCppCodegenOpts(); + emitDefs(*typedModule, cppOpts, "defs.cpp.inc"); + emitTypes(*typedModule, cppOpts, "types.h.inc"); + emitOps(*typedModule, cppOpts, "validity_regs.cpp.inc"); + emitOps(*typedModule, cppOpts, "validity_taps.cpp.inc"); + emitOps(*typedModule, cppOpts, "layout.cpp.inc"); + emitOps(*typedModule, cppOpts, "steps.cpp.inc"); typedModule->print(*openOutput("circuit.ir")); diff --git a/zirgen/bootstrap/src/main.rs b/zirgen/bootstrap/src/main.rs index 0c021b54..1d43fa1c 100644 --- a/zirgen/bootstrap/src/main.rs +++ b/zirgen/bootstrap/src/main.rs @@ -257,7 +257,7 @@ impl Args { "src", "", ); - copy_group(circuit, &src_path, &sys_path, ZIRGEN_SYS_OUTPUTS, "src", ""); + copy_group(circuit, &src_path, &sys_path, ZIRGEN_SYS_OUTPUTS, "cxx", ""); // TODO: Improve formatting performance // cargo_fmt_circuit(circuit, &rust_path, &None); } diff --git a/zirgen/circuit/bigint/gen_bigint.cpp b/zirgen/circuit/bigint/gen_bigint.cpp index ba4e8bbb..c98b25cb 100644 --- a/zirgen/circuit/bigint/gen_bigint.cpp +++ b/zirgen/circuit/bigint/gen_bigint.cpp @@ -41,14 +41,12 @@ std::unique_ptr openOutputFile(StringRef path, StringRef n return ofs; } -void emitLang(StringRef langName, - zirgen::codegen::LanguageSyntax* lang, - StringRef path, - ModuleOp module) { +void emit(StringRef langName, + const zirgen::codegen::CodegenOptions& codegenOpts, + StringRef path, + ModuleOp module) { auto ofs = openOutputFile(path, ("bigint." + langName + ".inc").str()); - codegen::CodegenOptions codegenOpts; - codegenOpts.lang = lang; zirgen::codegen::CodegenEmitter cg(codegenOpts, ofs.get(), module.getContext()); cg.emitModule(module); @@ -201,15 +199,17 @@ int main(int argc, char* argv[]) { throw std::runtime_error("Failed to apply basic optimization passes"); } - static codegen::RustLanguageSyntax rustLang; - rustLang.addContextArgument("ctx: &mut BigIntContext"); - rustLang.addItemsMacro("bigint_program_info"); - rustLang.addItemsMacro("bigint_program_list"); - emitLang("rs", &rustLang, outputDir, module.getModule()); + auto rustOpts = codegen::getRustCodegenOpts(); + auto rustLang = dynamic_cast(rustOpts.lang); + assert(rustLang && "expecting getRsutCodegenOpts to use RustLanguage"); + rustLang->addContextArgument("ctx: &mut BigIntContext"); + rustLang->addItemsMacro("bigint_program_info"); + rustLang->addItemsMacro("bigint_program_list"); + emit("rs", rustOpts, outputDir, module.getModule()); - static codegen::CppLanguageSyntax cppLang; - cppLang.addContextArgument("BigIntContext& ctx"); - emitLang("cpp", &cppLang, outputDir, module.getModule()); + auto cppOpts = codegen::getRustCodegenOpts(); + cppOpts.lang->addContextArgument("BigIntContext& ctx"); + emit("cpp", cppOpts, outputDir, module.getModule()); PassManager pm2(module.getCtx()); if (failed(applyPassManagerCLOptions(pm2))) { diff --git a/zirgen/compiler/codegen/CppLanguageSyntax.cpp b/zirgen/compiler/codegen/CppLanguageSyntax.cpp index bec14df6..eff41b05 100644 --- a/zirgen/compiler/codegen/CppLanguageSyntax.cpp +++ b/zirgen/compiler/codegen/CppLanguageSyntax.cpp @@ -25,24 +25,6 @@ using namespace zirgen::Zll; namespace zirgen::codegen { -void CppLanguageSyntax::fallbackEmitLiteral(CodegenEmitter& cg, - mlir::Type ty, - mlir::Attribute value) { - TypeSwitch(value) - .Case([&](auto intAttr) { cg << intAttr.getValue().getZExtValue(); }) - .Case([&](auto strAttr) { cg.emitEscapedString(strAttr); }) - .Case([&](auto polyAttr) { - cg << "(" << ty.cast().getTypeName(cg) << " {"; - cg.interleaveComma(polyAttr.asArrayRef()); - cg << "})"; - }) - .Default([&](auto) { - llvm::errs() << "Don't know how to emit type " << ty << " into C++ with value " << value - << "\n"; - abort(); - }); -} - void CppLanguageSyntax::emitConditional(CodegenEmitter& cg, CodegenValue condition, EmitPart emitThen) { diff --git a/zirgen/compiler/codegen/RustLanguageSyntax.cpp b/zirgen/compiler/codegen/RustLanguageSyntax.cpp index 81019967..392cac82 100644 --- a/zirgen/compiler/codegen/RustLanguageSyntax.cpp +++ b/zirgen/compiler/codegen/RustLanguageSyntax.cpp @@ -62,19 +62,6 @@ void RustLanguageSyntax::emitSwitchStatement(CodegenEmitter& cg, cg << "}"; } -void RustLanguageSyntax::fallbackEmitLiteral(CodegenEmitter& cg, - mlir::Type ty, - mlir::Attribute value) { - TypeSwitch(value) - .Case([&](auto intAttr) { cg << intAttr.getValue().getZExtValue(); }) - .Case([&](auto strAttr) { cg.emitEscapedString(strAttr); }) - .Default([&](auto) { - llvm::errs() << "Don't know how to emit type " << ty << " into rust++ with value " << value - << "\n"; - abort(); - }); -} - void RustLanguageSyntax::emitFuncDefinition(CodegenEmitter& cg, CodegenIdent funcName, llvm::ArrayRef> argNames, diff --git a/zirgen/compiler/codegen/codegen.cpp b/zirgen/compiler/codegen/codegen.cpp index b974ef87..1a775694 100644 --- a/zirgen/compiler/codegen/codegen.cpp +++ b/zirgen/compiler/codegen/codegen.cpp @@ -27,12 +27,50 @@ using namespace mlir; namespace cl = llvm::cl; namespace zirgen { - namespace codegen { +namespace { + +void addCommonSyntax(CodegenOptions& opts) { + opts.addLiteralHandler( + [](CodegenEmitter& cg, auto intAttr) { cg << intAttr.getValue().getZExtValue(); }); + opts.addLiteralHandler( + [](CodegenEmitter& cg, auto strAttr) { cg.emitEscapedString(strAttr); }); +} + +void addCppSyntax(CodegenOptions& opts) { + opts.addLiteralHandler([&](CodegenEmitter& cg, auto polyAttr) { + auto elems = polyAttr.asArrayRef(); + if (elems.size() == 1) { + cg << "Val(" << elems[0] << ")"; + } else { + cg << "Val" << elems.size() << "{"; + cg.interleaveComma(elems); + cg << "}"; + } + }); +} + +void addRustSyntax(CodegenOptions& opts) { + opts.addLiteralHandler([&](CodegenEmitter& cg, auto polyAttr) { + auto elems = polyAttr.asArrayRef(); + if (elems.size() == 1) { + cg << "Val::new(" << elems[0] << ")"; + } else { + cg << "ExtVal::new("; + cg.interleaveComma(elems); + cg << ")"; + } + }); +} + +} // namespace + CodegenOptions getRustCodegenOpts() { static codegen::RustLanguageSyntax kRust; codegen::CodegenOptions opts(&kRust); + addCommonSyntax(opts); + addRustSyntax(opts); ZStruct::addRustSyntax(opts); return opts; } @@ -40,6 +78,8 @@ CodegenOptions getRustCodegenOpts() { CodegenOptions getCppCodegenOpts() { static codegen::CppLanguageSyntax kCpp; codegen::CodegenOptions opts(&kCpp); + addCommonSyntax(opts); + addCppSyntax(opts); ZStruct::addCppSyntax(opts); return opts; } @@ -47,6 +87,8 @@ CodegenOptions getCppCodegenOpts() { CodegenOptions getCudaCodegenOpts() { static codegen::CudaLanguageSyntax kCuda; codegen::CodegenOptions opts(&kCuda); + addCommonSyntax(opts); + addCppSyntax(opts); ZStruct::addCppSyntax(opts); return opts; } diff --git a/zirgen/compiler/codegen/codegen.h b/zirgen/compiler/codegen/codegen.h index c00dc25e..929b6cc0 100644 --- a/zirgen/compiler/codegen/codegen.h +++ b/zirgen/compiler/codegen/codegen.h @@ -85,7 +85,6 @@ class RustLanguageSyntax : public LanguageSyntax { std::string canonIdent(llvm::StringRef ident, IdentKind idt) override; void emitClone(CodegenEmitter& cg, CodegenIdent value) override; void emitTakeReference(CodegenEmitter& cg, EmitPart emitTarget) override; - void fallbackEmitLiteral(CodegenEmitter& cg, mlir::Type ty, mlir::Attribute value) override; void emitConditional(CodegenEmitter& cg, CodegenValue condition, EmitPart emitThen) override; void emitSwitchStatement(CodegenEmitter& cg, @@ -161,7 +160,6 @@ struct CppLanguageSyntax : public LanguageSyntax { LanguageKind getLanguageKind() override { return LanguageKind::Cpp; } std::string canonIdent(llvm::StringRef ident, IdentKind idt) override; - void fallbackEmitLiteral(CodegenEmitter& cg, mlir::Type ty, mlir::Attribute value) override; void emitConditional(CodegenEmitter& cg, CodegenValue condition, EmitPart emitThen) override; void emitSwitchStatement(CodegenEmitter& cg, diff --git a/zirgen/compiler/tools/zirgen-translate.cpp b/zirgen/compiler/tools/zirgen-translate.cpp index ae740fd1..5de58fe5 100644 --- a/zirgen/compiler/tools/zirgen-translate.cpp +++ b/zirgen/compiler/tools/zirgen-translate.cpp @@ -85,9 +85,7 @@ int main(int argc, char** argv) { "rust-codegen", "", [](mlir::ModuleOp module, llvm::raw_ostream& output) { - static codegen::RustLanguageSyntax rust; - codegen::CodegenOptions opts; - opts.lang = &rust; + codegen::CodegenOptions opts = codegen::getRustCodegenOpts(); if (!funcName.empty()) { auto func = module.lookupSymbol(funcName); if (!func) { @@ -107,9 +105,7 @@ int main(int argc, char** argv) { "cpp-codegen", "", [](mlir::ModuleOp module, llvm::raw_ostream& output) { - static codegen::CppLanguageSyntax cpp; - codegen::CodegenOptions opts; - opts.lang = &cpp; + codegen::CodegenOptions opts = codegen::getCppCodegenOpts(); if (!funcName.empty()) { auto func = module.lookupSymbol(funcName); if (!func) { diff --git a/zirgen/dsl/driver.cpp b/zirgen/dsl/driver.cpp index ad177839..7532915f 100644 --- a/zirgen/dsl/driver.cpp +++ b/zirgen/dsl/driver.cpp @@ -262,14 +262,9 @@ int main(int argc, char* argv[]) { } if (emitAction == Action::PrintRust || emitAction == Action::PrintCpp) { - codegen::CodegenOptions codegenOpts; - static codegen::RustLanguageSyntax kRust; - static codegen::CppLanguageSyntax kCpp; - - codegenOpts.lang = (emitAction == Action::PrintRust) - ? static_cast(&kRust) - : static_cast(&kCpp); - + codegen::CodegenOptions codegenOpts = (emitAction == Action::PrintRust) + ? codegen::getRustCodegenOpts() + : codegen::getCppCodegenOpts(); zirgen::codegen::CodegenEmitter emitter(codegenOpts, &llvm::outs(), &context); if (zirgen::Zhlt::emitModule(*typedModule, emitter).failed()) { llvm::errs() << "Failed to emit circuit\n"; diff --git a/zirgen/dsl/examples/Fp.h b/zirgen/dsl/examples/Fp.h index 946a6ded..5529d931 100644 --- a/zirgen/dsl/examples/Fp.h +++ b/zirgen/dsl/examples/Fp.h @@ -62,27 +62,17 @@ Val4 operator*(const Val4& lhs, const Val4& rhs) { // In a real zero-knowledge proof, "Reg" would be a reference of some // sort into an execution trace. However, for testing code generation // we don't have to supply a full implementation. -struct Reg { - size_t index; -}; - -bool operator==(const Reg& lhs, const Reg& rhs) { - return lhs.index == rhs.index; -} +using Reg = size_t; -#define MAKE_REF(INDEX) \ - Reg { .index = INDEX } -#define MAKE_VAL(VAL) Val(VAL) -#define MAKE_VAL_EXT(...) Val4({__VA_ARGS__}) -#define LOAD(REF, BACK) Val(REF.buffer.at(REF.layout->index)) +#define LOAD(REF, BACK) Val(REF.buffer.at(*REF.layout)) #define LOAD_AS_EXT(REF, BACK) \ Val4 { LOAD(REF, BACK), 0, 0, 0 } #define LOAD_EXT(REF, BACK) \ Val4 { \ - REF.buffer.at(REF.layout->index + 0), REF.buffer.at(REF.layout->index + 1), \ - REF.buffer.at(REF.layout->index + 2), REF.buffer.at(REF.layout->index + 3), \ + REF.buffer.at(*REF.layout + 0), REF.buffer.at(*REF.layout + 1), \ + REF.buffer.at(*REF.layout + 2), REF.buffer.at(*REF.layout + 3), \ } -#define STORE(REF, VAL) REF.buffer.at(REF.layout->index) = VAL +#define STORE(REF, VAL) REF.buffer.at(*REF.layout) = VAL #define DEFINE_LAYOUT_BUFFER(CONST, BUFFER) /* */ #define LAYOUT_LOOKUP(LAYOUT, FIELD) LAYOUT.map([](auto layout) { return &layout->FIELD; }) #define LAYOUT_SUBSCRIPT(LAYOUT, INDEX) LAYOUT.map([](auto layout) { return &layout->at(INDEX); }) @@ -107,7 +97,7 @@ template struct BoundLayout { template auto load(T& buf, Reg ref, size_t distance = 0) { // TODO: Implement backs assert(distance == 0); - return buf.data.at(ref.index); + return buf.data.at(ref); } #define EQZ(VAL, LOC) eqz(VAL, LOC) diff --git a/zirgen/dsl/examples/calculator.cpp b/zirgen/dsl/examples/calculator.cpp index 32a3801c..7f480e72 100644 --- a/zirgen/dsl/examples/calculator.cpp +++ b/zirgen/dsl/examples/calculator.cpp @@ -96,10 +96,10 @@ TEST(calculator, adder) { TopStruct top = exec_Top(ctx, BoundLayout(&layout, dataBuffer)); // Make sure our output registers were filled in correctly. - EXPECT_EQ(ctx.data.at(layout.left._super.index), 123); - EXPECT_EQ(ctx.data.at(layout.right._super.index), 456); + EXPECT_EQ(ctx.data.at(layout.left._super), 123); + EXPECT_EQ(ctx.data.at(layout.right._super), 456); // TODO: hide this _construct7 name. - Val result = ctx.data.at(layout.result._super._super.index); + Val result = ctx.data.at(layout.result._super._super); EXPECT_EQ(result, 123 + 456); // Make sure the values returned from the "Top" component were filled in correctly. @@ -140,9 +140,9 @@ TEST(calculator, subtractor) { TopStruct top = exec_Top(ctx, BoundLayout(&layout, ctx.data)); // Make sure our output registers were filled in correctly. - EXPECT_EQ(ctx.data.at(layout.left._super.index), 456); - EXPECT_EQ(ctx.data.at(layout.right._super.index), 123); - Val result = ctx.data.at(layout.result._super._super.index); + EXPECT_EQ(ctx.data.at(layout.left._super), 456); + EXPECT_EQ(ctx.data.at(layout.right._super), 123); + Val result = ctx.data.at(layout.result._super._super); EXPECT_EQ(result, 456 - 123); // Make sure the values returned from the "Top" component were filled in correctly. diff --git a/zirgen/dsl/examples/calculator.cpp.inc b/zirgen/dsl/examples/calculator.cpp.inc index 8761f26d..d76bdc72 100644 --- a/zirgen/dsl/examples/calculator.cpp.inc +++ b/zirgen/dsl/examples/calculator.cpp.inc @@ -67,17 +67,17 @@ constexpr Tap8Array kTapList = Tap8Array{MAKE_TAP(0, 0, 0), MAKE_TAP(2, 4, 0), MAKE_TAP(2, 5, 0)}; constexpr TopLayout kLayout_Top = TopLayout{ - .op = NondetRegLayout{._super = MAKE_REF(0)}, - .left = NondetRegLayout{._super = MAKE_REF(1)}, - .right = NondetRegLayout{._super = MAKE_REF(2)}, - ._0 = - OneHotLayout{._super = NondetRegLayout2LayoutArray{NondetRegLayout{._super = MAKE_REF(3)}, - NondetRegLayout{._super = MAKE_REF(4)}}}, - .result = TopResultLayout{._super = NondetRegLayout{._super = MAKE_REF(5)}, - .arm0 = NondetRegLayout{._super = MAKE_REF(5)}, - .arm1 = NondetRegLayout{._super = MAKE_REF(5)}}}; + .op = NondetRegLayout{._super = /*offset=*/0}, + .left = NondetRegLayout{._super = /*offset=*/1}, + .right = NondetRegLayout{._super = /*offset=*/2}, + ._0 = OneHotLayout{._super = + NondetRegLayout2LayoutArray{NondetRegLayout{._super = /*offset=*/3}, + NondetRegLayout{._super = /*offset=*/4}}}, + .result = TopResultLayout{._super = NondetRegLayout{._super = /*offset=*/5}, + .arm0 = NondetRegLayout{._super = /*offset=*/5}, + .arm1 = NondetRegLayout{._super = /*offset=*/5}}}; constexpr _globalLayout kLayoutGlobal = - _globalLayout{.result = NondetRegLayout{._super = MAKE_REF(0)}}; + _globalLayout{.result = NondetRegLayout{._super = /*offset=*/0}}; Val exec_Isz(ExecContext ctx0, Val arg1) { return isz(arg1); } @@ -130,7 +130,7 @@ ComponentStruct exec_OutputToUser(ExecContext ctx0, Val arg1) { } OneHotStruct exec_OneHot(ExecContext ctx0, Val arg1, BoundLayout layout2) { // OneHot(zirgen/dsl/examples/calculator.zir:13) - Val2Array x3 = Val2Array{MAKE_VAL(0), MAKE_VAL(1)}; + Val2Array x3 = Val2Array{Val(0), Val(1)}; NondetRegStruct2Array x4 = map(x3, LAYOUT_LOOKUP(layout2, _super), @@ -144,31 +144,30 @@ OneHotStruct exec_OneHot(ExecContext ctx0, Val arg1, BoundLayout l // OneHot(zirgen/dsl/examples/calculator.zir:15) ComponentStruct2Array x10 = map(x4, std::function([&](NondetRegStruct2Array::value_type x11) { Val x12 = x11._super; - Val x13 = exec_Sub(ctx0, MAKE_VAL(1), x12); + Val x13 = exec_Sub(ctx0, Val(1), x12); Val x14 = exec_Mul(ctx0, x12, x13); EQZ(x14, "OneHot(zirgen/dsl/examples/calculator.zir:15)"); ComponentStruct x15 = exec_Component(ctx0); return x15; })); // OneHot(zirgen/dsl/examples/calculator.zir:17) - Val x16 = - reduce(x4, MAKE_VAL(0), std::function([&](Val x17, NondetRegStruct2Array::value_type x18) { - Val x19 = exec_Add(ctx0, x17, x18._super); - return x19; - })); - EQZ((x16 - MAKE_VAL(1)), "OneHot(zirgen/dsl/examples/calculator.zir:17)"); + Val x16 = reduce(x4, Val(0), std::function([&](Val x17, NondetRegStruct2Array::value_type x18) { + Val x19 = exec_Add(ctx0, x17, x18._super); + return x19; + })); + EQZ((x16 - Val(1)), "OneHot(zirgen/dsl/examples/calculator.zir:17)"); // OneHot(zirgen/dsl/examples/calculator.zir:19) OneHot__0_SuperStruct2Array x20 = map(x3, std::function([&](Val2Array::value_type x21) { Val x22 = exec_Mul(ctx0, x4[to_size_t(x21)]._super, x21); return OneHot__0_SuperStruct{._super = x22}; })); - Val x23 = reduce( - x20, MAKE_VAL(0), std::function([&](Val x24, OneHot__0_SuperStruct2Array::value_type x25) { - Val x26 = exec_Add(ctx0, x24, x25._super); - return x26; - })); + Val x23 = + reduce(x20, Val(0), std::function([&](Val x24, OneHot__0_SuperStruct2Array::value_type x25) { + Val x26 = exec_Add(ctx0, x24, x25._super); + return x26; + })); EQZ((x23 - arg1), "OneHot(zirgen/dsl/examples/calculator.zir:19)"); - return OneHotStruct{._super = x4, .n = MAKE_VAL(2), .bits = x4}; + return OneHotStruct{._super = x4, .n = Val(2), .bits = x4}; } RegStruct exec_GetGlobalResult(ExecContext ctx0) { // GetGlobalResult(zirgen/dsl/examples/calculator.zir:23) @@ -251,12 +250,11 @@ MixState validityTaps_(ValidityTapsContext ctx0, PolyMix polyMix1, ExtVal8Array // OneHot(zirgen/dsl/examples/calculator.zir:19) MixState x4 = andEqzExt( polyMix1, - andEqzExt( - polyMix1, - andEqzExt(polyMix1, - andEqzExt(polyMix1, x3, (taps2[5] * (MAKE_VAL_EXT(1, 0, 0, 0) - taps2[5]))), - (taps2[6] * (MAKE_VAL_EXT(1, 0, 0, 0) - taps2[6]))), - ((taps2[5] + taps2[6]) - MAKE_VAL_EXT(1, 0, 0, 0))), + andEqzExt(polyMix1, + andEqzExt(polyMix1, + andEqzExt(polyMix1, x3, (taps2[5] * (Val4{1, 0, 0, 0} - taps2[5]))), + (taps2[6] * (Val4{1, 0, 0, 0} - taps2[6]))), + ((taps2[5] + taps2[6]) - Val4{1, 0, 0, 0})), (taps2[6] - taps2[2])); // SetGlobalResult(zirgen/dsl/examples/calculator.zir:28) // Top(zirgen/dsl/examples/calculator.zir:41) @@ -284,17 +282,16 @@ MixState validityRegs_(ValidityRegsContext ctx0, PolyMix polyMix1) { MixState x5 = andEqz(polyMix1, trivialConstraint(), (LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 0), _super), 0) * - (MAKE_VAL(1) - LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 0), _super), 0)))); + (Val(1) - LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 0), _super), 0)))); // OneHot(zirgen/dsl/examples/calculator.zir:17) - MixState x6 = - andEqz(polyMix1, - andEqz(polyMix1, - x5, - (LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 1), _super), 0) * - (MAKE_VAL(1) - LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 1), _super), 0)))), - ((LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 0), _super), 0) + - LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 1), _super), 0)) - - MAKE_VAL(1))); + MixState x6 = andEqz(polyMix1, + andEqz(polyMix1, + x5, + (LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 1), _super), 0) * + (Val(1) - LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 1), _super), 0)))), + ((LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 0), _super), 0) + + LOAD(LAYOUT_LOOKUP(LAYOUT_SUBSCRIPT(x4, 1), _super), 0)) - + Val(1))); BoundLayout x7 = LAYOUT_LOOKUP(x3, _super); // Reg(:5) // Top(zirgen/dsl/examples/calculator.zir:37) diff --git a/zirgen/dsl/examples/calculator.rs.inc b/zirgen/dsl/examples/calculator.rs.inc index 1270454b..763534f5 100644 --- a/zirgen/dsl/examples/calculator.rs.inc +++ b/zirgen/dsl/examples/calculator.rs.inc @@ -138,39 +138,39 @@ pub const TAP_LIST: Tap8Array = [ ]; pub const LAYOUT_TOP: &TopLayout = &TopLayout { op: &NondetRegLayout { - _super: make_ref!(0), + _super: &Reg { offset: 0 }, }, left: &NondetRegLayout { - _super: make_ref!(1), + _super: &Reg { offset: 1 }, }, right: &NondetRegLayout { - _super: make_ref!(2), + _super: &Reg { offset: 2 }, }, _0: &OneHotLayout { _super: &[ &NondetRegLayout { - _super: make_ref!(3), + _super: &Reg { offset: 3 }, }, &NondetRegLayout { - _super: make_ref!(4), + _super: &Reg { offset: 4 }, }, ], }, result: &TopResultLayout { _super: &NondetRegLayout { - _super: make_ref!(5), + _super: &Reg { offset: 5 }, }, arm0: &NondetRegLayout { - _super: make_ref!(5), + _super: &Reg { offset: 5 }, }, arm1: &NondetRegLayout { - _super: make_ref!(5), + _super: &Reg { offset: 5 }, }, }, }; pub const LAYOUT_GLOBAL: &_globalLayout = &_globalLayout { result: &NondetRegLayout { - _super: make_ref!(0), + _super: &Reg { offset: 0 }, }, }; pub fn exec_isz(ctx0: &ExecContext, arg1: Val) -> Result { @@ -254,7 +254,7 @@ pub fn exec_one_hot( layout2: BoundLayout>, ) -> Result { // OneHot(zirgen/dsl/examples/calculator.zir:13) - let x3: Val2Array = [make_val!(0), make_val!(1)]; + let x3: Val2Array = [Val::new(0), Val::new(1)]; let x4: NondetRegStruct2Array = map_layout(x3, layout_lookup!(layout2, _super), |x5, x6| { let x7: Val = exec_sub(ctx0, x5, arg1)?; let x8: Val = exec_isz(ctx0, x7)?; @@ -264,19 +264,19 @@ pub fn exec_one_hot( // OneHot(zirgen/dsl/examples/calculator.zir:15) let x10: ComponentStruct2Array = map(x4, |x11| { let x12: Val = x11._super; - let x13: Val = exec_sub(ctx0, make_val!(1), x12)?; + let x13: Val = exec_sub(ctx0, Val::new(1), x12)?; let x14: Val = exec_mul(ctx0, x12, x13)?; eqz!(x14, "OneHot(zirgen/dsl/examples/calculator.zir:15)"); let x15: ComponentStruct = exec_component(ctx0)?; return Ok(x15); })?; // OneHot(zirgen/dsl/examples/calculator.zir:17) - let x16: Val = reduce(x4, make_val!(0), |x17, x18| { + let x16: Val = reduce(x4, Val::new(0), |x17, x18| { let x19: Val = exec_add(ctx0, x17, x18._super)?; return Ok(x19); })?; eqz!( - (x16 - make_val!(1)), + (x16 - Val::new(1)), "OneHot(zirgen/dsl/examples/calculator.zir:17)" ); // OneHot(zirgen/dsl/examples/calculator.zir:19) @@ -284,7 +284,7 @@ pub fn exec_one_hot( let x22: Val = exec_mul(ctx0, x4[u64::from(x21) as usize]._super, x21)?; return Ok(OneHot__0_SuperStruct { _super: x22 }); })?; - let x23: Val = reduce(x20, make_val!(0), |x24, x25| { + let x23: Val = reduce(x20, Val::new(0), |x24, x25| { let x26: Val = exec_add(ctx0, x24, x25._super)?; return Ok(x26); })?; @@ -294,7 +294,7 @@ pub fn exec_one_hot( ); return Ok(OneHotStruct { _super: x4.clone(), - n: make_val!(2), + n: Val::new(2), bits: x4, }); } @@ -401,11 +401,11 @@ pub fn validity_taps_( and_eqz_ext( poly_mix1, x3, - (taps2[5] * (make_val_ext!(1, 0, 0, 0) - taps2[5])), + (taps2[5] * (ExtVal::new(1, 0, 0, 0) - taps2[5])), )?, - (taps2[6] * (make_val_ext!(1, 0, 0, 0) - taps2[6])), + (taps2[6] * (ExtVal::new(1, 0, 0, 0) - taps2[6])), )?, - ((taps2[5] + taps2[6]) - make_val_ext!(1, 0, 0, 0)), + ((taps2[5] + taps2[6]) - ExtVal::new(1, 0, 0, 0)), )?, (taps2[6] - taps2[2]), )?; @@ -444,7 +444,7 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< poly_mix1, trivial_constraint()?, (load!(layout_lookup!(layout_subscript!(x4, 0), _super), 0) - * (make_val!(1) - load!(layout_lookup!(layout_subscript!(x4, 0), _super), 0))), + * (Val::new(1) - load!(layout_lookup!(layout_subscript!(x4, 0), _super), 0))), )?; // OneHot(zirgen/dsl/examples/calculator.zir:17) let x6: MixState = and_eqz( @@ -453,11 +453,11 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< poly_mix1, x5, (load!(layout_lookup!(layout_subscript!(x4, 1), _super), 0) - * (make_val!(1) - load!(layout_lookup!(layout_subscript!(x4, 1), _super), 0))), + * (Val::new(1) - load!(layout_lookup!(layout_subscript!(x4, 1), _super), 0))), )?, ((load!(layout_lookup!(layout_subscript!(x4, 0), _super), 0) + load!(layout_lookup!(layout_subscript!(x4, 1), _super), 0)) - - make_val!(1)), + - Val::new(1)), )?; let x7: BoundLayout = layout_lookup!(x3, _super); // Reg(:5) diff --git a/zirgen/dsl/examples/fibonacci.rs.inc b/zirgen/dsl/examples/fibonacci.rs.inc index fc516fd5..0b78dcdb 100644 --- a/zirgen/dsl/examples/fibonacci.rs.inc +++ b/zirgen/dsl/examples/fibonacci.rs.inc @@ -135,14 +135,14 @@ pub struct TopStruct { pub type ExtVal13Array = [ExtVal; 13]; pub const LAYOUT__0: &CycleCounterLayout = &CycleCounterLayout { _super: &NondetRegLayout { - _super: make_ref!(0), + _super: &Reg { offset: 0 }, }, is_first_cycle: &IsZeroLayout { _super: &NondetRegLayout { - _super: make_ref!(1), + _super: &Reg { offset: 1 }, }, inv: &NondetRegLayout { - _super: make_ref!(2), + _super: &Reg { offset: 2 }, }, }, }; @@ -164,38 +164,38 @@ pub const TAP_LIST: Tap13Array = [ pub const LAYOUT_TOP: &TopLayout = &TopLayout { cycle: LAYOUT__0, d2: &NondetRegLayout { - _super: make_ref!(3), + _super: &Reg { offset: 3 }, }, d3: &NondetRegLayout { - _super: make_ref!(4), + _super: &Reg { offset: 4 }, }, d1: &NondetRegLayout { - _super: make_ref!(5), + _super: &Reg { offset: 5 }, }, terminate: &IsZeroLayout { _super: &NondetRegLayout { - _super: make_ref!(6), + _super: &Reg { offset: 6 }, }, inv: &NondetRegLayout { - _super: make_ref!(7), + _super: &Reg { offset: 7 }, }, }, }; pub const LAYOUT_GLOBAL: &_globalLayout = &_globalLayout { f0: &NondetRegLayout { - _super: make_ref!(0), + _super: &Reg { offset: 0 }, }, f1: &NondetRegLayout { - _super: make_ref!(1), + _super: &Reg { offset: 1 }, }, f_last: &NondetRegLayout { - _super: make_ref!(2), + _super: &Reg { offset: 2 }, }, steps: &NondetRegLayout { - _super: make_ref!(3), + _super: &Reg { offset: 3 }, }, total_cycles: &NondetRegLayout { - _super: make_ref!(4), + _super: &Reg { offset: 4 }, }, }; pub fn exec_inv(ctx0: &ExecContext, arg1: Val) -> Result { @@ -285,14 +285,14 @@ pub fn exec_is_zero( // IsZero(zirgen/dsl/examples/fibonacci.zir:6) let x7: Val = x4._super; // IsZero(zirgen/dsl/examples/fibonacci.zir:12) - let x8: Val = exec_sub(ctx0, make_val!(1), x7)?; + let x8: Val = exec_sub(ctx0, Val::new(1), x7)?; let x9: Val = exec_mul(ctx0, x7, x8)?; eqz!(x9, "IsZero(zirgen/dsl/examples/fibonacci.zir:12)"); // IsZero(zirgen/dsl/examples/fibonacci.zir:9) let x10: Val = x6._super; // IsZero(zirgen/dsl/examples/fibonacci.zir:14) let x11: Val = exec_mul(ctx0, arg1, x10)?; - let x12: Val = exec_sub(ctx0, make_val!(1), x7)?; + let x12: Val = exec_sub(ctx0, Val::new(1), x7)?; eqz!((x11 - x12), "IsZero(zirgen/dsl/examples/fibonacci.zir:14)"); // IsZero(zirgen/dsl/examples/fibonacci.zir:16) let x13: Val = exec_mul(ctx0, x7, arg1)?; @@ -315,8 +315,7 @@ pub fn exec_cycle_counter( // CycleCounter(zirgen/dsl/examples/fibonacci.zir:31) let x3: BoundLayout = layout_lookup!(layout1, _super); // CycleCounter(zirgen/dsl/examples/fibonacci.zir:29) - let x4: NondetRegStruct = - exec_nondet_reg(ctx0, make_val!(6), layout_lookup!(x2, total_cycles))?; + let x4: NondetRegStruct = exec_nondet_reg(ctx0, Val::new(6), layout_lookup!(x2, total_cycles))?; // CycleCounter(zirgen/dsl/examples/fibonacci.zir:31) let x5: GetCycleStruct = exec_get_cycle(ctx0)?; let x6: NondetRegStruct = exec_nondet_reg(ctx0, x5._super, x3)?; @@ -325,7 +324,7 @@ pub fn exec_cycle_counter( let x8: IsZeroStruct = exec_is_zero(ctx0, x7, layout_lookup!(layout1, is_first_cycle))?; let x9: Val = x8._super._super; // CycleCounter(zirgen/dsl/examples/fibonacci.zir:34) - let x10: Val = exec_sub(ctx0, make_val!(1), x9)?; + let x10: Val = exec_sub(ctx0, Val::new(1), x9)?; let x11: ComponentStruct; if is_nonzero(x9) { let x12: ComponentStruct = exec_component(ctx0)?; @@ -333,7 +332,7 @@ pub fn exec_cycle_counter( } else if is_nonzero(x10) { // CycleCounter(zirgen/dsl/examples/fibonacci.zir:39) let x13: NondetRegStruct = back_nondet_reg(ctx0, 1, x3)?; - let x14: Val = exec_add(ctx0, x13._super, make_val!(1))?; + let x14: Val = exec_add(ctx0, x13._super, Val::new(1))?; eqz!( (x7 - x14), "CycleCounter(zirgen/dsl/examples/fibonacci.zir:39)" @@ -365,7 +364,7 @@ pub fn exec_top( let x6: IsZeroStruct = x5.is_first_cycle; let x7: Val = x6._super._super; // Top(zirgen/dsl/examples/fibonacci.zir:55) - let x8: Val = exec_sub(ctx0, make_val!(1), x7)?; + let x8: Val = exec_sub(ctx0, Val::new(1), x7)?; let x9: RegStruct; if is_nonzero(x7) { // Top(zirgen/dsl/examples/fibonacci.zir:45) @@ -380,7 +379,7 @@ pub fn exec_top( } let x12: RegStruct = exec_reg(ctx0, x9._super._super, layout_lookup!(layout1, d1))?; // Top(zirgen/dsl/examples/fibonacci.zir:56) - let x13: Val = exec_sub(ctx0, make_val!(1), x7)?; + let x13: Val = exec_sub(ctx0, Val::new(1), x7)?; let x14: RegStruct; if is_nonzero(x7) { // Top(zirgen/dsl/examples/fibonacci.zir:46) @@ -401,11 +400,11 @@ pub fn exec_top( let x20: RegStruct = back_reg(ctx0, 0, layout_lookup!(x2, steps))?; // Top(zirgen/dsl/examples/fibonacci.zir:62) let x21: Val = exec_sub(ctx0, x5._super._super, x20._super._super)?; - let x22: Val = exec_add(ctx0, x21, make_val!(1))?; + let x22: Val = exec_add(ctx0, x21, Val::new(1))?; let x23: IsZeroStruct = exec_is_zero(ctx0, x22, layout_lookup!(layout1, terminate))?; let x24: Val = x23._super._super; // Top(zirgen/dsl/examples/fibonacci.zir:63) - let x25: Val = exec_sub(ctx0, make_val!(1), x24)?; + let x25: Val = exec_sub(ctx0, Val::new(1), x24)?; let x26: ComponentStruct; if is_nonzero(x24) { // Top(zirgen/dsl/examples/fibonacci.zir:64) @@ -452,7 +451,7 @@ pub fn validity_taps_( // IsZero(zirgen/dsl/examples/fibonacci.zir:12) // CycleCounter(zirgen/dsl/examples/fibonacci.zir:32) // Top(zirgen/dsl/examples/fibonacci.zir:49) - let x5: ExtVal = (make_val_ext!(1, 0, 0, 0) - taps2[4]); + let x5: ExtVal = (ExtVal::new(1, 0, 0, 0) - taps2[4]); // IsZero(zirgen/dsl/examples/fibonacci.zir:18) let x6: MixState = and_eqz_ext( poly_mix1, @@ -481,9 +480,9 @@ pub fn validity_taps_( // Top(zirgen/dsl/examples/fibonacci.zir:62) let x9: ExtVal = ((taps2[2] - load_as_ext!(layout_lookup!(layout_lookup!(x4, steps), _super), 0)) - + make_val_ext!(1, 0, 0, 0)); + + ExtVal::new(1, 0, 0, 0)); // IsZero(zirgen/dsl/examples/fibonacci.zir:12) - let x10: ExtVal = (make_val_ext!(1, 0, 0, 0) - taps2[11]); + let x10: ExtVal = (ExtVal::new(1, 0, 0, 0) - taps2[11]); // IsZero(zirgen/dsl/examples/fibonacci.zir:14) let x11: MixState = and_eqz_ext( poly_mix1, @@ -501,7 +500,7 @@ pub fn validity_taps_( and_eqz_ext( poly_mix1, x3, - (taps2[2] - (taps2[3] + make_val_ext!(1, 0, 0, 0))), + (taps2[2] - (taps2[3] + ExtVal::new(1, 0, 0, 0))), )?, )?, x7, @@ -549,7 +548,7 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< poly_mix1, trivial_constraint()?, (load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0) - * (make_val!(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0))), + * (Val::new(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0))), )?; // IsZero(zirgen/dsl/examples/fibonacci.zir:18) let x11: MixState = and_eqz( @@ -561,8 +560,7 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< x10, ((load!(layout_lookup!(x8, _super), 0) * load!(layout_lookup!(layout_lookup!(x9, inv), _super), 0)) - - (make_val!(1) - - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0))), + - (Val::new(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0))), )?, (load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0) * load!(layout_lookup!(x8, _super), 0)), @@ -574,12 +572,12 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< let x12: Val = ((load!(layout_lookup!(layout_lookup!(x3, f0), _super), 0) * load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)) + (load!(layout_lookup!(x5, _super), 1) - * (make_val!(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)))); + * (Val::new(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)))); // Top(zirgen/dsl/examples/fibonacci.zir:56) let x13: Val = ((load!(layout_lookup!(layout_lookup!(x3, f1), _super), 0) * load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)) + (load!(layout_lookup!(x6, _super), 1) - * (make_val!(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)))); + * (Val::new(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)))); // Reg(:5) // Top(zirgen/dsl/examples/fibonacci.zir:59) let x14: MixState = and_eqz( @@ -590,12 +588,12 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< poly_mix1, and_cond( x11, - (make_val!(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)), + (Val::new(1) - load!(layout_lookup!(layout_lookup!(x9, _super), _super), 0)), and_eqz( poly_mix1, trivial_constraint()?, (load!(layout_lookup!(x8, _super), 0) - - (load!(layout_lookup!(x8, _super), 1) + make_val!(1))), + - (load!(layout_lookup!(x8, _super), 1) + Val::new(1))), )?, )?, (x12 - load!(layout_lookup!(layout_lookup!(x2, d1), _super), 0)), @@ -609,7 +607,7 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< // Top(zirgen/dsl/examples/fibonacci.zir:62) let x15: Val = ((load!(layout_lookup!(x8, _super), 0) - load!(layout_lookup!(layout_lookup!(x3, steps), _super), 0)) - + make_val!(1)); + + Val::new(1)); // IsZero(zirgen/dsl/examples/fibonacci.zir:14) let x16: MixState = and_eqz( poly_mix1, @@ -617,10 +615,10 @@ pub fn validity_regs_(ctx0: &ValidityRegsContext, poly_mix1: PolyMix) -> Result< poly_mix1, x14, (load!(layout_lookup!(layout_lookup!(x7, _super), _super), 0) - * (make_val!(1) - load!(layout_lookup!(layout_lookup!(x7, _super), _super), 0))), + * (Val::new(1) - load!(layout_lookup!(layout_lookup!(x7, _super), _super), 0))), )?, ((x15 * load!(layout_lookup!(layout_lookup!(x7, inv), _super), 0)) - - (make_val!(1) - load!(layout_lookup!(layout_lookup!(x7, _super), _super), 0))), + - (Val::new(1) - load!(layout_lookup!(layout_lookup!(x7, _super), _super), 0))), )?; // Top(zirgen/dsl/examples/fibonacci.zir:63) let x17: MixState = and_cond( diff --git a/zirgen/dsl/src/codegen/_support.rs b/zirgen/dsl/src/codegen/_support.rs index c1d2871d..96e50e80 100644 --- a/zirgen/dsl/src/codegen/_support.rs +++ b/zirgen/dsl/src/codegen/_support.rs @@ -208,7 +208,7 @@ macro_rules! import_macros { } import_macros! { - make_ref, make_tap, invoke_extern, make_val, make_val_ext, + make_tap, invoke_extern, set_field, load, load_as_ext, load_ext, store, store_ext, define_tap_buffer, define_global_buffer, define_buffer, define_buffer_list, bind_layout, layout_subscript, layout_lookup, eqz, get_buffer diff --git a/zirgen/dsl/src/codegen/_support_macros.rs b/zirgen/dsl/src/codegen/_support_macros.rs index 56eda258..c49f8b95 100644 --- a/zirgen/dsl/src/codegen/_support_macros.rs +++ b/zirgen/dsl/src/codegen/_support_macros.rs @@ -16,17 +16,6 @@ // minimimze namespace pollution since they appear in the top of the // library. -#[macro_export] -macro_rules! codegen_make_ref { - ($offset:literal) => { - paste::paste! { - &Reg { - offset: $offset, - } - } - }; -} - #[macro_export] macro_rules! codegen_make_tap { ($regGroupId:literal, $offset:literal, $back:literal) => { @@ -47,24 +36,6 @@ macro_rules! codegen_invoke_extern { } } -#[macro_export] -macro_rules! codegen_make_val { - ($val:literal) => { - paste::paste! { - Val::new($val) - } - }; -} - -#[macro_export] -macro_rules! codegen_make_val_ext { - ($($val:literal),*) => { - paste::paste! { - ExtVal::new($(Val::new($val),)*) - } - } -} - #[macro_export] macro_rules! codegen_set_field { ($field:ident) => {