summaryrefslogtreecommitdiff
path: root/gcc/config/arc/genmultilib.awk
blob: 785007e7efa995b890ec320fde38bcf16d50be8b (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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# Copyright (C) 2016-2018 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/>.

##################################################################
#
# This file is using AVR's genmultilib.awk idea.
# Transform CPU Information from arc-cpu.def to a
# Representation that is understood by GCC's multilib Machinery.
#
# The Script works as a Filter from STDIN to STDOUT.
#
# FORMAT = "Makefile": Generate Makefile Snipet that sets some
#                      MULTILIB_* Variables as needed.
#
##################################################################

BEGIN {
  FS ="[(, \t)]+"
  comment = 1
  n_cores = 0
  n_reuse = 0
}

##################################################################
# Add some Comments to the generated Files and copy-paste
# Copyright Notice from above.
##################################################################
/^#/ {
  if (!comment)
    next
  else if (comment == 1)
    {
      if (FORMAT == "Makefile")
	{
	  print "# Auto-generated Makefile Snip"
	  print "# Generated by    : ./gcc/config/arc/genmultilib.awk"
	  print "# Generated from  : ./gcc/config/arc/arc-cpu.def"
	  print "# Used by         : tmake_file from Makefile and genmultilib"
	  print ""
	}
    }

  comment = 2;

  print
}

/^$/ {
  # The first empty line stops copy-pasting the GPL comments
  # from this file to the generated file.

  comment = 0
}


/^ARC_CPU/ {
  name = $2
  #  gsub ("\"", "", name)

  if ($4 != "0")
    {
      arch = $3
      if (arch == "6xx")
	arch = 601

      n = split ($4, cpu_flg, "|")

      line = "mcpu." arch
      for (i = 1; i <= n; i++)
	{
	  if (cpu_flg[i] == "FL_MPYOPT_0")
	    line = line "/mmpy-option.0"
	  else if (cpu_flg[i] == "FL_MPYOPT_1")
	    line = line "/mmpy-option.1"
	  else if (cpu_flg[i] == "FL_MPYOPT_2")
	    line = line "/mmpy-option.2"
	  else if (cpu_flg[i] == "FL_MPYOPT_3")
	    line = line "/mmpy-option.3"
	  else if (cpu_flg[i] == "FL_MPYOPT_4")
	    line = line "/mmpy-option.4"
	  else if (cpu_flg[i] == "FL_MPYOPT_5")
	    line = line "/mmpy-option.5"
	  else if (cpu_flg[i] == "FL_MPYOPT_6")
	    line = line "/mmpy-option.6"
	  else if (cpu_flg[i] == "FL_MPYOPT_7")
	    line = line "/mmpy-option.7"
	  else if (cpu_flg[i] == "FL_MPYOPT_8")
	    line = line "/mmpy-option.8"
	  else if (cpu_flg[i] == "FL_MPYOPT_9")
	    line = line "/mmpy-option.9"
	  else if (cpu_flg[i] == "FL_CD")
	    line = line "/mcode-density"
	  else if (cpu_flg[i] == "FL_BS")
	    line = line "/mbarrel-shifter"
	  else if (cpu_flg[i] == "FL_DIVREM")
	    line = line "/mdiv-rem"
	  else if (cpu_flg[i] == "FL_NORM" \
		   || cpu_flg[i] == "FL_SWAP")
	    line = line "/mnorm"
	  else if (cpu_flg[i] == "FL_FPU_FPUS")
	    line = line "/mfpu.fpus"
	  else if (cpu_flg[i] == "FL_FPU_FPUDA")
	    line = line "/mfpu.fpuda"
	  else if (cpu_flg[i] == "FL_FPU_FPUD_ALL")
	    line = line "/mfpu.fpud_all"
	  else if (cpu_flg[i] == "FL_LL64")
	    line = line "/mll64"
	  else if (cpu_flg[i] == "FL_MUL64")
	    line = line "/mmul64"
	  else if (cpu_flg[i] == "FL_MUL32x16")
	    line = line "/mmul32x16"
	  else if (cpu_flg[i] == "FL_FPX_QUARK")
	    line = line "/quark"
	  else if (cpu_flg[i] == "FL_SPFP")
	    line = line "/spfp"
	  else if (cpu_flg[i] == "FL_DPFP")
	    line = line "/dpfp"
	  else if (cpu_flg[i] == "FL_RF16")
	    line = line "/mrf16"
	  else
	    {
	      print "Don't know the flag " cpu_flg[i] > "/dev/stderr"
	      exit 1
	    }
	}
      line = "mcpu." name "=" line
      reuse[n_reuse] = line
      n_reuse++
    }

  core = name
  cores[n_cores] = core
  n_cores++
}

##################################################################
#
# We gathered all the Information, now build/output the following:
#
#    awk Variable         target Variable          FORMAT
#  -----------------------------------------------------------
#    m_options     <->    MULTILIB_OPTIONS         Makefile
#    m_dirnames    <->    MULTILIB_DIRNAMES           "
#
##################################################################

END {
  m_options    = "\nMULTILIB_OPTIONS = "
  m_dirnames   = "\nMULTILIB_DIRNAMES ="
  m_reuse      = "\nMULTILIB_REUSE ="

  sep = ""
  for (c = 0; c < n_cores; c++)
    {
      m_options  = m_options sep "mcpu=" cores[c]
      m_dirnames = m_dirnames " " cores[c]
      sep = "/"
    }

  sep = ""
  for (c = 0; c < n_reuse; c++)
    {
      m_reuse = m_reuse sep reuse[c]
      sep = "\nMULTILIB_REUSE +="
    }
  ############################################################
  # Output that Stuff
  ############################################################

  if (FORMAT == "Makefile")
    {
      # Intended Target: ./gcc/config/arc/t-multilib

      print m_options
      print m_dirnames

      ############################################################
      # Legacy Aliases
      ############################################################

      print ""
      print "# Aliases:"
      print "MULTILIB_MATCHES  = mcpu?arc600=mcpu?ARC600"
      print "MULTILIB_MATCHES += mcpu?arc600=mARC600"
      print "MULTILIB_MATCHES += mcpu?arc600=mA6"
      print "MULTILIB_MATCHES += mcpu?arc601=mcpu?ARC601"
      print "MULTILIB_MATCHES += mcpu?arc700=mA7"
      print "MULTILIB_MATCHES += mcpu?arc700=mARC700"
    }
}