OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [config/] [avr/] [genmultilib.awk] - Blame information for rev 709

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 709 jeremybenn
# Copyright (C) 2011 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
# Transform Core/Device Information from avr-mcus.def to a
22
# Representation that is understood by GCC's multilib Machinery.
23
#
24
# The Script works as a Filter from STDIN to STDOUT.
25
#
26
# FORMAT = "Makefile": Generate Makefile Snipet that sets some
27
#                      MULTILIB_* Variables as needed.
28
#
29
# FORMAT = "multilib.h": Generate C Header intended to override
30
#                      (parts of) multilib.h used in gcc.c.
31
#
32
##################################################################
33
 
34
BEGIN {
35
    FS ="[(, \t]+"
36
    option[""] = ""
37
    tiny_stack[""] = 1
38
    comment = 1
39
    n_mcu = 0
40
    n_cores = 0
41
 
42
    mtiny[0] = ""
43
    mtiny[1] = "tiny-stack"
44
    option["tiny-stack"] = "mtiny-stack"
45
}
46
 
47
##################################################################
48
# Add some Comments to the generated Files and copy-paste
49
# Copyright Notice from above.
50
##################################################################
51
 
52
/^#/ {
53
    if (!comment)
54
        next
55
    else if (comment == 1)
56
    {
57
        if (FORMAT == "multilib.h")
58
        {
59
            print "/*"
60
            print "   Auto-generated C header"
61
            print "   Generated by    : ./gcc/config/avr/genmultilib.awk"
62
            print "   Generated from  : ./gcc/config/avr/avr-mcus.def"
63
            print "   Used by         : ./gcc/gcc.c via tm.h"
64
            print "   Purpose         : Override multilib_raw[] from multilib.h"
65
            print "*/"
66
            print "/*"
67
        }
68
 
69
        if (FORMAT == "Makefile")
70
        {
71
            print "# Auto-generated Makefile Snip"
72
            print "# Generated by    : ./gcc/config/avr/genmultilib.awk"
73
            print "# Generated from  : ./gcc/config/avr/avr-mcus.def"
74
            print "# Used by         : tmake_file from Makefile and genmultilib"
75
            print ""
76
        }
77
    }
78
 
79
    comment = 2;
80
 
81
    if (FORMAT == "multilib.h")
82
        gsub ("#", "  ")
83
 
84
    print
85
}
86
 
87
/^$/ {
88
    if (comment && FORMAT == "multilib.h")
89
        print "*/"
90
 
91
    comment = 0
92
}
93
 
94
##################################################################
95
# Run over all AVR_MCU Lines and gather Information:
96
# cores[]     : Enumerates the Cores (avr2, avr25, ...)
97
# mcu[]       : Enumerates the Devices
98
# tiny_stack[]: Maps Core/Device to 0 (2-byte SP) or 1 (1-byte SP)
99
# option[]    : Maps Core/Device to the mmcu= option to get it
100
# toCore[]    : Maps Device to its Core
101
##################################################################
102
 
103
/^AVR_MCU/ {
104
    name = $2
105
    gsub ("\"", "", name)
106
 
107
    if ($4 == "NULL")
108
    {
109
        core = name
110
 
111
        # avr1 is supported for Assembler only:  It gets no multilib
112
        if (core == "avr1")
113
            next
114
 
115
        cores[n_cores] = core
116
        n_cores++
117
        tiny_stack[core] = 0
118
        option[core] = "mmcu=" core
119
 
120
        next
121
    }
122
 
123
    # avr1 is supported for Assembler only:  Its Devices are ignored
124
    if (core == "avr1")
125
        next
126
 
127
    tiny_stack[name]  = $5
128
    mcu[n_mcu] = name
129
    n_mcu++
130
    option[name]      = "mmcu=" name
131
    toCore[name]      = core
132
 
133
    if (tiny_stack[name] == 1)
134
        tiny_stack[core] = 1
135
}
136
 
137
##################################################################
138
#
139
# We gathered all the Information, now build/output the following:
140
#
141
#    awk Variable         target Variable          FORMAT
142
#  -----------------------------------------------------------
143
#    m_options     <->    MULTILIB_OPTIONS         Makefile
144
#    m_dirnames    <->    MULTILIB_DIRNAMES           "
145
#    m_exceptions  <->    MULTILIB_EXCEPTIONS         "
146
#    m_matches     <->    MULTILIB_MATCHES            "
147
#    m_raw         <->    avr_multilib_raw         multilib.h
148
#
149
##################################################################
150
 
