public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch,avr] Simplify genmultilib.awk
@ 2017-05-22 11:48 Georg-Johann Lay
  2017-05-22 11:50 ` Denis Chertykov
  0 siblings, 1 reply; 3+ messages in thread
From: Georg-Johann Lay @ 2017-05-22 11:48 UTC (permalink / raw)
  To: gcc-patches
  Cc: Denis Chertykov, Senthil Kumar Selvaraj, Pitchumani Sivanupandi

[-- Attachment #1: Type: text/plain, Size: 1195 bytes --]

This patch simplifies genmultilib.awk so that it generates
MULTILIB_REQUIRED instead of the complement, MULTILIB_EXCEPTIONS.

The current awk script dates back to the days when we mapped
all the > 200 devices to the mmcu core and also parts of
--help=target to list all devices were generated from avr-mmcus.
That code rot is also cleaned up.  Moreover, the structure now allows
for simpler addition of new multilib options which are likely to come
in the near future.

The result of -print-multi-lib is:

.;
avr25;@mmcu=avr25
avr3;@mmcu=avr3
avr31;@mmcu=avr31
avr35;@mmcu=avr35
avr4;@mmcu=avr4
avr5;@mmcu=avr5
avr51;@mmcu=avr51
avr6;@mmcu=avr6
avrxmega2;@mmcu=avrxmega2
avrxmega4;@mmcu=avrxmega4
avrxmega5;@mmcu=avrxmega5
avrxmega6;@mmcu=avrxmega6
avrxmega7;@mmcu=avrxmega7
avrtiny;@mmcu=avrtiny
tiny-stack;@msp8
avr25/tiny-stack;@mmcu=avr25@msp8

hence unchanged.

Ok for trunk?

Johann


	* config/avr/t-avr (AWK) [t-multilib]: Remove "-v FORMAT=Makefile"
	command option from $(AWK) call.
	* config/avr/genmultilib.awk: Simplify and rewrite so that it
	generates MULTILIB_REQUIRED instead of MULTILIB_EXCEPTIONS.
	[FORMAT]: Remove handling of variable.
	* config/avr/t-multilib: Regenerate.

[-- Attachment #2: gen-multilib.diff --]
[-- Type: text/x-patch, Size: 8508 bytes --]

Index: config/avr/t-avr
===================================================================
--- config/avr/t-avr	(revision 247631)
+++ config/avr/t-avr	(working copy)
@@ -89,14 +89,13 @@ install-device-specs: s-device-specs ins
 		$(INSTALL_DATA) $${file} $(DESTDIR)$(libsubdir)/$${file}; \
 	done
 
-# Map -mmcu= to the right multilib variant
+# Get multilib layout
 # MULTILIB_OPTIONS
 # MULTILIB_DIRNAMES
-# MULTILIB_EXCEPTIONS
-# MULTILIB_MATCHES
+# MULTILIB_REQUIRED
 
 s-mlib: $(srcdir)/config/avr/t-multilib
 
 $(srcdir)/config/avr/t-multilib: $(srcdir)/config/avr/genmultilib.awk \
 				 $(AVR_MCUS)
-	$(AWK) -f $< -v FORMAT=Makefile   $< $(AVR_MCUS) > $@
+	$(AWK) -f $< $< $(AVR_MCUS) > $@
Index: config/avr/genmultilib.awk
===================================================================
--- config/avr/genmultilib.awk	(revision 247631)
+++ config/avr/genmultilib.awk	(working copy)
@@ -22,23 +22,28 @@
 # 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.
+# It generates a Makefile Snipet that sets some
+# MULTILIB_* Variables as needed.
 #
 ##################################################################
 
 BEGIN {
     FS ="[(, \t]+"
     option[""] = ""
-    tiny_stack[""] = 1
     comment = 1
-    n_mcu = 0
-    n_cores = 0
 
-    mtiny[0] = ""
-    mtiny[1] = "tiny-stack"
-    option["tiny-stack"] = "msp8"
+    dir_tiny = "tiny-stack"
+    opt_tiny = "msp8"
+
+    #    awk Variable         Makefile Variable  
+    #  ------------------------------------------
+    #    m_options     <->    MULTILIB_OPTIONS
+    #    m_dirnames    <->    MULTILIB_DIRNAMES
+    #    m_required    <->    MULTILIB_REQUIRED
+    m_sep = ""
+    m_options    = "\nMULTILIB_OPTIONS = "
+    m_dirnames   = "\nMULTILIB_DIRNAMES ="
+    m_required   = "\nMULTILIB_REQUIRED ="
 }
 
 ##################################################################
@@ -51,14 +56,11 @@ BEGIN {
 	next
     else if (comment == 1)
     {
-	if (FORMAT == "Makefile")
-	{
-	    print "# Auto-generated Makefile Snip"
-	    print "# Generated by    : ./gcc/config/avr/genmultilib.awk"
-	    print "# Generated from  : ./gcc/config/avr/avr-mcus.def"
-	    print "# Used by         : tmake_file from Makefile and genmultilib"
-	    print ""
-	}
+	print "# Auto-generated Makefile Snip"
+	print "# Generated by    : ./gcc/config/avr/genmultilib.awk"
+	print "# Generated from  : ./gcc/config/avr/avr-mcus.def"
+	print "# Used by         : tmake_file from Makefile and genmultilib"
+	print ""
     }
 
     comment = 2;
@@ -74,12 +76,10 @@ BEGIN {
 }
 
 ##################################################################
-# Run over all AVR_MCU Lines and gather Information:
-# cores[]     : Enumerates the Cores (avr2, avr25, ...)
-# mcu[]       : Enumerates the Devices
-# tiny_stack[]: Maps Core/Device to 0 (2-byte SP) or 1 (1-byte SP)
-# option[]    : Maps Core/Device to the mmcu= option to get it
-# toCore[]    : Maps Device to its Core
+# Run over all AVR_MCU Lines.  If we encounter a required multilib
+# variant, add according combination of options to m_required,
+# but onyl once.  Add encountered cores to m_dirnames and
+# according -mmcu= options to m_options.
 ##################################################################
 
 /^AVR_MCU/ {
@@ -94,11 +94,12 @@ BEGIN {
 	if (core == "avr1")
 	    next
 
-	cores[n_cores] = core
-	n_cores++
-	tiny_stack[core] = 0
 	option[core] = "mmcu=" core
 
+	m_options  = m_options m_sep option[core]
+	m_dirnames = m_dirnames " " core
+	m_sep = "/"
+
 	next
     }
 
@@ -109,113 +110,37 @@ BEGIN {
     # split device specific feature list
     n = split($4,dev_attribute,"|")
 
-    # set tiny_stack false by default
-    tiny_stack[name] = 0
+    opts = option[core]
+
     for (i=1; i <= n; i++)
-      if (dev_attribute[i] == "AVR_SHORT_SP") {
-        tiny_stack[name]  = 1
-        break
-      }
-
-    mcu[n_mcu] = name
-    n_mcu++
-    option[name]      = "mmcu=" name
-    toCore[name]      = core
+    {
+      if (dev_attribute[i] == "AVR_SHORT_SP")
+        opts = opts "/" opt_tiny
+    }
 
-    if (tiny_stack[name] == 1)
-	tiny_stack[core] = 1
+    if (!have[opts])
+    {
+	have[opts] = 1
+	# Some special handling for the default mmcu: Remove a
+	# leading "mmcu=avr2/" in order not to confuse genmultilib.
+	opts = gensub (/mmcu=avr2\//, "", 1, opts)
+	if (opts != "mmcu=avr2")
+	    m_required = m_required " \\\n\t" opts
+    }
 }
 
 ##################################################################
 # 
-# We gathered all the Information, now build/output the following:
-#
-#    awk Variable         target Variable          FORMAT
-#  -----------------------------------------------------------
-#    m_options     <->    MULTILIB_OPTIONS         Makefile
-#    m_dirnames    <->    MULTILIB_DIRNAMES           "
-#    m_exceptions  <->    MULTILIB_EXCEPTIONS         "
-#
 ##################################################################
 
 END {
-    m_options    = "\nMULTILIB_OPTIONS = "
-    m_dirnames   = "\nMULTILIB_DIRNAMES ="
-    m_exceptions = "\nMULTILIB_EXCEPTIONS ="
-
-    ##############################################################
-    # Compose MULTILIB_OPTIONS.  This represents the Cross-Product
-    #    (avr2, avr25, ...) x msp8
-
-    sep = ""
-    for (c = 0; c < n_cores; c++)
-    {
-	m_options = m_options sep option[cores[c]]
-	sep = "/"
-    }
-
-    # The ... x msp8
-    m_options = m_options " " option[mtiny[1]]
-
-    ##############################################################
-    # Map Device to its multilib
-
-    for (t = 0; t < n_mcu; t++)
-    {
-	core = toCore[mcu[t]]
-	
-	line = option[core] ":" option[mcu[t]]
-	gsub ("=", "?", line)
-	gsub (":", "=", line)
-    }
-
-    ####################################################################
-    # Compose MULTILIB_DIRNAMES and MULTILIB_EXEPTIONS
-
-    n_mtiny = 2
-    for (t = 0; t < n_mtiny; t++)
-	for (c = -1; c < n_cores; c++)
-	{
-	    if (c == -1)
-		core = ""
-	    else
-		core = cores[c]
-
-	    # The Directory Name for this multilib
-
-	    if (core != "" && mtiny[t] != "")
-	    {
-		mdir = core "/" mtiny[t]
-		mopt = option[core] "/" option[mtiny[t]]
-	    }
-	    else
-	    {
-		mdir = core mtiny[t]
-		mopt = option[core] option[mtiny[t]]
-	    }
-
-	    if (core != "" && tiny_stack[core] == 0 && mtiny[t] != "")
-	    {
-		# There's not a single SP = 8 Devices for this Core:
-		# Don't build respective multilib
-		m_exceptions = m_exceptions " \\\n\t" mopt
-		continue
-	    }
-
-	    if (core != "avr2" || mtiny[t] == "")
-		m_dirnames = m_dirnames " " mdir
-	}
-
     ############################################################
     # Output that Stuff
     ############################################################
 
-    if (FORMAT == "Makefile")
-    {
-	# Intended Target: ./gcc/config/avr/t-multilib
+    # Intended Target: ./gcc/config/avr/t-multilib
 
-	print m_options
-	print m_dirnames
-	print m_exceptions
-    }
+    print m_options  " " opt_tiny
+    print m_dirnames " " dir_tiny
+    print m_required
 }
Index: config/avr/t-multilib
===================================================================
--- config/avr/t-multilib	(revision 247631)
+++ config/avr/t-multilib	(working copy)
@@ -23,19 +23,22 @@
 
 MULTILIB_OPTIONS = mmcu=avr2/mmcu=avr25/mmcu=avr3/mmcu=avr31/mmcu=avr35/mmcu=avr4/mmcu=avr5/mmcu=avr51/mmcu=avr6/mmcu=avrxmega2/mmcu=avrxmega4/mmcu=avrxmega5/mmcu=avrxmega6/mmcu=avrxmega7/mmcu=avrtiny msp8
 
-MULTILIB_DIRNAMES =  avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 avrtiny tiny-stack avr25/tiny-stack
+MULTILIB_DIRNAMES = avr2 avr25 avr3 avr31 avr35 avr4 avr5 avr51 avr6 avrxmega2 avrxmega4 avrxmega5 avrxmega6 avrxmega7 avrtiny tiny-stack
 
-MULTILIB_EXCEPTIONS = \
-	mmcu=avr3/msp8 \
-	mmcu=avr31/msp8 \
-	mmcu=avr35/msp8 \
-	mmcu=avr4/msp8 \
-	mmcu=avr5/msp8 \
-	mmcu=avr51/msp8 \
-	mmcu=avr6/msp8 \
-	mmcu=avrxmega2/msp8 \
-	mmcu=avrxmega4/msp8 \
-	mmcu=avrxmega5/msp8 \
-	mmcu=avrxmega6/msp8 \
-	mmcu=avrxmega7/msp8 \
-	mmcu=avrtiny/msp8
+MULTILIB_REQUIRED = \
+	msp8 \
+	mmcu=avr25 \
+	mmcu=avr25/msp8 \
+	mmcu=avr3 \
+	mmcu=avr31 \
+	mmcu=avr35 \
+	mmcu=avr4 \
+	mmcu=avr5 \
+	mmcu=avr51 \
+	mmcu=avr6 \
+	mmcu=avrxmega2 \
+	mmcu=avrxmega4 \
+	mmcu=avrxmega5 \
+	mmcu=avrxmega6 \
+	mmcu=avrxmega7 \
+	mmcu=avrtiny

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch,avr] Simplify genmultilib.awk
  2017-05-22 11:48 [patch,avr] Simplify genmultilib.awk Georg-Johann Lay
@ 2017-05-22 11:50 ` Denis Chertykov
  2017-05-23  8:25   ` Georg-Johann Lay
  0 siblings, 1 reply; 3+ messages in thread
From: Denis Chertykov @ 2017-05-22 11:50 UTC (permalink / raw)
  To: Georg-Johann Lay
  Cc: gcc-patches, Senthil Kumar Selvaraj, Pitchumani Sivanupandi

2017-05-22 15:37 GMT+04:00 Georg-Johann Lay <avr@gjlay.de>:
> This patch simplifies genmultilib.awk so that it generates
> MULTILIB_REQUIRED instead of the complement, MULTILIB_EXCEPTIONS.
>
> The current awk script dates back to the days when we mapped
> all the > 200 devices to the mmcu core and also parts of
> --help=target to list all devices were generated from avr-mmcus.
> That code rot is also cleaned up.  Moreover, the structure now allows
> for simpler addition of new multilib options which are likely to come
> in the near future.
>
> The result of -print-multi-lib is:
>
> .;
> avr25;@mmcu=avr25
> avr3;@mmcu=avr3
> avr31;@mmcu=avr31
> avr35;@mmcu=avr35
> avr4;@mmcu=avr4
> avr5;@mmcu=avr5
> avr51;@mmcu=avr51
> avr6;@mmcu=avr6
> avrxmega2;@mmcu=avrxmega2
> avrxmega4;@mmcu=avrxmega4
> avrxmega5;@mmcu=avrxmega5
> avrxmega6;@mmcu=avrxmega6
> avrxmega7;@mmcu=avrxmega7
> avrtiny;@mmcu=avrtiny
> tiny-stack;@msp8
> avr25/tiny-stack;@mmcu=avr25@msp8
>
> hence unchanged.
>
> Ok for trunk?
>
> Johann
>
>
>         * config/avr/t-avr (AWK) [t-multilib]: Remove "-v FORMAT=Makefile"
>         command option from $(AWK) call.
>         * config/avr/genmultilib.awk: Simplify and rewrite so that it
>         generates MULTILIB_REQUIRED instead of MULTILIB_EXCEPTIONS.
>         [FORMAT]: Remove handling of variable.
>         * config/avr/t-multilib: Regenerate.

Approved.
Please commit.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [patch,avr] Simplify genmultilib.awk
  2017-05-22 11:50 ` Denis Chertykov
