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 "};"
#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 */"
# 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".
;
;
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 '{