Browse Source

+ get_int_value

florian 1 year ago
parent
commit
f29ff58ab9
4 changed files with 25 additions and 60 deletions
  1. 2 20
      compiler/i8086/n8086add.pas
  2. 3 20
      compiler/nadd.pas
  3. 2 20
      compiler/nmat.pas
  4. 18 0
      compiler/nutils.pas

+ 2 - 20
compiler/i8086/n8086add.pas

@@ -98,26 +98,8 @@ interface
             t:=nil;
 
             { load values }
-            case lt of
-              ordconstn:
-                lv:=tordconstnode(left).value;
-              pointerconstn:
-                lv:=tpointerconstnode(left).value;
-              niln:
-                lv:=0;
-              else
-                internalerror(2002080201);
-            end;
-            case rt of
-              ordconstn:
-                rv:=tordconstnode(right).value;
-              pointerconstn:
-                rv:=tpointerconstnode(right).value;
-              niln:
-                rv:=0;
-              else
-                internalerror(2002080204);
-            end;
+            lv:=get_int_value(left);
+            rv:=get_int_value(right);
 
             case nodetype of
               addn:

+ 3 - 20
compiler/nadd.pas

@@ -709,26 +709,9 @@ implementation
              t:=nil;
 
              { load values }
-             case lt of
-               ordconstn:
-                 lv:=tordconstnode(left).value;
-               pointerconstn:
-                 lv:=tpointerconstnode(left).value;
-               niln:
-                 lv:=0;
-               else
-                 internalerror(2002080202);
-             end;
-             case rt of
-               ordconstn:
-                 rv:=tordconstnode(right).value;
-               pointerconstn:
-                 rv:=tpointerconstnode(right).value;
-               niln:
-                 rv:=0;
-               else
-                 internalerror(2002080203);
-             end;
+             lv:=get_int_value(left);
+             rv:=get_int_value(right);
+
              { type checking already took care of multiplying      }
              { integer constants with pointeddef.size if necessary }
              case nodetype of

+ 2 - 20
compiler/nmat.pas

@@ -219,26 +219,8 @@ implementation
             if is_constintnode(left) or is_constpointernode(left) then
               begin
                 { load values }
-                case left.nodetype of
-                  ordconstn:
-                    lv:=tordconstnode(left).value;
-                  pointerconstn:
-                    lv:=tpointerconstnode(left).value;
-                  niln:
-                    lv:=0;
-                  else
-                    internalerror(2024041501);
-                end;
-                case right.nodetype of
-                  ordconstn:
-                    rv:=tordconstnode(right).value;
-                  pointerconstn:
-                    rv:=tpointerconstnode(right).value;
-                  niln:
-                    rv:=0;
-                  else
-                    internalerror(2024041502);
-                end;
+                lv:=get_int_value(left);
+                rv:=get_int_value(right);
 
                 case nodetype of
                   modn:

+ 18 - 0
compiler/nutils.pas

@@ -174,6 +174,9 @@ interface
     { returns true if the node has the int value l }
     function is_constintvalue(p : tnode;l : Tconstexprint) : Boolean;
 
+    { if the node is a constant node which can be an int value, this value is returned }
+    function get_int_value(p : tnode): Tconstexprint;
+
     { returns true if the node is an inline node of type i }
     function is_inlinefunction(p : tnode;i : tinlinenumber) : Boolean;
 
@@ -1629,6 +1632,21 @@ implementation
       end;
 
 
+    function get_int_value(p: tnode): Tconstexprint;
+      begin
+        case p.nodetype of
+          ordconstn:
+            result:=tordconstnode(p).value;
+          pointerconstn:
+            result:=tpointerconstnode(p).value;
+          niln:
+            result:=0;
+          else
+            internalerror(2002080202);
+        end;
+      end;
+
+
     function is_inlinefunction(p: tnode; i: tinlinenumber): Boolean;
       begin
         Result:=(p.nodetype=inlinen) and (tinlinenode(p).inlinenumber=i);