@@ -704,7 +704,7 @@ static void load_pin_loc(pugi::xml_node Locations,
704
704
for (int width = 0 ; width < type->width ; ++width) {
705
705
for (int height = 0 ; height < type->height ; ++height) {
706
706
for (e_side side : TOTAL_2D_SIDES) {
707
- for (auto token : pin_locs->assignments [sub_tile_index][width][height][layer][side]) {
707
+ for (const std::string& token : pin_locs->assignments [sub_tile_index][width][height][layer][side]) {
708
708
auto pin_range = process_pin_string<t_sub_tile*>(Locations,
709
709
&sub_tile,
710
710
token.c_str (),
@@ -763,39 +763,35 @@ static std::pair<int, int> process_instance_string(pugi::xml_node Locations,
763
763
t_sub_tile& sub_tile,
764
764
const char * pin_loc_string,
765
765
const pugiutil::loc_data& loc_data) {
766
- int num_tokens;
767
- t_token* tokens = get_tokens_from_string (pin_loc_string, &num_tokens);
766
+ Tokens tokens (pin_loc_string);
768
767
769
768
int token_index = 0 ;
770
769
t_token token = tokens[token_index];
771
770
772
- if (token.type != TOKEN_STRING || std::string (token.data ) != sub_tile.name ) {
771
+ if (token.type != e_token_type::STRING || std::string (token.data ) != sub_tile.name ) {
773
772
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
774
773
vtr::string_fmt (" Wrong physical type name of the port: %s\n " , pin_loc_string).c_str ());
775
774
}
776
775
777
776
token_index++;
778
- token = tokens[token_index];
779
777
780
778
int first_inst = 0 ;
781
779
int last_inst = sub_tile.capacity .total () - 1 ;
782
780
783
781
// If there is a dot, such as io.input[0:3], it indicates the full range of the capacity, the default value should be returned
784
- if (token.type == TOKEN_DOT) {
785
- free_tokens (tokens, num_tokens);
782
+ if (token.type == e_token_type::DOT) {
786
783
return std::make_pair (first_inst, last_inst);
787
784
}
788
785
789
786
// If the string contains index for capacity range, e.g., io[3:3].in[0:5], we skip the capacity range here.
790
- if (token.type != TOKEN_OPEN_SQUARE_BRACKET ) {
787
+ if (token.type != e_token_type::OPEN_SQUARE_BRACKET ) {
791
788
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
792
789
vtr::string_fmt (" No open square bracket present: %s\n " , pin_loc_string).c_str ());
793
790
}
794
791
795
792
token_index++;
796
- token = tokens[token_index];
797
793
798
- if (token .type != TOKEN_INT ) {
794
+ if (tokens[token_index] .type != e_token_type::INT ) {
799
795
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
800
796
vtr::string_fmt (" No integer to indicate least significant instance index: %s\n " , pin_loc_string).c_str ());
801
797
}
@@ -806,27 +802,26 @@ static std::pair<int, int> process_instance_string(pugi::xml_node Locations,
806
802
token = tokens[token_index];
807
803
808
804
// Single pin is specified
809
- if (token.type != TOKEN_COLON ) {
810
- if (token.type != TOKEN_CLOSE_SQUARE_BRACKET ) {
805
+ if (token.type != e_token_type::COLON ) {
806
+ if (token.type != e_token_type::CLOSE_SQUARE_BRACKET ) {
811
807
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
812
808
vtr::string_fmt (" No closing bracket: %s\n " , pin_loc_string).c_str ());
813
809
}
814
810
815
811
token_index++;
816
812
817
- if (token_index != num_tokens ) {
813
+ if (token_index != tokens. size () ) {
818
814
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
819
815
vtr::string_fmt (" instance of pin location should be completed, but more tokens are present: %s\n " , pin_loc_string).c_str ());
820
816
}
821
817
822
- free_tokens (tokens, num_tokens);
823
818
return std::make_pair (first_inst, first_inst);
824
819
}
825
820
826
821
token_index++;
827
822
token = tokens[token_index];
828
823
829
- if (token.type != TOKEN_INT ) {
824
+ if (token.type != e_token_type::INT ) {
830
825
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
831
826
vtr::string_fmt (" No integer to indicate most significant instance index: %s\n " , pin_loc_string).c_str ());
832
827
}
@@ -836,7 +831,7 @@ static std::pair<int, int> process_instance_string(pugi::xml_node Locations,
836
831
token_index++;
837
832
token = tokens[token_index];
838
833
839
- if (token.type != TOKEN_CLOSE_SQUARE_BRACKET ) {
834
+ if (token.type != e_token_type::CLOSE_SQUARE_BRACKET ) {
840
835
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
841
836
vtr::string_fmt (" No closed square bracket: %s\n " , pin_loc_string).c_str ());
842
837
}
@@ -845,7 +840,6 @@ static std::pair<int, int> process_instance_string(pugi::xml_node Locations,
845
840
std::swap (first_inst, last_inst);
846
841
}
847
842
848
- free_tokens (tokens, num_tokens);
849
843
return std::make_pair (first_inst, last_inst);
850
844
}
851
845
@@ -854,13 +848,11 @@ static std::pair<int, int> process_pin_string(pugi::xml_node Locations,
854
848
T type,
855
849
const char * pin_loc_string,
856
850
const pugiutil::loc_data& loc_data) {
857
- int num_tokens;
858
- t_token* tokens = get_tokens_from_string (pin_loc_string, &num_tokens);
851
+ Tokens tokens (pin_loc_string);
859
852
860
- int token_index = 0 ;
861
- auto token = tokens[token_index];
853
+ size_t token_index = 0 ;
862
854
863
- if (token .type != TOKEN_STRING || token .data != type->name ) {
855
+ if (tokens[token_index] .type != e_token_type::STRING || tokens[token_index] .data != type->name ) {
864
856
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
865
857
vtr::string_fmt (" Wrong physical type name of the port: %s\n " , pin_loc_string).c_str ());
866
858
}
@@ -928,50 +920,46 @@ static std::pair<int, int> process_pin_string(pugi::xml_node Locations,
928
920
vtr::string_fmt (" No integer to indicate least significant pin index: %s\n " , pin_loc_string).c_str ());
929
921
}
930
922
931
- int first_pin = vtr::atoi (token .data );
923
+ int first_pin = vtr::atoi (tokens[token_index] .data );
932
924
933
925
token_index++;
934
- token = tokens[token_index];
935
926
936
927
// Single pin is specified
937
- if (token .type != TOKEN_COLON ) {
938
- if (token .type != TOKEN_CLOSE_SQUARE_BRACKET ) {
928
+ if (tokens[token_index] .type != e_token_type::COLON ) {
929
+ if (tokens[token_index] .type != e_token_type::CLOSE_SQUARE_BRACKET ) {
939
930
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
940
931
vtr::string_fmt (" No closing bracket: %s\n " , pin_loc_string).c_str ());
941
932
}
942
933
943
934
token_index++;
944
935
945
- if (token_index != num_tokens ) {
936
+ if (token_index != tokens. size () ) {
946
937
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
947
938
vtr::string_fmt (" pin location should be completed, but more tokens are present: %s\n " , pin_loc_string).c_str ());
948
939
}
949
940
950
- free_tokens (tokens, num_tokens);
951
941
return std::make_pair (abs_first_pin_idx + first_pin, abs_first_pin_idx + first_pin + 1 );
952
942
}
953
943
954
944
token_index++;
955
- token = tokens[token_index];
956
945
957
- if (token .type != TOKEN_INT ) {
946
+ if (tokens[token_index] .type != e_token_type::INT ) {
958
947
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
959
948
vtr::string_fmt (" No integer to indicate most significant pin index: %s\n " , pin_loc_string).c_str ());
960
949
}
961
950
962
- int last_pin = vtr::atoi (token .data );
951
+ int last_pin = vtr::atoi (tokens[token_index] .data );
963
952
964
953
token_index++;
965
- token = tokens[token_index];
966
954
967
- if (token .type != TOKEN_CLOSE_SQUARE_BRACKET ) {
955
+ if (tokens[token_index] .type != e_token_type::CLOSE_SQUARE_BRACKET ) {
968
956
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
969
957
vtr::string_fmt (" No closed square bracket: %s\n " , pin_loc_string).c_str ());
970
958
}
971
959
972
960
token_index++;
973
961
974
- if (token_index != num_tokens ) {
962
+ if (token_index != tokens. size () ) {
975
963
archfpga_throw (loc_data.filename_c_str (), loc_data.line (Locations),
976
964
vtr::string_fmt (" pin location should be completed, but more tokens are present: %s\n " , pin_loc_string).c_str ());
977
965
}
@@ -980,7 +968,6 @@ static std::pair<int, int> process_pin_string(pugi::xml_node Locations,
980
968
std::swap (first_pin, last_pin);
981
969
}
982
970
983
- free_tokens (tokens, num_tokens);
984
971
return std::make_pair (abs_first_pin_idx + first_pin, abs_first_pin_idx + last_pin + 1 );
985
972
}
986
973
0 commit comments