[M3devel] cm3 -reduce-target-variation / cm3cg -freduce-target-variation?

Jay K jay.krell at cornell.edu
Mon Jul 4 17:13:57 CEST 2016


That is the intent.
Some of this is actually a restoration of historical behavior -- except now still under a swtich, and arguably the historical behavior wasn't a good default.
I'll remove the "f" on the cm3cg switch, so cm3 and cm3cg take the same parameters, which I think is a better convention than "-ffoo because cm3cg tends to use that."

There is also a slight optimization in there and removal of a seemingly redundant cm3cg -v option -- it is specified twice.
I'll check some build outputs to see if it redundant.

 - Jay


----------------------------------------
> Date: Mon, 4 Jul 2016 09:58:32 -0500
> From: rodney_bates at lcwb.coop
> To: m3devel at elegosoft.com
> Subject: Re: [M3devel] cm3 -reduce-target-variation / cm3cg -freduce-target-variation?
>
>
>
> On 07/04/2016 03:53 AM, Jay K wrote:
>> I guess I should learn to use branches and/or pull requests.
>>
>>
>>
>> This adds cm3 -reduce-target-variation and cm3cg -freduce-target-variation.
>>
>>
>> This meant for temporary development purposes.
>> No user would use them.
>> The point is to make e..g I386_FREEBSD and I386_NETBSD demonstrably identical, or at least closer to it.
>>
>>
>> Ok to commit?
>>
>
> If nothing happens unless these switches are explicitly supplied, it should
> have no effect on anybody else, so OK.
>
>>
>> Maybe name the two switches the same? Or something else?
>>
>>
>> Maybe be less aggressive?
>> i.e. even ../src/foo.m3 is getting changed to foo.m3.
>> The real target is ../I386_DARWIN/foo.m3 => foo.m3
>>
>>
>>
>> diff --git a/m3-sys/cm3/src/Main.m3 b/m3-sys/cm3/src/Main.m3
>> index 5d753e6..61b3f18 100644
>> --- a/m3-sys/cm3/src/Main.m3
>> +++ b/m3-sys/cm3/src/Main.m3
>> @@ -5,7 +5,7 @@ MODULE Main;
>>
>> IMPORT M3Timers, Pathname, Process, Quake;
>> IMPORT RTCollector, RTParams, RTutils, Thread, Wr;
>> -IMPORT TextTextTbl;
>> +IMPORT TextTextTbl, Target;
>>
>> IMPORT Builder, Dirs, M3Build, M3Options, Makefile, Msg, Utils, WebFile;
>> IMPORT MxConfig(*, M3Config, CMKey, CMCurrent *);
>> @@ -18,6 +18,8 @@ VAR
>> build_dir : TEXT := NIL;
>> mach : Quake.Machine := NIL;
>>
>> +CONST BoolToText = ARRAY BOOLEAN OF TEXT{"FALSE", "TRUE"};
>> +
>> PROCEDURE DefineIfNotDefined (qmachine: Quake.Machine;
>> symbol, value: TEXT) RAISES {Quake.Error} =
>> BEGIN
>> @@ -73,6 +75,7 @@ VAR defs: TextTextTbl.T;
>> (* DefineIfNotDefined (mach, "THREAD_LIBRARY", Version.ThreadLibrary); *)
>> (* DefineIfNotDefined (mach, "WINDOW_LIBRARY", Version.WindowLibrary); *)
>> DefineIfNotDefined (mach, "WORD_SIZE", MxConfig.HOST_WORD_SIZE);
>> + DefineIfNotDefined (mach, "REDUCE_TARGET_VARIATION", BoolToText[Target.ReduceTargetVariation]);
>>
>> (* Even if the config file overrides the defaults, such as to do
>> a cross build, the host characteristics are still available. *)
>> diff --git a/m3-sys/cm3/src/Makefile.m3 b/m3-sys/cm3/src/Makefile.m3
>> index 64e169e..8b12320 100644
>> --- a/m3-sys/cm3/src/Makefile.m3
>> +++ b/m3-sys/cm3/src/Makefile.m3
>> @@ -5,7 +5,7 @@ MODULE Makefile;
>>
>> IMPORT FS, M3File, M3Timers, OSError, Params, Process, Text, Thread, Wr;
>> IMPORT Arg, M3Build, M3Options, M3Path, Msg, Utils, TextSeq, TextTextTbl;
>> -IMPORT MxConfig, Dirs, Version;
>> +IMPORT MxConfig, Dirs, Version, Target;
>>
>> TYPE
>> NK = M3Path.Kind;
>> @@ -267,6 +267,9 @@ PROCEDURE ConvertOption (VAR s: State; arg: TEXT; arg_len: INTEGER)
>> | 'r' => IF Text.Equal(arg, "-realclean") THEN
>> ok := TRUE; (* mode set during the pre-scan *)
>> s.found_work := TRUE;
>> + ELSIF Text.Equal(arg, "-reduce-target-variation") THEN
>> + ok := TRUE;
>> + Target.ReduceTargetVariation := TRUE;
>> END;
>>
>> | 's' => IF Text.Equal (arg, "-silent") THEN
>> @@ -707,6 +710,9 @@ CONST
>> " -group-writable \"",
>> " -pb <n> allow <n> parallelism in running back-end (experimental)",
>> " -no-m3ship-resolution use quake variables in .M3SHIP (experimental)",
>> + " -reduce-target-variation omit target in some minor places such as",
>> + " current working directory in debug information",
>> + " for internal development purposes (showing target equivalence)",
>> "",
>> "environment variables:",
>> " M3CONFIG platform dependent configuration file to use (cm3.cfg)",
>> diff --git a/m3-sys/cminstall/src/config-no-install/cm3cfg.common b/m3-sys/cminstall/src/config-no-install/cm3cfg.common
>> index 7334252..9806c3c 100644
>> --- a/m3-sys/cminstall/src/config-no-install/cm3cfg.common
>> +++ b/m3-sys/cminstall/src/config-no-install/cm3cfg.common
>> @@ -460,6 +460,12 @@ proc GetM3Back() is
>> end end
>>
>> m3back = "@" & m3back & "cm3cg " & GetM3BackFlags()
>> +
>> + if defined ("REDUCE_TARGET_VARIATION")
>> + if REDUCE_TARGET_VARIATION
>> + m3back = m3back & " -freduce-target-variation"
>> + end
>> + end
>> return m3back
>> end
>>
>> diff --git a/m3-sys/m3back/src/M3C.m3 b/m3-sys/m3back/src/M3C.m3
>> index f6740c7..22c6ade 100644
>> --- a/m3-sys/m3back/src/M3C.m3
>> +++ b/m3-sys/m3back/src/M3C.m3
>> @@ -29,7 +29,7 @@ VAR CaseDefaultAssertFalse := FALSE;
>>
>> (* Taken together, these help debugging, as you get more lines in the
>> C and the error messages reference C line numbers *)
>> - CONST output_line_directives = TRUE;
>> + VAR output_line_directives := TRUE;
>> CONST output_extra_newlines = FALSE;
>> CONST inline_extract = FALSE;
>>
>> @@ -2197,7 +2197,9 @@ BEGIN
>> END;
>>
>> IF (*self.suppress_line_directive < 1 AND*) text_last_char = '\n' THEN
>> + IF NOT Target.ReduceTargetVariation THEN
>> Wr.PutText(self.c, self.line_directive);
>> + END;
>> self.width := 0;
>> self.last_char_was_newline := TRUE;
>> RETURN;
>> @@ -2205,7 +2207,9 @@ BEGIN
>>
>> IF Text.FindChar(text, '\n') # -1 THEN
>> self.width := 0; (* roughly *)
>> + IF NOT Target.ReduceTargetVariation THEN
>> Wr.PutText(self.c, self.nl_line_directive);
>> + END;
>> self.last_char_was_newline := TRUE;
>> RETURN;
>> END;
>> @@ -2217,11 +2221,13 @@ BEGIN
>> END;
>>
>> self.width := 0;
>> + IF NOT Target.ReduceTargetVariation THEN
>> IF self.last_char_was_newline THEN
>> Wr.PutText(self.c, self.line_directive);
>> ELSE
>> Wr.PutText(self.c, self.nl_line_directive);
>> END;
>> + END;
>> self.last_char_was_newline := TRUE;
>> END print;
>>
>> @@ -2339,9 +2345,10 @@ END set_error_handler;
>> PROCEDURE Prefix_Print(self: T; multipass: Multipass_t) =
>> BEGIN
>> self.comment("begin unit");
>> + output_line_directives := output_line_directives AND NOT Target.ReduceTargetVariation;
>> + IF NOT Target.ReduceTargetVariation THEN
>> self.comment("M3_TARGET = ", Target.System_name);
>> - (* This is an unnecessary target-specific output. *)
>> - (* self.comment("M3_TARGET = ", Target.System_name); *)
>> + END;
>> self.comment("M3_WORDSIZE = ", IntToDec(Target.Word.size));
>> self.static_link_id := M3ID.Add("_static_link");
>> self.alloca_id := M3ID.Add("alloca");
>> diff --git a/m3-sys/m3cc/gcc-4.7/gcc/dbxout.c b/m3-sys/m3cc/gcc-4.7/gcc/dbxout.c
>> index dc52576..33f8844 100644
>> --- a/m3-sys/m3cc/gcc-4.7/gcc/dbxout.c
>> +++ b/m3-sys/m3cc/gcc-4.7/gcc/dbxout.c
>> @@ -1065,6 +1065,9 @@ dbxout_init (const char *input_file_name)
>> labels. */
>> ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
>>
>> + /* Limit paths in debug output, to limit target variation. */
>> + if (!reduce_target_variation)
>> + {
>> /* Put the current working directory in an N_SO symbol. */
>> if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY)
>> {
>> @@ -1087,6 +1090,7 @@ dbxout_init (const char *input_file_name)
>> used_ltext_label_name = true;
>> #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
>> }
>> + }
>>
>> mapped_name = remap_debug_filename (input_file_name);
>> #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
>> diff --git a/m3-sys/m3cc/gcc-4.7/gcc/dwarf2out.c b/m3-sys/m3cc/gcc-4.7/gcc/dwarf2out.c
>> index 0da1021..0a48a65 100644
>> --- a/m3-sys/m3cc/gcc-4.7/gcc/dwarf2out.c
>> +++ b/m3-sys/m3cc/gcc-4.7/gcc/dwarf2out.c
>> @@ -15450,19 +15450,20 @@ add_gnat_descriptive_type_attribute (dw_die_ref die, tree type,
>> static void
>> add_comp_dir_attribute (dw_die_ref die)
>> {
>> + /* Limit paths in debug output, to limit target variation. */
>> + if (reduce_target_variation)
>> + return;
>> +
>> const char *wd = get_src_pwd ();
>> - char *wd1;
>>
>> if (wd == NULL)
>> return;
>>
>> if (DWARF2_DIR_SHOULD_END_WITH_SEPARATOR)
>> {
>> - int wdlen;
>> -
>> - wdlen = strlen (wd);
>> - wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
>> - strcpy (wd1, wd);
>> + int const wdlen = (int)strlen (wd);
>> + char * const wd1 = (char *) ggc_alloc_atomic (wdlen + 2);
>> + memcpy (wd1, wd, wdlen);
>> wd1 [wdlen] = DIR_SEPARATOR;
>> wd1 [wdlen + 1] = 0;
>> wd = wd1;
>> diff --git a/m3-sys/m3cc/gcc-4.7/gcc/toplev.c b/m3-sys/m3cc/gcc-4.7/gcc/toplev.c
>> index 63e4b92..d468632 100644
>> --- a/m3-sys/m3cc/gcc-4.7/gcc/toplev.c
>> +++ b/m3-sys/m3cc/gcc-4.7/gcc/toplev.c
>> @@ -217,11 +217,8 @@ const char *
>> get_src_pwd (void)
>> {
>> if (! src_pwd)
>> - {
>> - src_pwd = getpwd ();
>> - if (!src_pwd)
>> + if (reduce_target_variation || !(src_pwd = getpwd ()))
>> src_pwd = ".";
>> - }
>>
>> return src_pwd;
>> }
>> diff --git a/m3-sys/m3cc/gcc-4.7/gcc/toplev.h b/m3-sys/m3cc/gcc-4.7/gcc/toplev.h
>> index 588cfdb..f4f7cc7 100644
>> --- a/m3-sys/m3cc/gcc-4.7/gcc/toplev.h
>> +++ b/m3-sys/m3cc/gcc-4.7/gcc/toplev.h
>> @@ -80,4 +80,6 @@ extern bool set_src_pwd (const char *);
>> extern HOST_WIDE_INT get_random_seed (bool);
>> extern const char *set_random_seed (const char *);
>>
>> +extern bool reduce_target_variation;
>> +
>> #endif /* ! GCC_TOPLEV_H */
>> diff --git a/m3-sys/m3cc/gcc/gcc/m3cg/lang.opt b/m3-sys/m3cc/gcc/gcc/m3cg/lang.opt
>> index 3bd0469..edfca96 100644
>> --- a/m3-sys/m3cc/gcc/gcc/m3cg/lang.opt
>> +++ b/m3-sys/m3cc/gcc/gcc/m3cg/lang.opt
>> @@ -28,9 +28,6 @@ m3cg
>> Language
>> M3CG
>>
>> -y
>> -m3cg M3CG
>> -
>> fopcodes-trace
>> m3cg M3CG
>> Trace opcodes
>> @@ -59,10 +56,17 @@ ftypes-trace
>> m3cg M3CG
>> Trace types
>>
>> +freduce-target-variation
>> +m3cg M3CG
>> +Reduce target variation somewhat, such as by omitting current working
>> +directory from debug info. Many necessary target variations remain.
>> +
>> v
>> m3cg M3CG
>> +print version
>>
>> y
>> m3cg M3CG
>> +Trace opcodes
>>
>> ; This comment is to ensure we retain the blank line above.
>> diff --git a/m3-sys/m3cc/gcc/gcc/m3cg/parse.c b/m3-sys/m3cc/gcc/gcc/m3cg/parse.c
>> index 03417ed..0cfa46a 100644
>> --- a/m3-sys/m3cc/gcc/gcc/m3cg/parse.c
>> +++ b/m3-sys/m3cc/gcc/gcc/m3cg/parse.c
>> @@ -246,6 +246,7 @@ build_case_label (tree low_value, tree high_value, tree label_decl)
>> /*======================================================= OPTION HANDLING ===*/
>>
>> static int option_trace_all;
>> +bool reduce_target_variation;
>>
>> /*===========================================================================*/
>>
>> @@ -6364,6 +6365,10 @@ m3_handle_option (size_t code, PCSTR /*arg*/, int /*value*/)
>> case OPT_ftypes_trace:
>> option_trace_all += 1;
>> break;
>> +
>> + case OPT_freduce_target_variation:
>> + reduce_target_variation = true;
>> + break;
>> }
>>
>> return 1;
>> diff --git a/m3-sys/m3front/src/misc/Coverage.m3 b/m3-sys/m3front/src/misc/Coverage.m3
>> index c04c902..73fff21 100644
>> --- a/m3-sys/m3front/src/misc/Coverage.m3
>> +++ b/m3-sys/m3front/src/misc/Coverage.m3
>> @@ -77,8 +77,9 @@ PROCEDURE NoteProcedure (v: Value.T) =
>> PROCEDURE GenerateTables () =
>> VAR
>> nLines := MAX (0, maxLine - minLine) + 1;
>> + fname := Host.FileTail (Host.filename);
>> l_header := TLen (Header);
>> - l_fname := TLen (Host.filename);
>> + l_fname := TLen (fname);
>> l_trailer := TLen (Trailer);
>> size : INTEGER;
>> p : ProcHead;
>> @@ -124,10 +125,10 @@ PROCEDURE GenerateTables () =
>> (* CG.Init_int (size, Target.Integer.size, TInt.Zero, FALSE); *)
>> INC (size, Target.Integer.size); (*timestamp*)
>>
>> - CG.Init_intt (size, Target.Integer.size, Text.Length (Host.filename), FALSE);
>> + CG.Init_intt (size, Target.Integer.size, Text.Length (fname), FALSE);
>> INC (size, Target.Integer.size); (*fileLen*)
>>
>> - CG.Init_chars (size, Host.filename, FALSE);
>> + CG.Init_chars (size, fname, FALSE);
>> INC (size, l_fname * Target.Char.size); (*file*)
>>
>> CG.Init_intt (size, Target.Integer.size, minLine, FALSE);
>> diff --git a/m3-sys/m3front/src/misc/Host.i3 b/m3-sys/m3front/src/misc/Host.i3
>> index c71489f..af6a89a 100644
>> --- a/m3-sys/m3front/src/misc/Host.i3
>> +++ b/m3-sys/m3front/src/misc/Host.i3
>> @@ -75,4 +75,7 @@ PROCEDURE OpenUnit (name: M3ID.T; interface, generic: BOOLEAN;
>>
>> PROCEDURE CloseFile (rd: File.T);
>>
>> +PROCEDURE FileTail (path: TEXT): TEXT;
>> + (* returns the 'tail' of 'path' -- after any slashes or even spaces *)
>> +
>> END Host.
>> diff --git a/m3-sys/m3front/src/misc/Host.m3 b/m3-sys/m3front/src/misc/Host.m3
>> index 962d3c6..79042e3 100644
>> --- a/m3-sys/m3front/src/misc/Host.m3
>> +++ b/m3-sys/m3front/src/misc/Host.m3
>> @@ -9,7 +9,7 @@
>>
>> MODULE Host;
>>
>> -IMPORT File, Text, (*ETimer, M3Timers,*) M3ID, M3Compiler;
>> +IMPORT File, Text, (*ETimer, M3Timers,*) M3ID, M3Compiler, Target;
>>
>> PROCEDURE Initialize (READONLY options: ARRAY OF TEXT): BOOLEAN =
>> BEGIN
>> @@ -192,5 +192,24 @@ PROCEDURE CloseFile (rd: File.T) =
>> END;
>> END CloseFile;
>>
>> +PROCEDURE FileTail (path: TEXT): TEXT =
>> + VAR c: CHAR;
>> + BEGIN
>> + IF NOT Target.ReduceTargetVariation THEN RETURN path; END;
>> +
>> + IF (path = NIL) THEN RETURN NIL END;
>> +
>> + (* search for the last slash or blank in the string *)
>> + FOR x := Text.Length (path) - 1 TO 0 BY -1 DO
>> + c := Text.GetChar (path, x);
>> + IF (c = '/') OR (c = ' ') OR (c = '\\') THEN
>> + RETURN Text.Sub (path, x+1);
>> + END;
>> + END;
>> +
>> + (* no slashes *)
>> + RETURN path;
>> + END FileTail;
>> +
>> BEGIN
>> END Host.
>> diff --git a/m3-sys/m3front/src/misc/M3Header.m3 b/m3-sys/m3front/src/misc/M3Header.m3
>> index 1e4decf..877d77c 100644
>> --- a/m3-sys/m3front/src/misc/M3Header.m3
>> +++ b/m3-sys/m3front/src/misc/M3Header.m3
>> @@ -104,7 +104,7 @@ PROCEDURE PushGeneric (VAR s: State) =
>> IF (s.generic = NIL) THEN s.failed := TRUE; RETURN; END;
>>
>> (* build a synthetic file name & start reading *)
>> - filename := old_filename & " => " & filename;
>> + filename := Host.FileTail(old_filename) & " => " & filename;
>> Scanner.Push (filename, s.generic, is_main := Scanner.in_main);
>>
>> (* make sure we got what we wanted *)
>> diff --git a/m3-sys/m3front/src/misc/Scanner.m3 b/m3-sys/m3front/src/misc/Scanner.m3
>> index 7470374..e1dc024 100644
>> --- a/m3-sys/m3front/src/misc/Scanner.m3
>> +++ b/m3-sys/m3front/src/misc/Scanner.m3
>> @@ -228,13 +228,16 @@ PROCEDURE Here (VAR file: TEXT; VAR line: INTEGER) =
>> BEGIN
>> file := files [offset DIV MaxLines];
>> line := offset MOD MaxLines;
>> + IF Target.ReduceTargetVariation THEN
>> + file := Host.FileTail(file);
>> + END;
>> END Here;
>>
>> PROCEDURE LocalHere (VAR file: TEXT; VAR line: INTEGER) =
>> VAR fnum := offset DIV MaxLines;
>> BEGIN
>> IF (local_files[fnum] = NIL) THEN
>> - local_files[fnum] := files[fnum];
>> + local_files[fnum] := Host.FileTail(files[fnum]);
>> END;
>> file := local_files [fnum];
>> line := offset MOD MaxLines;
>> diff --git a/m3-sys/m3front/src/values/Module.m3 b/m3-sys/m3front/src/values/Module.m3
>> index a085eab..576c857 100644
>> --- a/m3-sys/m3front/src/values/Module.m3
>> +++ b/m3-sys/m3front/src/values/Module.m3
>> @@ -421,7 +421,7 @@ PROCEDURE PushGeneric (t: T; VAR rd: File.T): M3ID.T =
>> END;
>>
>> (* build a synthetic file name & start reading *)
>> - filename := old_filename & " => " & filename;
>> + filename := Host.FileTail(old_filename) & " => " & filename;
>> Scanner.Push (filename, rd, is_main := Scanner.in_main);
>> t.genericFile := filename;
>>
>> diff --git a/m3-sys/m3middle/src/Target.i3 b/m3-sys/m3middle/src/Target.i3
>> index fe198d2..cd7acee 100644
>> --- a/m3-sys/m3middle/src/Target.i3
>> +++ b/m3-sys/m3middle/src/Target.i3
>> @@ -529,4 +529,8 @@ VAR (*CONST*)
>> test for nested procedures passed as parameters must be more
>> elaborate (e.g. HPPA). *)
>>
>> + (* This removes some unnecessary target variation in the output,
>> + * such as current working directory in debug output. *)
>> + ReduceTargetVariation: BOOLEAN;
>> +
>> END Target.
>> diff --git a/scripts/python/pylib.py b/scripts/python/pylib.py
>> index 73e622f..487ad17 100755
>> --- a/scripts/python/pylib.py
>> +++ b/scripts/python/pylib.py
>> @@ -388,7 +388,7 @@ def _GetAllTargets():
>>
>> _CBackend = "c" in sys.argv or "C" in sys.argv
>> _BuildDirC = ["", "c"][_CBackend]
>> -_PossibleCm3Flags = ["boot", "keep", "override", "commands", "verbose", "why"]
>> +_PossibleCm3Flags = ["boot", "keep", "override", "commands", "verbose", "why", "reduce-target-variation", "reducetargetvariation"]
>> _SkipGccFlags = ["nogcc", "skipgcc", "omitgcc"]
>> _PossiblePylibFlags = ["noclean", "nocleangcc", "c", "C"] + _SkipGccFlags + _PossibleCm3Flags
>>
>>
>> Thank you,
>> - Jay
>>
>>
>> _______________________________________________
>> M3devel mailing list
>> M3devel at elegosoft.com
>> https://m3lists.elegosoft.com/mailman/listinfo/m3devel
>>
>
> --
> Rodney Bates
> rodney.m.bates at acm.org
> _______________________________________________
> M3devel mailing list
> M3devel at elegosoft.com
> https://m3lists.elegosoft.com/mailman/listinfo/m3devel
 		 	   		  


More information about the M3devel mailing list