summaryrefslogtreecommitdiff
path: root/gcc/config/mips/genopt.sh
blob: 19228ff66c3a0f8d68a2fb476627233daec527d2 (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
#!/bin/sh
# Generate mips-tables.opt from the list of CPUs in mips-cpus.def.
# Copyright (C) 2011-2021 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/>.

cat <<EOF
; -*- buffer-read-only: t -*-
; Generated automatically by genopt.sh from mips-cpus.def.

; Copyright (C) 2011-2021 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/>.

Enum
Name(mips_arch_opt_value) Type(int)
Known MIPS CPUs (for use with the -march= and -mtune= options):

Enum
Name(mips_mips_opt_value) Type(int)
Known MIPS ISA levels (for use with the -mips option):

EnumValue
Enum(mips_arch_opt_value) String(from-abi) Value(MIPS_ARCH_OPTION_FROM_ABI)

EnumValue
Enum(mips_arch_opt_value) String(native) Value(MIPS_ARCH_OPTION_NATIVE) DriverOnly

EOF

awk -F'[(, 	]+' '
BEGIN {
    value = 0
}

# Write an entry for a single string accepted as a -march= argument.

function write_one_arch_value(name, value, flags)
{
    print "EnumValue"
    print "Enum(mips_arch_opt_value) String(" name ") Value(" value ")" flags
    print ""
    if (name ~ "^mips") {
	sub("^mips", "", name)
	print "EnumValue"
	print "Enum(mips_mips_opt_value) String(" name ") Value(" value ")"
	print ""
    }
}

# The logic for matching CPU name variants should be the same as in GAS.

# Write an entry for a single string accepted as a -march= argument,
# plus any variant with a final "000" replaced by "k".

function write_arch_value_maybe_k(name, value, flags)
{
    write_one_arch_value(name, value, flags)
    if (name ~ "000$") {
	sub("000$", "k", name)
	write_one_arch_value(name, value, "")
    }
}

# Write all the entries for a -march= argument.  In addition to
# replacement of a final "000" with "k", an argument starting with
# "vr", "rm" or "r" followed by a number, or just a plain number,
# matches a plain number or "r" followed by a plain number.

function write_all_arch_values(name, value)
{
    write_arch_value_maybe_k(name, value, " Canonical")
    cname = name
    if (cname ~ "^vr") {
	sub("^vr", "", cname)
    } else if (cname ~ "^rm") {
	sub("^rm", "", cname)
    } else if (cname ~ "^r") {
	sub("^r", "", cname)
    }
    if (cname ~ "^[0-9]") {
	if (cname != name)
	    write_arch_value_maybe_k(cname, value, "")
	rname = "r" cname
	if (rname != name)
	    write_arch_value_maybe_k(rname, value, "")
    }
}

/^MIPS_CPU/ {
    name = $2
    gsub("\"", "", name)
    write_all_arch_values(name, value)
    value++
}' $1/mips-cpus.def