public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-1638] PR modula2/110126 variables are reported as unused when referenced by ASM
@ 2023-06-08 23:56 Gaius Mulley
  0 siblings, 0 replies; only message in thread
From: Gaius Mulley @ 2023-06-08 23:56 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:990d10ab23360fef8b5eb6937ac10b4f67f46e2d

commit r14-1638-g990d10ab23360fef8b5eb6937ac10b4f67f46e2d
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Fri Jun 9 00:55:50 2023 +0100

    PR modula2/110126 variables are reported as unused when referenced by ASM
    
    This patches fixes two problems with the asm statement.
    gm2 -Wall -c fooasm3.mod generates an incorrect warning and
    gm2 cannot concatenate strings before an ASM statement.
    The asm statement now accepts a constant expression (rather than
    a string) and it updates the variable read/write use lists as
    appropriate.
    
    gcc/m2/ChangeLog:
    
            PR modula2/110126
            * gm2-compiler/M2GenGCC.mod (BuildTreeFromInterface): Remove
            tokenno parameter.  Use object tok instead of tokenno.
            (BuildTrashTreeFromInterface): Use object tok instead of
            GetDeclaredMod.
            (CodeInline): Remove tokenno from parameter list to BuildTreeFromInterface.
            * gm2-compiler/M2Quads.def (BuildAsmElement): Exported and
            defined.
            * gm2-compiler/M2Quads.mod (BuildOptimizeOff): Reformatted.
            (BuildInline): Reformatted.
            (BuildLineNo): Reformatted.
            (UseLineNote): Reformatted.
            (BuildAsmElement): New procedure.
            * gm2-compiler/P0SyntaxCheck.bnf (AsmOperands): Use
            ConstExpression instead of string.
            (AsmElement): Use ConstExpression instead of string.
            (TrashList): Use ConstExpression instead of string.
            * gm2-compiler/P1Build.bnf (AsmOperands): Use
            ConstExpression instead of string.
            (AsmElement): Use ConstExpression instead of string.
            (TrashList): Use ConstExpression instead of string.
            * gm2-compiler/P2Build.bnf (AsmOperands): Use
            ConstExpression instead of string.
            (AsmElement): Use ConstExpression instead of string.
            (TrashList): Use ConstExpression instead of string.
            * gm2-compiler/P3Build.bnf (AsmOperands): Rewrite.
            (AsmOperandSpec): Rewrite.
            (AsmOutputList): New rule.
            (AsmInputList): New rule.
            (TrashList): Rewrite.
            * gm2-compiler/PCBuild.bnf (AsmOperands): Use
            ConstExpression instead of string.
            (AsmElement): Use ConstExpression instead of string.
            (TrashList): Use ConstExpression instead of string.
            * gm2-compiler/PHBuild.bnf (AsmOperands): Use
            ConstExpression instead of string.
            (AsmElement): Use ConstExpression instead of string.
            (TrashList): Use ConstExpression instead of string.
            * gm2-compiler/SymbolTable.def (PutRegInterface):
            Rewrite interface.
            (GetRegInterface): Rewrite interface.
            * gm2-compiler/SymbolTable.mod (SetFirstUsed): New procedure.
            (PutFirstUsed): New procedure.
            (PutRegInterface): Rewrite.
            (GetRegInterface): Rewrite.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/110126
            * gm2/pim/pass/fooasm3.mod: New test.
    
    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

Diff:
---
 gcc/m2/gm2-compiler/M2GenGCC.mod       |  32 ++++----
 gcc/m2/gm2-compiler/M2Quads.def        |  28 ++++++-
 gcc/m2/gm2-compiler/M2Quads.mod        |  84 ++++++++++++++++++---
 gcc/m2/gm2-compiler/P0SyntaxCheck.bnf  |   6 +-
 gcc/m2/gm2-compiler/P1Build.bnf        |  10 +--
 gcc/m2/gm2-compiler/P2Build.bnf        |  10 +--
 gcc/m2/gm2-compiler/P3Build.bnf        | 132 ++++++++++-----------------------
 gcc/m2/gm2-compiler/PCBuild.bnf        |  10 ++-
 gcc/m2/gm2-compiler/PHBuild.bnf        |  10 +--
 gcc/m2/gm2-compiler/SymbolTable.def    |  11 ++-
 gcc/m2/gm2-compiler/SymbolTable.mod    | 128 ++++++++++++++++++++++----------
 gcc/testsuite/gm2/pim/pass/fooasm3.mod |  12 +++
 12 files changed, 292 insertions(+), 181 deletions(-)

diff --git a/gcc/m2/gm2-compiler/M2GenGCC.mod b/gcc/m2/gm2-compiler/M2GenGCC.mod
index 67a003e3dd6..90e237d82f5 100644
--- a/gcc/m2/gm2-compiler/M2GenGCC.mod
+++ b/gcc/m2/gm2-compiler/M2GenGCC.mod
@@ -701,8 +701,9 @@ END FindType ;
    BuildTreeFromInterface - generates a GCC tree from an interface definition.
 *)
 
-PROCEDURE BuildTreeFromInterface (tokenno: CARDINAL; sym: CARDINAL) : Tree ;
+PROCEDURE BuildTreeFromInterface (sym: CARDINAL) : Tree ;
 VAR
+   tok     : CARDINAL ;
    i       : CARDINAL ;
    name    : Name ;
    str,
