@@ -386,6 +386,13 @@ struct BlifAllocCallback : public blifparse::Callback {
386
386
parse_error (lineno_, " .param" , " Supported only in extended BLIF format" );
387
387
}
388
388
389
+ // Validate the parameter value
390
+ bool is_valid = is_string_param (value) || is_binary_param (value) || is_real_param (value);
391
+
392
+ if (!is_valid) {
393
+ parse_error (lineno_, " .param" , " Incorrect parameter value specification" );
394
+ }
395
+
389
396
curr_model ().set_block_param (curr_block (), name, value);
390
397
}
391
398
@@ -666,6 +673,70 @@ vtr::LogicValue to_vtr_logic_value(blifparse::LogicValue val) {
666
673
return new_val;
667
674
}
668
675
676
+ bool is_string_param (const std::string& param) {
677
+ /* Empty param is considered a string */
678
+ if (param.empty ()) {
679
+ return true ;
680
+ }
681
+
682
+ /* There have to be at least 2 characters (the quotes) */
683
+ if (param.length () < 2 ) {
684
+ return false ;
685
+ }
686
+
687
+ /* The first and the last characters must be quotes */
688
+ size_t len = param.length ();
689
+ if (param[0 ] != ' "' || param[len - 1 ] != ' "' ) {
690
+ return false ;
691
+ }
692
+
693
+ /* There mustn't be any other quotes except for escaped ones */
694
+ for (size_t i = 1 ; i < (len - 1 ); ++i) {
695
+ if (param[i] == ' "' && param[i - 1 ] != ' \\ ' ) {
696
+ return false ;
697
+ }
698
+ }
699
+
700
+ /* This is a string param */
701
+ return true ;
702
+ }
703
+
704
+ bool is_binary_param (const std::string& param) {
705
+ /* Must be non-empty */
706
+ if (param.empty ()) {
707
+ return false ;
708
+ }
709
+
710
+ /* The string must contain only '0' and '1' */
711
+ for (size_t i = 0 ; i < param.length (); ++i) {
712
+ if (param[i] != ' 0' && param[i] != ' 1' ) {
713
+ return false ;
714
+ }
715
+ }
716
+
717
+ /* This is a binary word param */
718
+ return true ;
719
+ }
720
+
721
+ bool is_real_param (const std::string& param) {
722
+ const std::string chars = " 012345678." ;
723
+
724
+ /* Must be non-empty */
725
+ if (param.empty ()) {
726
+ return false ;
727
+ }
728
+
729
+ /* The string mustn't contain any other chars that the expected ones */
730
+ for (size_t i = 0 ; i < param.length (); ++i) {
731
+ if (chars.find (param[i]) == std::string::npos) {
732
+ return false ;
733
+ }
734
+ }
735
+
736
+ /* This is a real number param */
737
+ return true ;
738
+ }
739
+
669
740
AtomNetlist read_blif (e_circuit_format circuit_format,
670
741
const char * blif_file,
671
742
const t_model* user_models,
0 commit comments