/cp
[official-gcc.git] / gcc / config / arc / genmultilib.awk
blob785007e7efa995b890ec320fde38bcf16d50be8b
1 # Copyright (C) 2016-2018 Free Software Foundation, Inc.
3 # This file is part of GCC.
5 # GCC is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 3, or (at your option) any later
8 # version.
10 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with GCC; see the file COPYING3. If not see
17 # <http://www.gnu.org/licenses/>.
19 ##################################################################
21 # This file is using AVR's genmultilib.awk idea.
22 # Transform CPU Information from arc-cpu.def to a
23 # Representation that is understood by GCC's multilib Machinery.
25 # The Script works as a Filter from STDIN to STDOUT.
27 # FORMAT = "Makefile": Generate Makefile Snipet that sets some
28 # MULTILIB_* Variables as needed.
30 ##################################################################
32 BEGIN {
33 FS ="[(, \t)]+"
34 comment = 1
35 n_cores = 0
36 n_reuse = 0
39 ##################################################################
40 # Add some Comments to the generated Files and copy-paste
41 # Copyright Notice from above.
42 ##################################################################
43 /^#/ {
44 if (!comment)
45 next
46 else if (comment == 1)
48 if (FORMAT == "Makefile")
50 print "# Auto-generated Makefile Snip"
51 print "# Generated by : ./gcc/config/arc/genmultilib.awk"
52 print "# Generated from : ./gcc/config/arc/arc-cpu.def"
53 print "# Used by : tmake_file from Makefile and genmultilib"
54 print ""
58 comment = 2;
60 print
63 /^$/ {
64 # The first empty line stops copy-pasting the GPL comments
65 # from this file to the generated file.
67 comment = 0
71 /^ARC_CPU/ {
72 name = $2
73 # gsub ("\"", "", name)
75 if ($4 != "0")
77 arch = $3
78 if (arch == "6xx")
79 arch = 601
81 n = split ($4, cpu_flg, "|")
83 line = "mcpu." arch
84 for (i = 1; i <= n; i++)
86 if (cpu_flg[i] == "FL_MPYOPT_0")
87 line = line "/mmpy-option.0"
88 else if (cpu_flg[i] == "FL_MPYOPT_1")
89 line = line "/mmpy-option.1"
90 else if (cpu_flg[i] == "FL_MPYOPT_2")
91 line = line "/mmpy-option.2"
92 else if (cpu_flg[i] == "FL_MPYOPT_3")
93 line = line "/mmpy-option.3"
94 else if (cpu_flg[i] == "FL_MPYOPT_4")
95 line = line "/mmpy-option.4"
96 else if (cpu_flg[i] == "FL_MPYOPT_5")
97 line = line "/mmpy-option.5"
98 else if (cpu_flg[i] == "FL_MPYOPT_6")
99 line = line "/mmpy-option.6"
100 else if (cpu_flg[i] == "FL_MPYOPT_7")
101 line = line "/mmpy-option.7"
102 else if (cpu_flg[i] == "FL_MPYOPT_8")
103 line = line "/mmpy-option.8"
104 else if (cpu_flg[i] == "FL_MPYOPT_9")
105 line = line "/mmpy-option.9"
106 else if (cpu_flg[i] == "FL_CD")
107 line = line "/mcode-density"
108 else if (cpu_flg[i] == "FL_BS")
109 line = line "/mbarrel-shifter"
110 else if (cpu_flg[i] == "FL_DIVREM")
111 line = line "/mdiv-rem"
112 else if (cpu_flg[i] == "FL_NORM" \
113 || cpu_flg[i] == "FL_SWAP")
114 line = line "/mnorm"
115 else if (cpu_flg[i] == "FL_FPU_FPUS")
116 line = line "/mfpu.fpus"
117 else if (cpu_flg[i] == "FL_FPU_FPUDA")
118 line = line "/mfpu.fpuda"
119 else if (cpu_flg[i] == "FL_FPU_FPUD_ALL")
120 line = line "/mfpu.fpud_all"
121 else if (cpu_flg[i] == "FL_LL64")
122 line = line "/mll64"
123 else if (cpu_flg[i] == "FL_MUL64")
124 line = line "/mmul64"
125 else if (cpu_flg[i] == "FL_MUL32x16")
126 line = line "/mmul32x16"
127 else if (cpu_flg[i] == "FL_FPX_QUARK")
128 line = line "/quark"
129 else if (cpu_flg[i] == "FL_SPFP")
130 line = line "/spfp"
131 else if (cpu_flg[i] == "FL_DPFP")
132 line = line "/dpfp"
133 else if (cpu_flg[i] == "FL_RF16")
134 line = line "/mrf16"
135 else
137 print "Don't know the flag " cpu_flg[i] > "/dev/stderr"
138 exit 1
141 line = "mcpu." name "=" line
142 reuse[n_reuse] = line
143 n_reuse++
146 core = name
147 cores[n_cores] = core
148 n_cores++
151 ##################################################################
153 # We gathered all the Information, now build/output the following:
155 # awk Variable target Variable FORMAT
156 # -----------------------------------------------------------
157 # m_options <-> MULTILIB_OPTIONS Makefile
158 # m_dirnames <-> MULTILIB_DIRNAMES "
160 ##################################################################
162 END {
163 m_options = "\nMULTILIB_OPTIONS = "
164 m_dirnames = "\nMULTILIB_DIRNAMES ="
165 m_reuse = "\nMULTILIB_REUSE ="
167 sep = ""
168 for (c = 0; c < n_cores; c++)
170 m_options = m_options sep "mcpu=" cores[c]
171 m_dirnames = m_dirnames " " cores[c]
172 sep = "/"
175 sep = ""
176 for (c = 0; c < n_reuse; c++)
178 m_reuse = m_reuse sep reuse[c]
179 sep = "\nMULTILIB_REUSE +="
181 ############################################################
182 # Output that Stuff
183 ############################################################
185 if (FORMAT == "Makefile")
187 # Intended Target: ./gcc/config/arc/t-multilib
189 print m_options
190 print m_dirnames
192 ############################################################
193 # Legacy Aliases
194 ############################################################
196 print ""
197 print "# Aliases:"
198 print "MULTILIB_MATCHES = mcpu?arc600=mcpu?ARC600"
199 print "MULTILIB_MATCHES += mcpu?arc600=mARC600"
200 print "MULTILIB_MATCHES += mcpu?arc600=mA6"
201 print "MULTILIB_MATCHES += mcpu?arc601=mcpu?ARC601"
202 print "MULTILIB_MATCHES += mcpu?arc700=mA7"
203 print "MULTILIB_MATCHES += mcpu?arc700=mARC700"