@ 2017-05-23  8:25   ` Georg-Johann Lay
  0 siblings, 0 replies; 3+ messages in thread
From: Georg-Johann Lay @ 2017-05-23  8:25 UTC (permalink / raw)
  To: gcc-patches; +Cc: Denis Chertykov

On 22.05.2017 13:47, Denis Chertykov wrote:
> 2017-05-22 15:37 GMT+04:00 Georg-Johann Lay <avr@gjlay.de>:
>> This patch simplifies genmultilib.awk so that it generates
>> MULTILIB_REQUIRED instead of the complement, MULTILIB_EXCEPTIONS.
>>
>> The current awk script dates back to the days when we mapped
>> all the > 200 devices to the mmcu core and also parts of
>> --help=target to list all devices were generated from avr-mmcus.
>> That code rot is also cleaned up.  Moreover, the structure now allows
>> for simpler addition of new multilib options which are likely to come
>> in the near future.
>>
>> The result of -print-multi-lib is:
>>
>> .;
>> avr25;@mmcu=avr25
>> avr3;@mmcu=avr3
>> avr31;@mmcu=avr31
>> avr35;@mmcu=avr35
>> avr4;@mmcu=avr4
>> avr5;@mmcu=avr5
>> avr51;@mmcu=avr51
>> avr6;@mmcu=avr6
>> avrxmega2;@mmcu=avrxmega2
>> avrxmega4;@mmcu=avrxmega4
>> avrxmega5;@mmcu=avrxmega5
>> avrxmega6;@mmcu=avrxmega6
>> avrxmega7;@mmcu=avrxmega7
>> avrtiny;@mmcu=avrtiny
>> tiny-stack;@msp8
>> avr25/tiny-stack;@mmcu=avr25@msp8
>>
>> hence unchanged.
>>
>> Ok for trunk?
>>
>> Johann
>>
>>
>>         * config/avr/t-avr (AWK) [t-multilib]: Remove "-v FORMAT=Makefile"
>>         command option from $(AWK) call.
>>         * config/avr/genmultilib.awk: Simplify and rewrite so that it
>>         generates MULTILIB_REQUIRED instead of MULTILIB_EXCEPTIONS.
>>         [FORMAT]: Remove handling of variable.
>>         * config/avr/t-multilib: Regenerate.
>
> Approved.
> Please commit.

Also committed the following change to make it work with less common
awk implementations:

https://gcc.gnu.org/r248357

Johann


Index: config/avr/genmultilib.awk
===================================================================
--- config/avr/genmultilib.awk  (revision 248332)
+++ config/avr/genmultilib.awk  (working copy)
@@ -123,7 +123,7 @@ BEGIN {
         have[opts] = 1
         # Some special handling for the default mmcu: Remove a
         # leading "mmcu=avr2/" in order not to confuse genmultilib.
-       opts = gensub (/mmcu=avr2\//, "", 1, opts)
+       gsub (/^mmcu=avr2\//, "", opts)
         if (opts != "mmcu=avr2")
             m_required = m_required " \\\n\t" opts
      }



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-05-23  7:55 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-22 11:48 [patch,avr] Simplify genmultilib.awk Georg-Johann Lay
2017-05-22 11:50 ` Denis Chertykov
2017-05-23  8:25   ` Georg-Johann Lay

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).