aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/loongarch/genopts/genstr.sh
blob: 5b3bf7fdf0c01a01ce103aa45f785100f2eef4fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/sh
# A simple script that generates loongarch-str.h and loongarch.opt
# from genopt/loongarch-optstr.
#
# Copyright (C) 2021-2024 Free Software Foundation, Inc.
#
# This file is part of GCC.
#
# GCC is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 3, or (at your option) any later
# version.
#
# GCC is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

cd "$(dirname "$0")"

# Generate a header containing definitions from the string table.
gen_defines() {
    cat <<EOF
/* Generated automatically by "genstr" from "loongarch-strings" and
   "isa-evolution.in".  Please do not edit this file directly.

   Copyright (C) 2021-2024 Free Software Foundation, Inc.
   Contributed by Loongson Ltd.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#ifndef LOONGARCH_STR_H
#define LOONGARCH_STR_H
EOF

    sed -e '/^$/n' -e 's@#.*$@@' -e '/^$/d' \
	-e 's@^\([^ \t]\+\)[ \t]*\([^ \t]*\)@#define \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

    echo
    echo "#endif /* LOONGARCH_STR_H */"
}


# Substitute all "@@<KEY>@@" to "<VALUE>" in loongarch.opt.in
# 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
; Generated by "genstr" from the template "loongarch.opt.in"
; and definitions from "loongarch-strings" and "isa-evolution.in".
;
; Please do not edit this file directly.
; It will be automatically updated during a gcc build
; if you change "loongarch.opt.in", "loongarch-strings", or
; "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 the strings from isa-evolution.in.
    awk '{
      print("")
      print("m"$3)
      gsub(/-/, "_", $3)
      print("Target Mask(ISA_"toupper($3)") Var(la_isa_evolution)")
      $1=""; $2=""; $3=""; $4=""
      sub(/^ */, "", $0)
      print($0)
    }' isa-evolution.in
}

main() {
    case "$1" in
	evolution_h)
            awk -v header_p=1 -f gen-evolution.awk isa-evolution.in
            ;;
	evolution_c)
            awk -v header_p=0 -f gen-evolution.awk isa-evolution.in
            ;;
	header)
            gen_defines
            ;;
	opt)
            gen_options
            ;;
	*)
            echo "Unknown Command: \"$1\". Available: header, opt, evolution_h, evolution_c"
            exit 1
            ;;
    esac
}

main "$@"