Tested with nawk, mawk, and gawk.
gcc/ChangeLog:
* config/loongarch/genopts/gen-evolution.awk: remove
usage of "asort".
* config/loongarch/genopts/genstr.sh: replace sed with awk.
---
.../loongarch/genopts/gen-evolution.awk | 12 +++-
gcc/config/loongarch/genopts/genstr.sh | 57 ++++++++++---------
2 files changed, 40 insertions(+), 29 deletions(-)
diff --git a/gcc/config/loongarch/genopts/gen-evolution.awk
b/gcc/config/loongarch/genopts/gen-evolution.awk
index 142b658fe7a..507063bd50d 100644
--- a/gcc/config/loongarch/genopts/gen-evolution.awk
+++ b/gcc/config/loongarch/genopts/gen-evolution.awk
@@ -101,10 +101,18 @@ function gen_cpucfg_useful_idx()
idx_list[j++] = i+0
delete idx_bucket
- asort (idx_list)
+ for (i = 1; i < j; i++) {
+ t = i
+ for (k = i + 1; k < j; k++)
+ t = idx_list[k] < idx_list[t] ? k : t
+
+ k = idx_list[t]
+ idx_list[t] = idx_list[i]
+ idx_list[i] = k
+ }
print "static constexpr int cpucfg_useful_idx[] = {"
- for (i in idx_list)
+ for (i = 1; i < j; i++)
printf(" %d,\n", idx_list[i])
print "};"
diff --git a/gcc/config/loongarch/genopts/genstr.sh b/gcc/config/loongarch/genopts/genstr.sh
index 16c2edd4fa8..97517da40f4 100755
--- a/gcc/config/loongarch/genopts/genstr.sh
+++ b/gcc/config/loongarch/genopts/genstr.sh
@@ -51,18 +51,18 @@ along with GCC; see the file COPYING3. If not see
#define LOONGARCH_STR_H
EOF
- sed -e '/^$/n' -e 's@#.*$@@' -e '/^$/d' \
- -e 's@^\([^ \t]\+\)[ \t]*\([^ \t]*\)@#define \1 "\2"@' \
- loongarch-strings
+ awk '/^#.*$/ { next } /^$/ { print; next }
+ { printf ("#define %s \"%s\"\n", $1, $2) }' \
+ loongarch-strings
echo
- # Generate the strings from isa-evolution.in.
- awk '{
- a=$3
- gsub(/-/, "_", a)
- print("#define OPTSTR_"toupper(a)"\t\""$3"\"")
- }' isa-evolution.in
+ # Generate the strings from isa-evolution.in.
+ awk '{
+ a=$3
+ gsub(/-/, "_", a)
+ print("#define OPTSTR_"toupper(a)"\t\""$3"\"")
+ }' isa-evolution.in
echo
echo "#endif /* LOONGARCH_STR_H */"
@@ -73,18 +73,8 @@ EOF
# according to the key-value pairs defined in loongarch-strings.
gen_options() {
-
- sed -e '/^$/n' -e 's@#.*$@@' -e '/^$/d' \
- -e 's@^\([^ \t]\+\)[ \t]*\([^ \t]*\)@\1="\2"@' \
- loongarch-strings | { \
-
- # read the definitions
- while read -r line; do
- eval "$line"
- done
-
- # print a header
- cat << EOF
+ # print a header
+ cat << EOF
; Generated by "genstr" from the template "loongarch.opt.in"
; and definitions from "loongarch-strings" and "isa-evolution.in".
;
@@ -95,12 +85,25 @@ gen_options() {
;
EOF
- # make the substitutions
- sed -e 's@"@\\"@g' -e 's/@@\([^@]\+\)@@/${\1}/g' loongarch.opt.in | \
- while read -r line; do
- eval "echo \"$line\""
- done
- }
+ # Generate loongarch.opt.
+ awk 'BEGIN {
+ delete strtab
+ while (getline < "loongarch-strings" > 0) {
+ if ($0 ~ /^#.*$/ || $0 ~ /^$/) continue
+ strtab[$1] = $2
+ }
+ }
+ {
+ n = split($0, tmp, "@@")
+ for (i = 2; i <= n; i += 2)
+ tmp[i] = strtab[tmp[i]]
+
+ for (i = 1; i <= n; i++)
+ printf("%s", tmp[i])
+ printf ("\n")
+
+ }' loongarch.opt.in
+
# Generate the strings from isa-evolution.in.
awk '{