1# Copyright (C) 2016-2021 Free Software Foundation, Inc. 2# 3# This file is part of GCC. 4# 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. 9# 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. 14# 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/>. 18 19################################################################## 20# 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. 24# 25# The Script works as a Filter from STDIN to STDOUT. 26# 27# FORMAT = "Makefile": Generate Makefile Snipet that sets some 28# MULTILIB_* Variables as needed. 29# 30################################################################## 31 32BEGIN { 33 FS ="[(, \t)]+" 34 comment = 1 35 n_cores = 0 36 n_reuse = 0 37} 38 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) 47 { 48 if (FORMAT == "Makefile") 49 { 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 "" 55 } 56 } 57 58 comment = 2; 59 60 print 61} 62 63/^$/ { 64 # The first empty line stops copy-pasting the GPL comments 65 # from this file to the generated file. 66 67 comment = 0 68} 69 70 71/^ARC_CPU/ { 72 name = $2 73 # gsub ("\"", "", name) 74 75 if ($4 != "0") 76 { 77 arch = $3 78 if (arch == "6xx") 79 arch = 601 80 81 n = split ($4, cpu_flg, "|") 82 83 line = "mcpu." arch 84 for (i = 1; i <= n; i++) 85 { 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 136 { 137 print "Don't know the flag " cpu_flg[i] > "/dev/stderr" 138 exit 1 139 } 140 } 141 line = "mcpu." name "=" line 142 reuse[n_reuse] = line 143 n_reuse++ 144 } 145 146 core = name 147 cores[n_cores] = core 148 n_cores++ 149} 150 151################################################################## 152# 153# We gathered all the Information, now build/output the following: 154# 155# awk Variable target Variable FORMAT 156# ----------------------------------------------------------- 157# m_options <-> MULTILIB_OPTIONS Makefile 158# m_dirnames <-> MULTILIB_DIRNAMES " 159# 160################################################################## 161 162END { 163 m_options = "\nMULTILIB_OPTIONS = " 164 m_dirnames = "\nMULTILIB_DIRNAMES =" 165 m_reuse = "\nMULTILIB_REUSE =" 166 167 sep = "" 168 for (c = 0; c < n_cores; c++) 169 { 170 m_options = m_options sep "mcpu=" cores[c] 171 m_dirnames = m_dirnames " " cores[c] 172 sep = "/" 173 } 174 175 sep = "" 176 for (c = 0; c < n_reuse; c++) 177 { 178 m_reuse = m_reuse sep reuse[c] 179 sep = "\nMULTILIB_REUSE +=" 180 } 181 ############################################################ 182 # Output that Stuff 183 ############################################################ 184 185 if (FORMAT == "Makefile") 186 { 187 # Intended Target: ./gcc/config/arc/t-multilib 188 189 print m_options 190 print m_dirnames 191 192 ############################################################ 193 # Legacy Aliases 194 ############################################################ 195 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" 204 } 205} 206