]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
LoongArch: Fix awk / sed usage for compatibility
authorYang Yujie <yangyujie@loongson.cn>
Mon, 7 Apr 2025 02:31:46 +0000 (10:31 +0800)
committerLulu Cheng <chenglulu@loongson.cn>
Wed, 9 Apr 2025 01:09:40 +0000 (09:09 +0800)
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.

gcc/config/loongarch/genopts/gen-evolution.awk
gcc/config/loongarch/genopts/genstr.sh

index 142b658fe7a35c0bbf141e3f53c80c95474bc82a..507063bd50dfc84a67329303477fabec97de4bf6 100644 (file)
@@ -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 "};"
 
index 16c2edd4fa8a161dd0584d278936815e4384a2f2..97517da40f4945ce9d38ba900de12abffa3deca1 100755 (executable)
@@ -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 '{