From 61c36671cb2ebc2e69503e3120a93ebff556c3af Mon Sep 17 00:00:00 2001 From: MikePopoloski Date: Fri, 1 Mar 2024 21:46:31 -0500 Subject: [PATCH] Tests and fixes for config param overriding --- source/ast/symbols/ParameterBuilder.cpp | 12 +++-- tests/unittests/ast/ConfigTests.cpp | 63 +++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 5 deletions(-) diff --git a/source/ast/symbols/ParameterBuilder.cpp b/source/ast/symbols/ParameterBuilder.cpp index 5e02c29f0..29d36d5cc 100644 --- a/source/ast/symbols/ParameterBuilder.cpp +++ b/source/ast/symbols/ParameterBuilder.cpp @@ -26,6 +26,13 @@ ParameterBuilder::ParameterBuilder(const Scope& scope, std::string_view definiti void ParameterBuilder::setAssignments(const ParameterValueAssignmentSyntax& syntax, bool isFromConfig) { + // Special case for config param assignments: if the assignment + // syntax list is empty, we set all params back to their defaults. + if (isFromConfig && syntax.parameters.empty()) { + assignments.clear(); + return; + } + // Build up data structures to easily index the parameter assignments. We need to handle // both ordered assignment as well as named assignment, though a specific instance can only // use one method or the other. @@ -103,11 +110,6 @@ void ParameterBuilder::setAssignments(const ParameterValueAssignmentSyntax& synt continue; } - // It's allowed to have no initializer in the assignment; - // it means to just use the default. - if (!arg->expr) - continue; - assignments[param.name] = {arg->expr, isFromConfig}; } diff --git a/tests/unittests/ast/ConfigTests.cpp b/tests/unittests/ast/ConfigTests.cpp index af333ba17..77f1a0a8d 100644 --- a/tests/unittests/ast/ConfigTests.cpp +++ b/tests/unittests/ast/ConfigTests.cpp @@ -557,9 +557,64 @@ config cfg1; instance top use #(.WIDTH(32)); instance top.a1 use #(.W(top.WIDTH)); endconfig + +module top4 (); + parameter S = 16; + adder #(.ID("a1")) a1(); + adder #(.ID("a2")) a2(); + adder #(.ID("a3")) a3(); + adder #(.ID("a4")) a4(); +endmodule + +config cfg2; + localparam S = 24; + design top4; + instance top4.a1 use #(.W(top4.S)); + instance top4.a2 use #(.W(S)); +endconfig + +module top5 (); + parameter WIDTH = 64, DEPTH = 1024, ID = "A1"; + adder #(.ID(ID), .W(WIDTH), .D(DEPTH)) a1(); +endmodule + +config cfg3; + design top5; + instance top5.a1 use #(.W()); +endconfig + +module top6 (); + adder #(.W(64), .D(1024)) a1(); +endmodule + +config cfg4; + design top6; + instance top6.a1 use #(); +endconfig + +module test; + top8 t(); + defparam t.WIDTH = 64; + defparam t.a1.W = 16; +endmodule + +module top8 (); + parameter WIDTH = 32; + adder #(.ID("a1")) a1(); + adder #(.ID("a2"), .W(WIDTH)) a2(); +endmodule + +config cfg6; + design test; + instance test.t use #(.WIDTH(48)); +endconfig )"); CompilationOptions options; options.topModules.emplace("cfg1"); + options.topModules.emplace("cfg2"); + options.topModules.emplace("cfg3"); + options.topModules.emplace("cfg4"); + options.topModules.emplace("cfg6"); Compilation compilation(options); compilation.addSyntaxTree(tree); @@ -572,4 +627,12 @@ endconfig CHECK(getParam("top.a1.W").integer() == 32); CHECK(getParam("top.a1.D").integer() == 512); + CHECK(getParam("top4.a1.W").integer() == 16); + CHECK(getParam("top4.a2.W").integer() == 24); + CHECK(getParam("top5.a1.W").integer() == 8); + CHECK(getParam("top5.a1.D").integer() == 1024); + CHECK(getParam("top6.a1.W").integer() == 8); + CHECK(getParam("top6.a1.D").integer() == 512); + CHECK(getParam("test.t.a1.W").integer() == 16); + CHECK(getParam("test.t.a2.W").integer() == 48); }