Browse Source

+ function node_not_zero and make use of it

florian 6 months ago
parent
commit
9cb6497fae
2 changed files with 12 additions and 3 deletions
  1. 2 3
      compiler/ncginl.pas
  2. 10 0
      compiler/nutils.pas

+ 2 - 3
compiler/ncginl.pas

@@ -81,7 +81,7 @@ implementation
       aasmbase,aasmdata,
       aasmbase,aasmdata,
       cgbase,pass_2,
       cgbase,pass_2,
       cpubase,procinfo,
       cpubase,procinfo,
-      nadd,ncon,ncal,
+      nadd,ncon,ncal,nutils,
       tgobj,ncgutil,
       tgobj,ncgutil,
       cgutils,cgobj,hlcgobj,
       cgutils,cgobj,hlcgobj,
       defcmp
       defcmp
@@ -999,8 +999,7 @@ implementation
       opsize: tcgsize;
       opsize: tcgsize;
     begin
     begin
       reverse:=(inlinenumber = in_bsr_x);
       reverse:=(inlinenumber = in_bsr_x);
-      not_zero:=(left.nodetype=orn) and (((is_constintnode(taddnode(left).left) and (tordconstnode(taddnode(left).left).value<>0))) or
-        ((is_constintnode(taddnode(left).right) and (tordconstnode(taddnode(left).right).value<>0))));
+      not_zero:=node_not_zero(left);
       secondpass(left);
       secondpass(left);
 
 
       opsize:=tcgsize2unsigned[left.location.size];
       opsize:=tcgsize2unsigned[left.location.size];

+ 10 - 0
compiler/nutils.pas

@@ -214,6 +214,9 @@ interface
     { Returns True if n one of its children has a type that appears in TypeList }
     { Returns True if n one of its children has a type that appears in TypeList }
     function has_node_of_type(n: TNode; TypeList: TNodeTypeSet): Boolean; {$IFDEF USEINLINE}inline;{$ENDIF USEINLINE}
     function has_node_of_type(n: TNode; TypeList: TNodeTypeSet): Boolean; {$IFDEF USEINLINE}inline;{$ENDIF USEINLINE}
 
 
+    { returns true if n is guranteed not to return an ordinal zero }
+    function node_not_zero(n : tnode) : Boolean;
+
 
 
 implementation
 implementation
 
 
@@ -1727,4 +1730,11 @@ implementation
          Result := foreachnodestatic(n, @node_in_list, @TypeList);
          Result := foreachnodestatic(n, @node_in_list, @TypeList);
        end;
        end;
 
 
+
+     function node_not_zero(n: tnode): Boolean;
+       begin
+         result:=(is_constintnode(n) and (get_int_value(n)<>0)) or
+           ((n.nodetype=orn) and (node_not_zero(taddnode(n).left) or node_not_zero(taddnode(n).right)));
+       end;
+
 end.
 end.