@@ -715,19 +716,19 @@ BEGIN
    THEN
       i := 1 ;
       REPEAT
-         GetRegInterface (sym, i, name, str, obj) ;
+         GetRegInterface (sym, i, tok, name, str, obj) ;
          IF str#NulSym
          THEN
             IF IsConstString (str)
             THEN
-               DeclareConstant (tokenno, obj) ;
+               DeclareConstant (tok, obj) ;
                IF name = NulName
                THEN
                   gccName := NIL
                ELSE
                   gccName := BuildStringConstant (KeyToCharStar (name), LengthKey (name))
                END ;
-               tree := ChainOnParamValue (tree, gccName, PromoteToString (tokenno, str), Mod2Gcc (obj))
+               tree := ChainOnParamValue (tree, gccName, PromoteToString (tok, str), Mod2Gcc (obj))
             ELSE
                WriteFormat0 ('a constraint to the GNU ASM statement must be a constant string')
             END
@@ -745,25 +746,26 @@ END BuildTreeFromInterface ;
 
 PROCEDURE BuildTrashTreeFromInterface (sym: CARDINAL) : Tree ;
 VAR
+   tok : CARDINAL ;
    i   : CARDINAL ;
    str,
    obj : CARDINAL ;
    name: Name ;
    tree: Tree ;
 BEGIN
-   tree := Tree(NIL) ;
+   tree := Tree (NIL) ;
    IF sym#NulSym
    THEN
       i := 1 ;
       REPEAT
-         GetRegInterface(sym, i, name, str, obj) ;
-         IF str#NulSym
+         GetRegInterface (sym, i, tok, name, str, obj) ;
+         IF str # NulSym
          THEN
-            IF IsConstString(str)
+            IF IsConstString (str)
             THEN
-               tree := AddStringToTreeList(tree, PromoteToString(GetDeclaredMod(str), str))
+               tree := AddStringToTreeList (tree, PromoteToString (tok, str))
             ELSE
-               WriteFormat0('a constraint to the GNU ASM statement must be a constant string')
+               WriteFormat0 ('a constraint to the GNU ASM statement must be a constant string')
             END
          END ;
 (*
@@ -772,10 +774,10 @@ BEGIN
             InternalError ('not expecting the object to be non null in the trash list')
          END ;
 *)
-         INC(i)
-      UNTIL (str=NulSym) AND (obj=NulSym)
+         INC (i)
+      UNTIL (str = NulSym) AND (obj = NulSym)
    END ;
-   RETURN( tree )
+   RETURN tree
 END BuildTrashTreeFromInterface ;
 
 
@@ -801,8 +803,8 @@ BEGIN
       can handle the register dependency providing the user
       specifies VOLATILE and input/output/trash sets correctly.
    *)
-   inputs  := BuildTreeFromInterface (tokenno, GetGnuAsmInput(GnuAsm)) ;
-   outputs := BuildTreeFromInterface (tokenno, GetGnuAsmOutput(GnuAsm)) ;
+   inputs  := BuildTreeFromInterface (GetGnuAsmInput(GnuAsm)) ;
+   outputs := BuildTreeFromInterface (GetGnuAsmOutput(GnuAsm)) ;
    trash   := BuildTrashTreeFromInterface (GetGnuAsmTrash(GnuAsm)) ;
    labels  := NIL ;  (* at present it makes no sence for Modula-2 to jump to a label,
                         given that labels are not allowed in Modula-2.  *)
diff --git a/gcc/m2/gm2-compiler/M2Quads.def b/gcc/m2/gm2-compiler/M2Quads.def
index 582daeb21a7..493111e7c1b 100644
--- a/gcc/m2/gm2-compiler/M2Quads.def
+++ b/gcc/m2/gm2-compiler/M2Quads.def
@@ -144,7 +144,7 @@ EXPORT QUALIFIED StartBuildDefFile, StartBuildModFile, EndBuildFile,
                  IsAutoPushOn, PushAutoOn, PushAutoOff, PopAuto,
                  PushInConstExpression, PopInConstExpression,
                  IsInConstExpression,
-                 MustCheckOverflow ;
+                 MustCheckOverflow, BuildAsmElement ;
 
 
 TYPE
@@ -2711,4 +2711,30 @@ PROCEDURE PopInConstExpression ;
 PROCEDURE IsInConstExpression () : BOOLEAN ;
 
 
+(*
+   BuildAsmElement - the stack is expected to contain:
+
+
+                        Entry                      Exit
+                        =====                      ====
+
+                 Ptr ->
+                        +------------------+
+                        | expr | tokpos    |
+                        |------------------|
+                        | str              |
+                        |------------------|
+                        | name             |
+                        |------------------|       +------------------+
+                        | CurrentInterface |       | CurrentInterface |
+                        |------------------|       |------------------|
+                        | CurrentAsm       |       | CurrentAsm       |
+                        |------------------|       |------------------|
+                        | n                |       | n                |
+                        |------------------|       |------------------|
+*)
+
+PROCEDURE BuildAsmElement (input, output, trash: BOOLEAN) ;
+
+
 END M2Quads.
