From 0fb93a84edca4da3290b0de310485f11f253bb6c Mon Sep 17 00:00:00 2001 From: Stan Lee <135666755+stanminlee@users.noreply.github.com> Date: Thu, 19 Feb 2026 09:54:51 -0800 Subject: [PATCH 1/3] remove validation in parser --- liberty/LibertyReader.cc | 8 -------- 1 file changed, 8 deletions(-) diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index e3bd11c0..10b24988 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -3324,10 +3324,6 @@ LibertyReader::visitShifts(LibertyAttr *attr) LibertyAttrValueIterator value_iter(attr->values()); while (value_iter.hasNext()) { LibertyAttrValue *value = value_iter.next(); - if (!value->isFloat()) { - delete shifts; - libError(1234, attr, "shifts attribute must be a float."); - } float float_value = value->floatValue(); shifts->push_back(float_value); } @@ -3357,10 +3353,6 @@ LibertyReader::visitEdges(LibertyAttr *attr) LibertyAttrValueIterator value_iter(attr->values()); while (value_iter.hasNext()) { LibertyAttrValue *value = value_iter.next(); - if (!value->isFloat()) { - delete edges; - libError(1234, attr, "edges attribute must be a float."); - } float float_value = value->floatValue(); int int_value = static_cast(float_value); edges->push_back(int_value); From e232c3ea00ea76fd0d2ca232f37e35f702c20fa4 Mon Sep 17 00:00:00 2001 From: Stan Lee <135666755+stanminlee@users.noreply.github.com> Date: Thu, 19 Feb 2026 10:06:21 -0800 Subject: [PATCH 2/3] can be float or string --- liberty/LibertyReader.cc | 37 ++++++++++++++++++++++++++++--------- test/generated_clock.lib | 8 ++++++-- test/generated_clock.ok | 2 +- 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index 10b24988..c221f3e2 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -3317,17 +3317,27 @@ LibertyReader::visitShifts(LibertyAttr *attr) { if (generated_clock_) { if (!attr->isComplex()) { - libError(1234, attr, "'shifts' attribute is not a complex attribute."); + libError(1234, attr, "'shifts' attribute must be a complex attribute."); } // Initialize edges sequence FloatSeq *shifts = new FloatSeq; LibertyAttrValueIterator value_iter(attr->values()); while (value_iter.hasNext()) { LibertyAttrValue *value = value_iter.next(); - float float_value = value->floatValue(); - shifts->push_back(float_value); + // Convert string to float if necessary + if (value->isFloat()) { + float float_value = value->floatValue(); + shifts->push_back(float_value); + } + else if (value->isString()) { + const char *string_value = value->stringValue(); + float float_value = strtof(string_value, nullptr); + shifts->push_back(float_value); + } + else { + libError(1234, attr, "shifts attribute must be a float or string."); + } } - // Error checking, only size 3 is supported at the moment if (shifts->size() != 3) { delete shifts; @@ -3346,18 +3356,27 @@ LibertyReader::visitEdges(LibertyAttr *attr) { if (generated_clock_) { if (!attr->isComplex()) { - libError(1234, attr, "'edges' attribute is not a complex attribute."); + libError(1234, attr, "'edges' attribute must be a complex attribute."); } // Initialize edges sequence IntSeq *edges = new IntSeq; LibertyAttrValueIterator value_iter(attr->values()); while (value_iter.hasNext()) { LibertyAttrValue *value = value_iter.next(); - float float_value = value->floatValue(); - int int_value = static_cast(float_value); - edges->push_back(int_value); + // Convert string to float if necessary + if (value->isFloat()) { + float float_value = value->floatValue(); + edges->push_back(float_value); + } + else if (value->isString()) { + const char *string_value = value->stringValue(); + float float_value = strtof(string_value, nullptr); + edges->push_back(float_value); + } + else { + libError(1234, attr, "edges attribute must be a float or string."); + } } - // Error checking, only size 3 is supported at the moment if (edges->size() != 3) { delete edges; diff --git a/test/generated_clock.lib b/test/generated_clock.lib index c9d93ddd..a42490fe 100644 --- a/test/generated_clock.lib +++ b/test/generated_clock.lib @@ -53,8 +53,12 @@ library (generated_clock) { generated_clock (shift) { clock_pin : CLK_OUT ; master_pin : CLK_IN; - edges (1, 3, 5); - shifts (0, 0, 0) + edges("1", \ + 3, \ + "5"); + shifts(0, \ + "0", \ + 0); } timing () { related_pin : CLK_IN; diff --git a/test/generated_clock.ok b/test/generated_clock.ok index 797d6104..d0537705 100644 --- a/test/generated_clock.ok +++ b/test/generated_clock.ok @@ -1,4 +1,4 @@ -Warning: generated_clock.lib line 57, shifts are not supported yet, may cause malformed waveforms. +Warning: generated_clock.lib line 59, shifts are not supported yet, may cause malformed waveforms. Number of clocks: 9 clk period: 10.000000 u_second_hierarchy/clk_gen/CLK_OUT_DIV period: 20.000000 From c68f8cbcb2aa4537b9e06a390e82193d4935c857 Mon Sep 17 00:00:00 2001 From: Stan Lee <135666755+stanminlee@users.noreply.github.com> Date: Fri, 20 Feb 2026 10:32:25 -0800 Subject: [PATCH 3/3] fix --- liberty/LibertyReader.cc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/liberty/LibertyReader.cc b/liberty/LibertyReader.cc index c221f3e2..a17bf61f 100644 --- a/liberty/LibertyReader.cc +++ b/liberty/LibertyReader.cc @@ -3335,6 +3335,7 @@ LibertyReader::visitShifts(LibertyAttr *attr) shifts->push_back(float_value); } else { + delete shifts; libError(1234, attr, "shifts attribute must be a float or string."); } } @@ -3366,14 +3367,17 @@ LibertyReader::visitEdges(LibertyAttr *attr) // Convert string to float if necessary if (value->isFloat()) { float float_value = value->floatValue(); - edges->push_back(float_value); + int int_value = static_cast(float_value); + edges->push_back(int_value); } else if (value->isString()) { const char *string_value = value->stringValue(); float float_value = strtof(string_value, nullptr); - edges->push_back(float_value); + int int_value = static_cast(float_value); + edges->push_back(int_value); } else { + delete edges; libError(1234, attr, "edges attribute must be a float or string."); } }