| 1 |
#!/bin/sh |
| 2 |
# A simple script that generates loongarch-str.h and loongarch.opt |
| 3 |
# from genopt/loongarch-optstr. |
| 4 |
# |
| 5 |
# Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 6 |
# |
| 7 |
# This file is part of GCC. |
| 8 |
# |
| 9 |
# GCC is free software; you can redistribute it and/or modify it under |
| 10 |
# the terms of the GNU General Public License as published by the Free |
| 11 |
# Software Foundation; either version 3, or (at your option) any later |
| 12 |
# version. |
| 13 |
# |
| 14 |
# GCC is distributed in the hope that it will be useful, but WITHOUT |
| 15 |
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 16 |
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public |
| 17 |
# License for more details. |
| 18 |
# |
| 19 |
# You should have received a copy of the GNU General Public License |
| 20 |
# along with GCC; see the file COPYING3. If not see |
| 21 |
# <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
cd "$(dirname "$0")" |
| 24 |
|
| 25 |
# Generate a header containing definitions from the string table. |
| 26 |
gen_defines() { |
| 27 |
cat <<EOF |
| 28 |
/* Generated automatically by "genstr" from "loongarch-strings" and |
| 29 |
"isa-evolution.in". Please do not edit this file directly. |
| 30 |
|
| 31 |
Copyright (C) 2021-2025 Free Software Foundation, Inc. |
| 32 |
Contributed by Loongson Ltd. |
| 33 |
|
| 34 |
This file is part of GCC. |
| 35 |
|
| 36 |
GCC is free software; you can redistribute it and/or modify |
| 37 |
it under the terms of the GNU General Public License as published by |
| 38 |
the Free Software Foundation; either version 3, or (at your option) |
| 39 |
any later version. |
| 40 |
|
| 41 |
GCC is distributed in the hope that it will be useful, |
| 42 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 43 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 44 |
GNU General Public License for more details. |
| 45 |
|
| 46 |
You should have received a copy of the GNU General Public License |
| 47 |
along with GCC; see the file COPYING3. If not see |
| 48 |
<http://www.gnu.org/licenses/>. */ |
| 49 |
|
| 50 |
#ifndef LOONGARCH_STR_H |
| 51 |
#define LOONGARCH_STR_H |
| 52 |
EOF |
| 53 |
|
| 54 |
awk '/^#.*$/ { next } /^$/ { print; next } |
| 55 |
{ printf ("#define %s \"%s\"\n", $1, $2) }' \ |
| 56 |
loongarch-strings |
| 57 |
|
| 58 |
echo |
| 59 |
|
| 60 |
# Generate the strings from isa-evolution.in. |
| 61 |
awk '{ |
| 62 |
a=$3 |
| 63 |
gsub(/-/, "_", a) |
| 64 |
print("#define OPTSTR_"toupper(a)"\t\""$3"\"") |
| 65 |
}' isa-evolution.in |
| 66 |
|
| 67 |
echo |
| 68 |
echo "#endif /* LOONGARCH_STR_H */" |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
# Substitute all "@@<KEY>@@" to "<VALUE>" in loongarch.opt.in |
| 73 |
# according to the key-value pairs defined in loongarch-strings. |
| 74 |
|
| 75 |
gen_options() { |
| 76 |
# print a header |
| 77 |
cat << EOF |
| 78 |
; Generated by "genstr" from the template "loongarch.opt.in" |
| 79 |
; and definitions from "loongarch-strings" and "isa-evolution.in". |
| 80 |
; |
| 81 |
; Please do not edit this file directly. |
| 82 |
; It will be automatically updated during a gcc build |
| 83 |
; if you change "loongarch.opt.in", "loongarch-strings", or |
| 84 |
; "isa-evolution.in". |
| 85 |
; |
| 86 |
EOF |
| 87 |
|
| 88 |
# Generate loongarch.opt. |
| 89 |
awk 'BEGIN { |
| 90 |
delete strtab |
| 91 |
while (getline < "loongarch-strings" > 0) { |
| 92 |
if ($0 ~ /^#.*$/ || $0 ~ /^$/) continue |
| 93 |
strtab[$1] = $2 |
| 94 |
} |
| 95 |
} |
| 96 |
{ |
| 97 |
n = split($0, tmp, "@@") |
| 98 |
for (i = 2; i <= n; i += 2) |
| 99 |
tmp[i] = strtab[tmp[i]] |
| 100 |
|
| 101 |
for (i = 1; i <= n; i++) |
| 102 |
printf("%s", tmp[i]) |
| 103 |
printf ("\n") |
| 104 |
|
| 105 |
}' loongarch.opt.in |
| 106 |
|
| 107 |
|
| 108 |
# Generate the strings from isa-evolution.in. |
| 109 |
awk '{ |
| 110 |
print("") |
| 111 |
print("m"$3) |
| 112 |
gsub(/-/, "_", $3) |
| 113 |
print("Target Mask(ISA_"toupper($3)") Var(la_isa_evolution)") |
| 114 |
$1=""; $2=""; $3=""; $4="" |
| 115 |
sub(/^ */, "", $0) |
| 116 |
print($0) |
| 117 |
}' isa-evolution.in |
| 118 |
} |
| 119 |
|
| 120 |
main() { |
| 121 |
case "$1" in |
| 122 |
evolution_h) |
| 123 |
awk -v header_p=1 -f gen-evolution.awk isa-evolution.in |
| 124 |
;; |
| 125 |
evolution_c) |
| 126 |
awk -v header_p=0 -f gen-evolution.awk isa-evolution.in |
| 127 |
;; |
| 128 |
header) |
| 129 |
gen_defines |
| 130 |
;; |
| 131 |
opt) |
| 132 |
gen_options |
| 133 |
;; |
| 134 |
*) |
| 135 |
echo "Unknown Command: \"$1\". Available: header, opt, evolution_h, evolution_c" |
| 136 |
exit 1 |
| 137 |
;; |
| 138 |
esac |
| 139 |
} |
| 140 |
|
| 141 |
main "$@" |