diff --git a/gcc/m2/gm2-compiler/M2Quads.mod b/gcc/m2/gm2-compiler/M2Quads.mod
index 65e3c49cf50..8639d5e5807 100644
--- a/gcc/m2/gm2-compiler/M2Quads.mod
+++ b/gcc/m2/gm2-compiler/M2Quads.mod
@@ -94,6 +94,8 @@ FROM SymbolTable IMPORT ModeOfAddr, GetMode, PutMode, GetSymName, IsUnknown,
                         NoOfElements,
                         NoOfParam,
                         StartScope, EndScope,
+                        IsGnuAsm, IsGnuAsmVolatile,
+                        MakeRegInterface, PutRegInterface,
                         HasExceptionBlock, PutExceptionBlock,
                         HasExceptionFinally, PutExceptionFinally,
                         GetParent, GetRecord, IsRecordField, IsFieldVarient, IsRecord,
@@ -13995,7 +13997,7 @@ END BuildOptimizeOn ;
 
 PROCEDURE BuildOptimizeOff ;
 BEGIN
-   GenQuad(OptimizeOffOp, NulSym, NulSym, NulSym)
+   GenQuad (OptimizeOffOp, NulSym, NulSym, NulSym)
 END BuildOptimizeOff ;
 
 
@@ -14020,8 +14022,8 @@ PROCEDURE BuildInline ;
 VAR
    Sym: CARDINAL ;
 BEGIN
-   PopT(Sym) ;
-   GenQuad(InlineOp, NulSym, NulSym, Sym)
+   PopT (Sym) ;
+   GenQuad (InlineOp, NulSym, NulSym, Sym)
 END BuildInline ;
 
 
