1#!/bin/sh
2# Generate mips-tables.opt from the list of CPUs in mips-cpus.def.
3# Copyright (C) 2011-2015 Free Software Foundation, Inc.
4#
5# This file is part of GCC.
6#
7# GCC is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 3, or (at your option)
10# any later version.
11#
12# GCC is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GCC; see the file COPYING3.  If not see
19# <http://www.gnu.org/licenses/>.
20
21cat <<EOF
22; -*- buffer-read-only: t -*-
23; Generated automatically by genopt.sh from mips-cpus.def.
24
25; Copyright (C) 2011-2015 Free Software Foundation, Inc.
26;
27; This file is part of GCC.
28;
29; GCC is free software; you can redistribute it and/or modify it under
30; the terms of the GNU General Public License as published by the Free
31; Software Foundation; either version 3, or (at your option) any later
32; version.
33;
34; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
35; WARRANTY; without even the implied warranty of MERCHANTABILITY or
36; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
37; for more details.
38;
39; You should have received a copy of the GNU General Public License
40; along with GCC; see the file COPYING3.  If not see
41; <http://www.gnu.org/licenses/>.
42
43Enum
44Name(mips_arch_opt_value) Type(int)
45Known MIPS CPUs (for use with the -march= and -mtune= options):
46
47Enum
48Name(mips_mips_opt_value) Type(int)
49Known MIPS ISA levels (for use with the -mips option):
50
51EnumValue
52Enum(mips_arch_opt_value) String(from-abi) Value(MIPS_ARCH_OPTION_FROM_ABI)
53
54EnumValue
55Enum(mips_arch_opt_value) String(native) Value(MIPS_ARCH_OPTION_NATIVE) DriverOnly
56
57EOF
58
59awk -F'[(, 	]+' '
60BEGIN {
61    value = 0
62}
63
64# Write an entry for a single string accepted as a -march= argument.
65
66function write_one_arch_value(name, value, flags)
67{
68    print "EnumValue"
69    print "Enum(mips_arch_opt_value) String(" name ") Value(" value ")" flags
70    print ""
71    if (name ~ "^mips") {
72	sub("^mips", "", name)
73	print "EnumValue"
74	print "Enum(mips_mips_opt_value) String(" name ") Value(" value ")"
75	print ""
76    }
77}
78
79# The logic for matching CPU name variants should be the same as in GAS.
80
81# Write an entry for a single string accepted as a -march= argument,
82# plus any variant with a final "000" replaced by "k".
83
84function write_arch_value_maybe_k(name, value, flags)
85{
86    write_one_arch_value(name, value, flags)
87    if (name ~ "000$") {
88	sub("000$", "k", name)
89	write_one_arch_value(name, value, "")
90    }
91}
92
93# Write all the entries for a -march= argument.  In addition to
94# replacement of a final "000" with "k", an argument starting with
95# "vr", "rm" or "r" followed by a number, or just a plain number,
96# matches a plain number or "r" followed by a plain number.
97
98function write_all_arch_values(name, value)
99{
100    write_arch_value_maybe_k(name, value, " Canonical")
101    cname = name
102    if (cname ~ "^vr") {
103	sub("^vr", "", cname)
104    } else if (cname ~ "^rm") {
105	sub("^rm", "", cname)
106    } else if (cname ~ "^r") {
107	sub("^r", "", cname)
108    }
109    if (cname ~ "^[0-9]") {
110	if (cname != name)
111	    write_arch_value_maybe_k(cname, value, "")
112	rname = "r" cname
113	if (rname != name)
114	    write_arch_value_maybe_k(rname, value, "")
115    }
116}
117
118/^MIPS_CPU/ {
119    name = $2
120    gsub("\"", "", name)
121    write_all_arch_values(name, value)
122    value++
123}' $1/mips-cpus.def
124