151
END {
152
    m_options    = "\nMULTILIB_OPTIONS = "
153
    m_dirnames   = "\nMULTILIB_DIRNAMES ="
154
    m_exceptions = "\nMULTILIB_EXCEPTIONS ="
155
    m_matches    = "\nMULTILIB_MATCHES ="
156
 
157
    m_raw = ""
158
 
159
    ##############################################################
160
    # Compose MULTILIB_OPTIONS.  This represents the Cross-Product
161
    #    (avr2, avr25, ...) x mtiny-stack
162
 
163
    sep = ""
164
    for (c = 0; c < n_cores; c++)
165
    {
166
        m_options = m_options sep option[cores[c]]
167
        sep = "/"
168
    }
169
 
170
    # The ... x mtiny-stack
171
    m_options = m_options " " option[mtiny[1]]
172
 
173
    ##############################################################
174
    # Map Device to its multilib
175
 
176
    # All Mappings that cannot be represented by GCC's genmultilib
177
    # Machinery must be handcrafted.
178
 
179
    dot_excludes = ""
180
    m_raw_sp8 = ""
181
 
182
    for (t = 0; t < n_mcu; t++)
183
    {
184
        core = toCore[mcu[t]]
185
 
186
        if (tiny_stack[mcu[t]] == 1)
187
        {
188
            if (core == "avr2")
189
                dir = mtiny[1]
190
            else
191
                dir = core "/" mtiny[1]
192
 
193
            m_raw_sp8 = m_raw_sp8 "  \"" dir " " option[mcu[t]] ";\",\n"
194
            dot_excludes = dot_excludes " !" option[mcu[t]]
195
 
196
            line = option[mcu[t]] ":" option[mcu[t]]
197
            gsub ("=", "?", line)
198
            gsub (":", "=", line)
199
 
200
            m_matches = m_matches " \\\n\t" line
201
        }
202
 
203
        # The SP = 16 Devices are vanilla: Do the same as
204
        # MULTILIB_MATCHES would yield.  Don't list avr2 (default)
205
 
206
        if (core != "avr2")
207
        {
208
            line = option[core] ":" option[mcu[t]]
209
            gsub ("=", "?", line)
210
            gsub (":", "=", line)
211
 
212
            m_matches = m_matches " \\\n\t" line
213
        }
214
    }
215
 
216
    ####################################################################
217
    # Compose MULTILIB_DIRNAMES, MULTILIB_EXEPTIONS and avr_multilib_raw
218
 
219
    n_mtiny = 2
220
    for (t = 0; t < n_mtiny; t++)
221
        for (c = -1; c < n_cores; c++)
222
        {
223
            if (c == -1)
224
                core = ""
225
            else
226
                core = cores[c]
227
 
228
            # The Directory Name for this multilib
229
 
230
            if (core != "" && mtiny[t] != "")
231
            {
232
                mdir = core "/" mtiny[t]
233
                mopt = option[core] "/" option[mtiny[t]]
234
            }
235
            else
236
            {
237
                mdir = core mtiny[t]
238
                mopt = option[core] option[mtiny[t]]
239
            }
240
 
241
            if (core != "" && tiny_stack[core] == 0 && mtiny[t] != "")
242
            {
243
                # There's not a single SP = 8 Devices for this Core:
244
                # Don't build respective multilib
245
                m_exceptions = m_exceptions " \\\n\t" mopt
246
                continue
247
            }
248
 
249
            if (core != "avr2" || mtiny[t] == "")
250
                m_dirnames = m_dirnames " " mdir
251
 
252
            # Remainder deals with avr_multilib_raw Entries.
253
            # Each Entry looks like
254
            #     "multilib-dir option-to-match !option-to-avoid-match;"
255
            # for Example:
256
            #     "avr25/tiny-stack !mmcu=avr2 mmcu=avr25 !mmcu=avr3 ... mtiny-stack;"
257
 
258
            if (mdir == "")
259
                mdir = "."
260
 
261
            line = mdir
262
 
263
            for (s = 0; s < n_cores; s++)
264
            {
265
                if (cores[s] == core)
266
                    line = line " " option[cores[s]]
267
                else
268
                    line = line " !" option[cores[s]]
269
            }
270
 
271
            if (tiny_stack[core] != 0)
272
            {
273
                if (mtiny[t] == "")
274
                    line = line " !" option[mtiny[1]]
275
                else
276
                    line = line " " option[mtiny[1]]
277
            }
278
 
279
            if (mdir == ".")
280
                line = line dot_excludes
281
 
282
            m_raw = m_raw "  \"" line ";\",\n"
283
        }
284
 
285
    ############################################################
286
    # Output that Stuff
287
    ############################################################
288
 
289
    if (FORMAT == "Makefile")
290
    {
291
        # Intended Target: ./gcc/config/avr/t-multilib
292
 
293
        print m_options
294
        print m_dirnames
295
        print m_exceptions
296
        print m_matches
297
    }
298
 
299
    if (FORMAT == "multilib.h")
300
    {
301
        # Intended Target: ./gcc/config/avr/multilib.h
302
 
303
        print "#if defined NULL && !defined AVR_MULTILIB_H"
304
        print "#define AVR_MULTILIB_H"
305
 
306
        print "static const char* const avr_multilib_raw[] = {"
307
        print m_raw_sp8
308
        print m_raw
309
        print "  NULL\n};"
310
 
311
        print "#undef  multilib_raw"
312
        print "#define multilib_raw avr_multilib_raw"
313
        print "#endif /* AVR_MULTILIB_H */"
314
    }
315
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.