@@ -14047,11 +14049,11 @@ VAR
 BEGIN
    IF (NextQuad#Head) AND (GenerateLineDebug OR GenerateDebugging) AND FALSE
    THEN
-      filename := makekey(string(GetFileName())) ;
-      f := GetQF(NextQuad-1) ;
-      IF NOT ((f^.Operator=LineNumberOp) AND (f^.Operand1=WORD(filename)))
+      filename := makekey (string (GetFileName ())) ;
+      f := GetQF (NextQuad-1) ;
+      IF NOT ((f^.Operator = LineNumberOp) AND (f^.Operand1 = WORD (filename)))
       THEN
-         GenQuad(LineNumberOp, WORD(filename), NulSym, WORD(GetLineNo()))
+         GenQuad (LineNumberOp, WORD (filename), NulSym, WORD (GetLineNo ()))
       END
    END
 END BuildLineNo ;
@@ -14066,14 +14068,14 @@ VAR
    f: QuadFrame ;
 BEGIN
    WITH l^ DO
-      f := GetQF(NextQuad-1) ;
-      IF (f^.Operator=LineNumberOp) AND (f^.Operand1=WORD(File))
+      f := GetQF (NextQuad-1) ;
+      IF (f^.Operator = LineNumberOp) AND (f^.Operand1 = WORD (File))
       THEN
          (* do nothing *)
       ELSE
          IF FALSE
          THEN
-            GenQuad(LineNumberOp, WORD(File), NulSym, WORD(Line))
+            GenQuad (LineNumberOp, WORD (File), NulSym, WORD (Line))
          END
       END ;
       Next := FreeLineList
@@ -14396,6 +14398,68 @@ BEGIN
 END AddVarientEquality ;
 
 
+(*
+   BuildAsmElement - the stack is expected to contain:
+
+
+                        Entry                      Exit
+                        =====                      ====
+
+                 Ptr ->
+                        +------------------+
+                        | expr | tokpos    |
+                        |------------------|
+                        | str              |
+                        |------------------|
+                        | name             |
+                        |------------------|       +------------------+
+                        | CurrentInterface |       | CurrentInterface |
+                        |------------------|       |------------------|
+                        | CurrentAsm       |       | CurrentAsm       |
+                        |------------------|       |------------------|
+                        | n                |       | n                |
+                        |------------------|       |------------------|
+*)
+
+PROCEDURE BuildAsmElement (input, output, trash: BOOLEAN) ;
+VAR
+   n, str, expr, tokpos,
+   CurrentInterface,
+   CurrentAsm, name    : CARDINAL ;
+BEGIN
+   PopTtok (expr, tokpos) ;
+   PopT (str) ;
+   PopT (name) ;
+   PopT (CurrentInterface) ;
+   PopT (CurrentAsm) ;
+   Assert (IsGnuAsm (CurrentAsm) OR IsGnuAsmVolatile (CurrentAsm)) ;
+   PopT (n) ;
+   INC (n) ;
+   IF CurrentInterface = NulSym
+   THEN
+      CurrentInterface := MakeRegInterface ()
+   END ;
+   IF input
+   THEN
+      PutRegInterface (tokpos, CurrentInterface, n, name, str, expr,
+                       NextQuad, 0)
+   END ;
+   IF output
+   THEN
+      PutRegInterface (tokpos, CurrentInterface, n, name, str, expr,
+                       0, NextQuad)
+   END ;
+   IF trash
+   THEN
+      PutRegInterface (tokpos, CurrentInterface, n, name, str, expr,
+                       0, NextQuad)
+   END ;
+   PushT (n) ;
+   PushT (CurrentAsm) ;
+   PushT (CurrentInterface)
+END BuildAsmElement ;
+
+
 (*
    IncOperandD - increment the dimension number associated with symbol
                  at, pos, on the boolean stack.
diff --git a/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf b/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
index f2c74c7cc23..52a8629f0bb 100644
--- a/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
+++ b/gcc/m2/gm2-compiler/P0SyntaxCheck.bnf
@@ -918,14 +918,14 @@ NamedOperand := '[' Ident ']' =:
 
 AsmOperandName := [ NamedOperand ] =:
 
-AsmOperands  := string [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ]
+AsmOperands  := ConstExpression ':' AsmList [ ':' AsmList [ ':' TrashList ] ]
               =:
 
 AsmList      := [ AsmElement ] { ',' AsmElement } =:
 
-AsmElement   := AsmOperandName string '(' Expression ')'
+AsmElement   := AsmOperandName ConstExpression '(' Expression ')'
               =:
 
-TrashList    := [ string ] { ',' string } =:
+TrashList    := [ ConstExpression ] { ',' ConstExpression } =:
 
 FNB
diff --git a/gcc/m2/gm2-compiler/P1Build.bnf b/gcc/m2/gm2-compiler/P1Build.bnf
index c234d00efec..5be6af4ddcb 100644
--- a/gcc/m2/gm2-compiler/P1Build.bnf
+++ b/gcc/m2/gm2-compiler/P1Build.bnf
@@ -1037,14 +1037,14 @@ NamedOperand := '[' Ident ']' =:
 
 AsmOperandName := [ NamedOperand ] =:
 
-AsmOperands  := string [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ]
-             =:
+AsmOperands  := ConstExpression ':' AsmList [ ':' AsmList [ ':' TrashList ] ]
+              =:
 
 AsmList      := [ AsmElement ] { ',' AsmElement } =:
 
-AsmElement   := AsmOperandName string '(' Expression ')'
-             =:
+AsmElement   := AsmOperandName ConstExpression '(' Expression ')'
+              =:
 
-TrashList    := [ string ] { ',' string } =:
+TrashList    := [ ConstExpression ] { ',' ConstExpression } =:
 
 FNB
diff --git a/gcc/m2/gm2-compiler/P2Build.bnf b/gcc/m2/gm2-compiler/P2Build.bnf
index ea5cfe73a5d..0a82e6b97f1 100644
--- a/gcc/m2/gm2-compiler/P2Build.bnf
+++ b/gcc/m2/gm2-compiler/P2Build.bnf
@@ -1227,14 +1227,14 @@ NamedOperand := '[' Ident ']' =:
 
 AsmOperandName := [ NamedOperand ] =:
 
-AsmOperands  := string [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ]
-             =:
+AsmOperands  := ConstExpression ':' AsmList [ ':' AsmList [ ':' TrashList ] ]
+              =:
 
 AsmList      := [ AsmElement ] { ',' AsmElement } =:
 
-AsmElement   := AsmOperandName string '(' Expression ')'
-             =:
+AsmElement   := AsmOperandName ConstExpression '(' Expression ')'
+              =:
 
-TrashList    := [ string ] { ',' string } =:
+TrashList    := [ ConstExpression ] { ',' ConstExpression } =:
 
 FNB
diff --git a/gcc/m2/gm2-compiler/P3Build.bnf b/gcc/m2/gm2-compiler/P3Build.bnf
index 328ef4f1a35..8fbe19111b6 100644
--- a/gcc/m2/gm2-compiler/P3Build.bnf
+++ b/gcc/m2/gm2-compiler/P3Build.bnf
@@ -126,6 +126,7 @@ FROM M2Quads IMPORT PushT, PopT, PushTF, PopTF, PopNothing, Annotate,
                     BuildRetry,
                     DisplayStack,
                     AddVarientRange, AddVarientEquality,
+                    BuildAsmElement,
                     BeginVarient, EndVarient, BeginVarientList, EndVarientList,
                     PushInConstExpression, PopInConstExpression, IsInConstExpression,
                     BuildDefaultFieldAlignment, BuildPragmaField,
@@ -1489,7 +1490,7 @@ AsmStatement :=                                                            % VAR
 AsmOperands :=                                                             % VAR CurrentAsm, count: CARDINAL ;
                                                                                  str: CARDINAL ;
                                                                            %
-               string                                                      % IF Pass3
+               ConstExpression                                             % IF Pass3
                                                                              THEN
                                                                                 PopT(str) ;
                                                                                 PopT(CurrentAsm) ;
@@ -1517,7 +1518,7 @@ AsmOperands :=                                                             % VAR
 
 AsmOperandSpec :=                                                          % VAR CurrentAsm, outputs, inputs, trash, count: CARDINAL ;
                                                                            %
-                  [ ':' AsmList                                            % IF Pass3
+                    ':' AsmOutputList                                      % IF Pass3
                                                                              THEN
                                                                                 PopT(outputs) ;
                                                                                 PopT(CurrentAsm) ;
@@ -1533,7 +1534,7 @@ AsmOperandSpec :=                                                          % VAR
                                                                                 PushT(NulSym)    (* the InterfaceSym *)
                                                                              END
                                                                            %
-                     [ ':' AsmList                                         % IF Pass3
+                     [ ':' AsmInputList                                    % IF Pass3
                                                                              THEN
                                                                                 PopT(inputs) ;
                                                                                 PopT(CurrentAsm) ;
@@ -1549,7 +1550,7 @@ AsmOperandSpec :=                                                          % VAR
                                                                                 PushT(NulSym)    (* the InterfaceSym *)
                                                                              END
                                                                            %
-                        [ ':' TrashList                                    % IF Pass3
+                        [ ':' AsmTrashList                                 % IF Pass3
                                                                              THEN
                                                                                 PopT(trash) ;
                                                                                 PopT(CurrentAsm) ;
@@ -1565,26 +1566,12 @@ AsmOperandSpec :=                                                          % VAR
                                                                                 PushT(NulSym)    (* the InterfaceSym *)
                                                                              END
                                                                            %
-                           ] ] ]
+                           ] ]
             =:
 
-AsmList     :=                                                             % VAR count, CurrentAsm, CurrentInterface: CARDINAL ; %
-                                                                           % IF Pass3
-                                                                             THEN
-                                                                                PopT(CurrentInterface) ;
-                                                                                PopT(CurrentAsm) ;
-                                                                                PopT(count) ;
-                                                                                Assert(IsGnuAsm(CurrentAsm) OR IsGnuAsmVolatile(CurrentAsm)) ;
-                                                                                PushT(count) ;
-                                                                                PushT(CurrentAsm) ;
-                                                                                PushT(CurrentInterface) ;
-                                                                                IF DebugAsm
-                                                                                THEN
-                                                                                   printf1('8: AsmList has a count of asm operands: %d\n', count)
-                                                                                END
-                                                                             END
-                                                                           %
-               [ AsmElement ] { ',' AsmElement } =:
+AsmOutputList := [ AsmOutputElement ] { ',' AsmOutputElement } =:
+
+AsmInputList := [ AsmInputElement ] { ',' AsmInputElement } =:
 
 NamedOperand := '[' Ident ']' =:
 
@@ -1597,85 +1584,48 @@ AsmOperandName :=  ( NamedOperand
                                     )
                 =:
 
-AsmElement :=                                                              % VAR n, str, expr,
-                                                                                 CurrentInterface,
-                                                                                 CurrentAsm, name: CARDINAL ; %
-              AsmOperandName
+AsmInputElement := AsmOperandName
+                   ConstExpression '(' Expression                          % IF Pass3
+                                                                             THEN
+                                                                                BuildAsmElement (TRUE, FALSE, FALSE)
+                                                                             END
+                                                                           %
+                                   ')'
+                 =:
 
-              string '(' Expression                                        % IF Pass3
+AsmOutputElement := AsmOperandName
+                    ConstExpression '(' Expression                         % IF Pass3
                                                                              THEN
-                                                                                PopT(expr) ;
-                                                                                PopT(str) ;
-                                                                                PopT(name) ;
-                                                                                PopT(CurrentInterface) ;
-                                                                                PopT(CurrentAsm) ;
-                                                                                Assert(IsGnuAsm(CurrentAsm) OR IsGnuAsmVolatile(CurrentAsm)) ;
-                                                                                PopT(n) ;
-                                                                                INC(n) ;
-                                                                                IF CurrentInterface=NulSym
-                                                                                THEN
-                                                                                   CurrentInterface := MakeRegInterface()
-                                                                                END ;
-                                                                                IF DebugAsm
-                                                                                THEN
-                                                                                   printf1('5: count of asm operands: %d\n', n)
-                                                                                END ;
-                                                                                PutRegInterface(CurrentInterface, n, name, str, expr) ;
-                                                                                PushT(n) ;
-                                                                                PushT(CurrentAsm) ;
-                                                                                PushT(CurrentInterface)
+                                                                                BuildAsmElement (FALSE, TRUE, FALSE)
                                                                              END
                                                                            %
-                      ')'
-           =:
+                                    ')'
+                  =:
 
-TrashList :=                                                               % VAR CurrentInterface,
-                                                                                 CurrentAsm,
-                                                                                 n, str          : CARDINAL ; %
-             [ string                                                      % IF Pass3
+AsmTrashList :=                                                            % VAR expr, tokpos  : CARDINAL ; %
+                 [ ConstExpression                                         % IF Pass3
                                                                              THEN
-                                                                                PopT(str) ;
-                                                                                PopT(CurrentInterface) ;
-                                                                                PopT(CurrentAsm) ;
-                                                                                PopT(n) ;
-                                                                                INC(n) ;
-                                                                                Assert(IsGnuAsm(CurrentAsm) OR IsGnuAsmVolatile(CurrentAsm)) ;
-                                                                                IF DebugAsm
-                                                                                THEN
-                                                                                   printf1('6: count of asm trash operands: %d\n', n)
-                                                                                END ;
-                                                                                IF CurrentInterface=NulSym
-                                                                                THEN
-                                                                                   CurrentInterface := MakeRegInterface()
-                                                                                END ;
-                                                                                PutRegInterface(CurrentInterface, n, NulName, str, NulSym) ;
-                                                                                PushT(n) ;
-                                                                                PushT(CurrentAsm) ;
-                                                                                PushT(CurrentInterface)
+                                                                                PopTtok (expr, tokpos) ;
+                                                                                PushT (NulSym) ;
+                                                                                PushTtok (expr, tokpos) ;
+                                                                                BuildAsmElement (FALSE, FALSE, TRUE) ;
+                                                                                PopTtok (expr, tokpos) ;
+                                                                                PopNothing ;
+                                                                                PushTtok (expr, tokpos) ;
                                                                              END
+
                                                                            %
-             ] { ',' string                                                % IF Pass3
+                 ] { ',' ConstExpression                                   % IF Pass3
                                                                              THEN
-                                                                                PopT(str) ;
-                                                                                PopT(CurrentInterface) ;
-                                                                                PopT(CurrentAsm) ;
-                                                                                PopT(n) ;
-                                                                                INC(n) ;
-                                                                                Assert(IsGnuAsm(CurrentAsm) OR IsGnuAsmVolatile(CurrentAsm)) ;
-                                                                                IF DebugAsm
-                                                                                THEN
-                                                                                   printf1('7: count of asm trash operands: %d\n', n)
-                                                                                END ;
-                                                                                IF CurrentInterface=NulSym
-                                                                                THEN
-                                                                                   CurrentInterface := MakeRegInterface()
-                                                                                END ;
-                                                                                PutRegInterface(CurrentInterface, n, NulName, str, NulSym) ;
-                                                                                PushT(n) ;
-                                                                                PushT(CurrentAsm) ;
-                                                                                PushT(CurrentInterface)
+                                                                                PopTtok (expr, tokpos) ;
+                                                                                PushT (NulSym) ;
+                                                                                PushTtok (expr, tokpos) ;
+                                                                                BuildAsmElement (FALSE, FALSE, TRUE) ;
+                                                                                PopTtok (expr, tokpos) ;
+                                                                                PopNothing ;
+                                                                                PushTtok (expr, tokpos) ;
                                                                              END
                                                                            %
-                } =:
+                   } =:
 
 FNB
diff --git a/gcc/m2/gm2-compiler/PCBuild.bnf b/gcc/m2/gm2-compiler/PCBuild.bnf
index ba25d51de0a..bffb1ea569c 100644
--- a/gcc/m2/gm2-compiler/PCBuild.bnf
+++ b/gcc/m2/gm2-compiler/PCBuild.bnf
@@ -1252,12 +1252,14 @@ NamedOperand := '[' Ident ']' =:
 
 AsmOperandName := [ NamedOperand ] =:
 
-AsmOperands := string [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ] =:
+AsmOperands  := ConstExpression ':' AsmList [ ':' AsmList [ ':' TrashList ] ]
+              =:
 
-AsmList     := [ AsmElement ] { ',' AsmElement } =:
+AsmList      := [ AsmElement ] { ',' AsmElement } =:
 
-AsmElement := AsmOperandName string '(' Expression ')' =:
+AsmElement   := AsmOperandName ConstExpression '(' Expression ')'
+              =:
 
-TrashList := [ string ] { ',' string } =:
+TrashList    := [ ConstExpression ] { ',' ConstExpression } =:
 
 FNB
diff --git a/gcc/m2/gm2-compiler/PHBuild.bnf b/gcc/m2/gm2-compiler/PHBuild.bnf
index 79ebcde9732..c829a6ee0b0 100644
--- a/gcc/m2/gm2-compiler/PHBuild.bnf
+++ b/gcc/m2/gm2-compiler/PHBuild.bnf
@@ -1227,14 +1227,14 @@ NamedOperand := '[' Ident ']' =:
 
 AsmOperandName := [ NamedOperand ] =:
 
-AsmOperands  := AsmOperandName string [ ':' AsmList [ ':' AsmList [ ':' TrashList ] ] ]
-             =:
+AsmOperands  := ConstExpression ':' AsmList [ ':' AsmList [ ':' TrashList ] ]
+              =:
 
 AsmList      := [ AsmElement ] { ',' AsmElement } =:
 
-AsmElement   := string '(' Expression ')'
-             =:
+AsmElement   := AsmOperandName ConstExpression '(' Expression ')'
+              =:
 
-TrashList    := [ string ] { ',' string } =:
+TrashList    := [ ConstExpression ] { ',' ConstExpression } =:
 
 FNB
diff --git a/gcc/m2/gm2-compiler/SymbolTable.def b/gcc/m2/gm2-compiler/SymbolTable.def
index c7f584bfb09..5249952e22f 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.def
+++ b/gcc/m2/gm2-compiler/SymbolTable.def
@@ -998,10 +998,14 @@ PROCEDURE MakeRegInterface () : CARDINAL ;
                      sym, at position, i.
                      The string symbol will either be a register name or a constraint.
                      The object is an optional Modula-2 variable or constant symbol.
+                     read and write are the quadruple numbers representing any read
+                     or write operation.
 *)
 
-PROCEDURE PutRegInterface (sym: CARDINAL; i: CARDINAL;
-                           n: Name; string, object: CARDINAL) ;
+PROCEDURE PutRegInterface (tok: CARDINAL;
+                           sym: CARDINAL; i: CARDINAL;
+                           n: Name; string, object: CARDINAL;
+                           read, write: CARDINAL) ;
 
 
 (*
@@ -1010,7 +1014,8 @@ PROCEDURE PutRegInterface (sym: CARDINAL; i: CARDINAL;
 *)
 
 PROCEDURE GetRegInterface (sym: CARDINAL; i: CARDINAL;
-                           VAR n: Name; VAR string, object: CARDINAL) ;
+                           VAR tok: CARDINAL; VAR n: Name;
+                           VAR string, object: CARDINAL) ;
 
 
 (*
diff --git a/gcc/m2/gm2-compiler/SymbolTable.mod b/gcc/m2/gm2-compiler/SymbolTable.mod
index 1ea5fee9d3e..ad3788d885b 100644
--- a/gcc/m2/gm2-compiler/SymbolTable.mod
+++ b/gcc/m2/gm2-compiler/SymbolTable.mod
@@ -142,9 +142,10 @@ TYPE
                 END ;
 
    PtrToAsmConstraint = POINTER TO RECORD
-                                      name: Name ;
-                                      str : CARDINAL ;   (* regnames or constraints     *)
-                                      obj : CARDINAL ;   (* list of M2 syms             *)
+                                      tokpos: CARDINAL ;
+                                      name  : Name ;
+                                      str   : CARDINAL ;   (* regnames or constraints     *)
+                                      obj   : CARDINAL ;   (* list of M2 syms             *)
                                    END ;
 
    ModuleCtor = RECORD
@@ -2335,6 +2336,46 @@ BEGIN
 END IsDeclaredIn ;
 
 
+(*
+   SetFirstUsed - assigns the FirstUsed field in at to tok providing
+                  it has not already been set.
+*)
+
+PROCEDURE SetFirstUsed (tok: CARDINAL; VAR at: Where) ;
+BEGIN
+   IF at.FirstUsed = UnknownTokenNo
+   THEN
+      at.FirstUsed := tok
+   END
+END SetFirstUsed ;
+
+
+(*
+   PutFirstUsed - sets tok to the first used providing it has not already been set.
+                  It also includes the read and write quad into the usage list
+                  providing the quad numbers are not 0.
+*)
+
+PROCEDURE PutFirstUsed (object: CARDINAL; tok: CARDINAL; read, write: CARDINAL) ;
+VAR
+   pSym: PtrToSymbol ;
+BEGIN
+   IF IsVar (object)
+   THEN
+      pSym := GetPsym (object) ;
+      SetFirstUsed (tok, pSym^.Var.At) ;
+      IF read # 0
+      THEN
+         PutReadQuad (object, GetMode (object), read)
+      END ;
+      IF write # 0
+      THEN
+         PutWriteQuad (object, GetMode (object), write)
+      END
+   END
+END PutFirstUsed ;
+
+
 (*
    MakeGnuAsm - create a GnuAsm symbol.
 *)
@@ -2345,12 +2386,12 @@ VAR
    Sym : CARDINAL ;
 BEGIN
    NewSym(Sym) ;
-   pSym := GetPsym(Sym) ;
+   pSym := GetPsym (Sym) ;
    WITH pSym^ DO
       SymbolType := GnuAsmSym ;
       WITH GnuAsm DO
          String   := NulSym ;
-         InitWhereDeclared(At) ;
+         InitWhereDeclared (At) ;
          Inputs   := NulSym ;
          Outputs  := NulSym ;
          Trashed  := NulSym ;
@@ -2370,7 +2411,7 @@ PROCEDURE PutGnuAsm (sym: CARDINAL; string: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   Assert(IsConstString(string)) ;
+   Assert (IsConstString (string)) ;
    pSym := GetPsym(sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
@@ -2397,7 +2438,7 @@ BEGIN
    WITH pSym^ DO
       CASE SymbolType OF
 
-      GnuAsmSym: RETURN( GnuAsm.String )
+      GnuAsmSym: RETURN GnuAsm.String
 
       ELSE
          InternalError ('expecting GnuAsm symbol')
@@ -2435,7 +2476,7 @@ PROCEDURE PutGnuAsmInput (sym: CARDINAL; in: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(sym) ;
+   pSym := GetPsym (sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
@@ -2456,7 +2497,7 @@ PROCEDURE PutGnuAsmTrash (sym: CARDINAL; trash: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(sym) ;
+   pSym := GetPsym (sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
@@ -2477,11 +2518,11 @@ PROCEDURE GetGnuAsmInput (sym: CARDINAL) : CARDINAL ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(sym) ;
+   pSym := GetPsym (sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
-      GnuAsmSym: RETURN( GnuAsm.Inputs )
+      GnuAsmSym: RETURN GnuAsm.Inputs
 
       ELSE
          InternalError ('expecting PutGnuAsm symbol')
@@ -2498,11 +2539,11 @@ PROCEDURE GetGnuAsmOutput (sym: CARDINAL) : CARDINAL ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(sym) ;
+   pSym := GetPsym (sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
-      GnuAsmSym: RETURN( GnuAsm.Outputs )
+      GnuAsmSym: RETURN GnuAsm.Outputs
 
       ELSE
          InternalError ('expecting PutGnuAsm symbol')
@@ -2519,11 +2560,11 @@ PROCEDURE GetGnuAsmTrash (sym: CARDINAL) : CARDINAL ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(sym) ;
+   pSym := GetPsym (sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
-      GnuAsmSym: RETURN( GnuAsm.Trashed )
+      GnuAsmSym: RETURN GnuAsm.Trashed
 
       ELSE
          InternalError ('expecting PutGnuAsm symbol')
@@ -2540,7 +2581,7 @@ PROCEDURE PutGnuAsmVolatile (Sym: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(Sym) ;
+   pSym := GetPsym (Sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
@@ -2561,7 +2602,7 @@ PROCEDURE PutGnuAsmSimple (Sym: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
 BEGIN
-   pSym := GetPsym(Sym) ;
+   pSym := GetPsym (Sym) ;
    WITH pSym^ DO
       CASE SymbolType OF
 
@@ -2583,13 +2624,13 @@ VAR
    pSym: PtrToSymbol ;
    Sym : CARDINAL ;
 BEGIN
-   NewSym(Sym) ;
-   pSym := GetPsym(Sym) ;
+   NewSym (Sym) ;
+   pSym := GetPsym (Sym) ;
    WITH pSym^ DO
       SymbolType := InterfaceSym ;
       WITH Interface DO
-         Parameters := InitIndex(1) ;
-         InitWhereDeclared(At)
+         Parameters := InitIndex (1) ;
+         InitWhereDeclared (At)
       END
    END ;
    RETURN( Sym )
@@ -2601,9 +2642,13 @@ END MakeRegInterface ;
                      sym, at position, i.
                      The string symbol will either be a register name or a constraint.
                      The object is an optional Modula-2 variable or constant symbol.
+                     read and write are the quadruple numbers representing any read
+                     or write operation.
 *)
 
-PROCEDURE PutRegInterface (sym: CARDINAL; i: CARDINAL; n: Name; string, object: CARDINAL) ;
+PROCEDURE PutRegInterface (tok: CARDINAL;
+                           sym: CARDINAL; i: CARDINAL; n: Name; string, object: CARDINAL;
+                           read, write: CARDINAL) ;
 VAR
    pSym : PtrToSymbol ;
    p    : PtrToAsmConstraint ;
@@ -2623,10 +2668,12 @@ BEGIN
                        InternalError ('expecting to add parameters sequentially')
                     END ;
                     WITH p^ DO
-                       name := n ;
-                       str  := string ;
-                       obj  := object
-                    END
+                       tokpos := tok ;
+                       name   := n ;
+                       str    := string ;
+                       obj    := object
+                    END ;
+                    PutFirstUsed (object, tok, read, write)
 
       ELSE
          InternalError ('expecting Interface symbol')
@@ -2640,7 +2687,8 @@ END PutRegInterface ;
                      sym, from position, i.
 *)
 
-PROCEDURE GetRegInterface (sym: CARDINAL; i: CARDINAL; VAR n: Name; VAR string, object: CARDINAL) ;
+PROCEDURE GetRegInterface (sym: CARDINAL; i: CARDINAL;
+                           VAR tok: CARDINAL; VAR n: Name; VAR string, object: CARDINAL) ;
 VAR
    pSym: PtrToSymbol ;
    p   : PtrToAsmConstraint ;
@@ -2653,11 +2701,13 @@ BEGIN
                     THEN
                        p := Indexing.GetIndice(Interface.Parameters, i) ;
                        WITH p^ DO
+                          tok    := tokpos ;
                           n      := name ;
                           string := str ;
                           object := obj
                        END
                     ELSE
+                       tok    := UnknownTokenNo ;
                        n      := NulName ;
                        string := NulSym ;
                        object := NulSym
@@ -8953,20 +9003,20 @@ BEGIN
       CASE SymbolType OF
 
       DefImpSym: WITH DefImp DO
-                    CheckForUnknowns( name, ExportQualifiedTree,
-                                      'EXPORT QUALIFIED' ) ;
-                    CheckForUnknowns( name, ExportUnQualifiedTree,
-                                      'EXPORT UNQUALIFIED' ) ;
-                    CheckForSymbols ( ExportRequest,
-                                      'requested by another modules import (symbols have not been exported by the appropriate definition module)' ) ;
-                    CheckForUnknowns( name, Unresolved, 'unresolved' ) ;
-                    CheckForUnknowns( name, LocalSymbols, 'locally used' )
+                    CheckForUnknowns (name, ExportQualifiedTree,
+                                      'EXPORT QUALIFIED') ;
+                    CheckForUnknowns (name, ExportUnQualifiedTree,
+                                      'EXPORT UNQUALIFIED') ;
+                    CheckForSymbols  (ExportRequest,
+                                      'requested by another modules import (symbols have not been exported by the appropriate definition module)') ;
+                    CheckForUnknowns (name, Unresolved, 'unresolved') ;
+                    CheckForUnknowns (name, LocalSymbols, 'locally used')
                  END |
       ModuleSym: WITH Module DO
-                    CheckForUnknowns( name, Unresolved, 'unresolved' ) ;
-                    CheckForUnknowns( name, ExportUndeclared, 'exported but undeclared' ) ;
-                    CheckForUnknowns( name, ExportTree, 'exported but undeclared' ) ;
-                    CheckForUnknowns( name, LocalSymbols, 'locally used' )
+                    CheckForUnknowns (name, Unresolved, 'unresolved') ;
+                    CheckForUnknowns (name, ExportUndeclared, 'exported but undeclared') ;
+                    CheckForUnknowns (name, ExportTree, 'exported but undeclared') ;
+                    CheckForUnknowns (name, LocalSymbols, 'locally used')
                  END
 
       ELSE
diff --git a/gcc/testsuite/gm2/pim/pass/fooasm3.mod b/gcc/testsuite/gm2/pim/pass/fooasm3.mod
new file mode 100644
index 00000000000..84e95ccc481
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/pass/fooasm3.mod
@@ -0,0 +1,12 @@
+MODULE fooasm3 ;
+
+VAR x: INTEGER;
+
+PROCEDURE test;
+BEGIN
+  ASM("" : "=rm"(x));  (* x is an output.  *)
+END test;
+
+BEGIN
+   test
+END fooasm3.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-08 23:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-08 23:56 [gcc r14-1638] PR modula2/110126 variables are reported as unused when referenced by ASM Gaius Mulley

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).