aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorGaius Mulley <gaiusmod2@gmail.com>2025-03-16 15:56:48 +0000
committerGaius Mulley <gaiusmod2@gmail.com>2025-03-16 15:56:48 +0000
commit5ed0564f2879db35106272556ba91f028177c5cd (patch)
tree97e135ec3974f65403bd08a96245e2db39e09392 /gcc
parent952e17223d3a9809a32be23f86f77166b5860b36 (diff)
downloadgcc-5ed0564f2879db35106272556ba91f028177c5cd.zip
gcc-5ed0564f2879db35106272556ba91f028177c5cd.tar.gz
gcc-5ed0564f2879db35106272556ba91f028177c5cd.tar.bz2
PR modula2/115111 Incorrect line debugging locations at the end of the WHILE loop
This fix corrects the END token position used during the GotoOp at the bottom of the WHILE loop. The fix is to pass the relative token position down to M2Quads. This method should be replicated for the other loops END or UNTIL keywords and possibly the END statements for conditional statements. gcc/m2/ChangeLog: PR modula2/115111 * gm2-compiler/M2GenGCC.mod (CodeStatementNote): Add debugging. * gm2-compiler/M2Quads.def (BuildEndWhile): New parameter reltokpos. * gm2-compiler/M2Quads.mod (BuildEndWhile): Reimplement using new parameter. * gm2-compiler/P3Build.bnf (WhileStatement): Call BuildEndWhile with -1 relative position. * gm2-gcc/m2block.cc (do_add_stmt): Tidy comment. (GetGlobals): Ditto. (flush_pending_note): Remove #if 0 code. * gm2-gcc/m2pp.cc (m2pp_nop_expr): New function. (m2pp_statement): New case clause call m2pp_nop_expr. gcc/testsuite/ChangeLog: PR modula2/115111 * gm2/pim/pass/whilestep.mod: New test. Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/m2/gm2-compiler/M2GenGCC.mod4
-rw-r--r--gcc/m2/gm2-compiler/M2Quads.def2
-rw-r--r--gcc/m2/gm2-compiler/M2Quads.mod15
-rw-r--r--gcc/m2/gm2-compiler/P3Build.bnf2
-rw-r--r--gcc/m2/gm2-gcc/m2block.cc21
-rw-r--r--gcc/m2/gm2-gcc/m2pp.cc15
-rw-r--r--gcc/testsuite/gm2/pim/pass/whilestep.mod18
7 files changed, 52 insertions, 25 deletions
diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index 761e79b..ec38dc2 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -1032,6 +1032,10 @@ END FoldStatementNote ;
PROCEDURE CodeStatementNote (tokenno: CARDINAL) ;
BEGIN
+ IF Debugging
+ THEN
+ MetaErrorT0 (tokenno, '{%W} statement note')
+ END ;
CurrentQuadToken := tokenno ;
addStmtNote (TokenToLocation (tokenno))
END CodeStatementNote ;
diff --git a/gcc/m2/gm2-compiler/M2Quads.def b/gcc/m2/gm2-compiler/M2Quads.def
index ec82acc..28e43aa 100644
--- a/gcc/m2/gm2-compiler/M2Quads.def
+++ b/gcc/m2/gm2-compiler/M2Quads.def
@@ -1188,7 +1188,7 @@ PROCEDURE BuildDoWhile ;
False exit is backpatched with q+1
*)
-PROCEDURE BuildEndWhile ;
+PROCEDURE BuildEndWhile (reltokpos: INTEGER) ;
(*
diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index d057a27..a45d67a 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -4283,16 +4283,19 @@ END BuildDoWhile ;
False exit is backpatched with q+1
*)
-PROCEDURE BuildEndWhile ;
+PROCEDURE BuildEndWhile (reltokpos: INTEGER) ;
VAR
+ tok : CARDINAL ;
While,
t, f : CARDINAL ;
BEGIN
- PopBool(t, f) ;
- Assert(t=0) ;
- PopT(While) ;
- GenQuad(GotoOp, NulSym, NulSym, While) ;
- BackPatch(f, NextQuad)
+ tok := GetTokenNo () ;
+ tok := VAL (INTEGER, tok) + reltokpos ;
+ PopBool (t, f) ;
+ Assert (t=0) ;
+ PopT (While) ;
+ GenQuadO (tok, GotoOp, NulSym, NulSym, While, FALSE) ;
+ BackPatch (f, NextQuad)
END BuildEndWhile ;
diff --git a/gcc/m2/gm2-compiler/P3Build.bnf b/gcc/m2/gm2-compiler/P3Build.bnf
index d181f23..4f6ffb7 100644
--- a/gcc/m2/gm2-compiler/P3Build.bnf
+++ b/gcc/m2/gm2-compiler/P3Build.bnf
@@ -1299,7 +1299,7 @@ WhileStatement := "WHILE" % Bui
% BuildStmtNote (0) %
"DO" % BuildDoWhile %
StatementSequence % BuildStmtNote (0) %
- "END" % DisplayStack ; BuildEndWhile %
+ "END" % DisplayStack ; BuildEndWhile (-1) %
=:
RepeatStatement := "REPEAT"
diff --git a/gcc/m2/gm2-gcc/m2block.cc b/gcc/m2/gm2-gcc/m2block.cc
index 40ab96b..c4877d1 100644
--- a/gcc/m2/gm2-gcc/m2block.cc
+++ b/gcc/m2/gm2-gcc/m2block.cc
@@ -28,6 +28,7 @@ along with GNU Modula-2; see the file COPYING3. If not see
#include "m2options.h"
#include "m2tree.h"
#include "m2treelib.h"
+#include "m2pp.h"
/* For each binding contour we allocate a binding_level structure
which records the entities defined or declared in that contour.
@@ -667,8 +668,7 @@ m2block_GetErrorNode (void)
return error_mark_node;
}
-/* GetGlobals - returns a list of global variables, functions,
- constants. */
+/* GetGlobals returns a list of global variables, functions and constants. */
tree
m2block_GetGlobals (void)
@@ -685,7 +685,7 @@ m2block_GetGlobalContext (void)
return global_binding_level->context;
}
-/* do_add_stmt - t is a statement. Add it to the statement-tree. */
+/* do_add_stmt t is a statement. Add it to the statement-tree. */
static tree
do_add_stmt (tree t)
@@ -695,27 +695,14 @@ do_add_stmt (tree t)
return t;
}
-/* flush_pending_note - flushes a pending_statement note if
- necessary. */
+/* flush_pending_note flushes a pending_statement note if necessary. */
static void
flush_pending_note (void)
{
if (pending_statement && (M2Options_GetM2g ()))
{
-#if 0
- /* --fixme-- we need a machine independant way to generate a nop. */
- tree instr = m2decl_BuildStringConstant ("nop", 3);
- tree string
- = resolve_asm_operand_names (instr, NULL_TREE, NULL_TREE, NULL_TREE);
- tree note = build_stmt (pending_location, ASM_EXPR, string, NULL_TREE,
- NULL_TREE, NULL_TREE, NULL_TREE);
-
- ASM_BASIC_P (note) = false;
- ASM_VOLATILE_P (note) = false;
-#else
tree note = build_empty_stmt (pending_location);
-#endif
pending_statement = false;
do_add_stmt (note);
}
diff --git a/gcc/m2/gm2-gcc/m2pp.cc b/gcc/m2/gm2-gcc/m2pp.cc
index d7f5a41..6ec8aaa 100644
--- a/gcc/m2/gm2-gcc/m2pp.cc
+++ b/gcc/m2/gm2-gcc/m2pp.cc
@@ -2362,6 +2362,18 @@ m2pp_asm_expr (pretty *state, tree node)
m2pp_print (state, ");\n");
}
+/* m2pp_nop_expr display the nop_expr node. */
+
+static void
+m2pp_nop_expr (pretty *state, tree t)
+{
+ enum tree_code code = TREE_CODE (t);
+ m2pp_begin (state);
+ m2pp_print (state, "(* NOP for debug location *)");
+ m2pp_needspace (state);
+ m2pp_loc (state, t);
+}
+
/* m2pp_statement attempts to reconstruct a statement. */
static void
@@ -2430,6 +2442,9 @@ m2pp_statement (pretty *s, tree t)
case IF_STMT:
m2pp_if_stmt (s, t);
break;
+ case NOP_EXPR:
+ m2pp_nop_expr (s, t);
+ break;
case ERROR_MARK:
m2pp_print (s, "<ERROR CODE>\n");
break;
diff --git a/gcc/testsuite/gm2/pim/pass/whilestep.mod b/gcc/testsuite/gm2/pim/pass/whilestep.mod
new file mode 100644
index 0000000..452bd3b
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/pass/whilestep.mod
@@ -0,0 +1,18 @@
+MODULE whilestep ;
+
+FROM libc IMPORT printf ;
+
+PROCEDURE init ;
+VAR
+ c: CARDINAL ;
+BEGIN
+ c := 0 ;
+ WHILE c < 20 DO
+ printf ("iteration %d\n", c) ;
+ INC (c)
+ END
+END init ;
+
+BEGIN
+ init
+END whilestep.