Extending Integers

This procedure extends integers to new integer type.
Procedure TExpression.ExtendInteger (NewIntegerType: TIntegerTypeSet);
Var upCode: LongRec;
    TempValue: LongRec absolute upCode;
begin
  TempValue := Value.LongRec;
  Case Location of
    elConstant: begin
                  If not (it16Bit in NewIntegerType) then
                    begin
                      Integer (TempValue.WordL) := ShortInt (Lo (TempValue.WordL));
                      If itUnsigned in NewIntegerType then TempValue.Byte1 := 0;
                    end;
                  If not (it32Bit in NewIntegerType)then
                    begin
                      TempValue.Long := Integer (TempValue.WordL);
                      If itUnsigned in NewIntegerType then TempValue.WordH := 0;
                    end;
                  Value.LongRec := TempValue;
                end;
    else begin
           upCode.Long := 0;
           If (it16Bit in NewIntegerType) and not (it16Bit in DataType) then
             begin
               upCode.Byte0 := CBW;
               If itUnsigned in DataType then upCode.WordL := XOR_AH_AH;
             end;
           If (it32Bit in NewIntegerType) and not (it32Bit in DataType) then
             begin
               Include (UsedRegisters, urDX);
               upCode.Byte2 := CWD;
               If itUnsigned in DataType then upCode.WordH := XOR_DX_DX;
             end;
           If (upCode.Long <> 0) or ((Location = elPointerToMemory) and not (it16Bit in NewIntegerType)) then
             begin
               Calculate;
               LoadExpressionToRegisters (urAX);
               If upCode.WordL <> 0 then
                 begin
                   If upCode.Byte1 = 0 then GenerateInstruction_Byte (upCode.Byte0)
                     else GenerateInstruction_TwoBytes (upCode.Byte0, upCode.Byte1);
                 end;
               If upCode.WordH <> 0 then
                 begin
                   If upCode.Byte3 = 0 then GenerateInstruction_Byte (upCode.Byte2)
                     else GenerateInstruction_TwoBytes (upCode.Byte2, upCode.Byte3);
                 end;
               EndIntermediateCodeSubroutine;
             end;
         end;
  end;
  DataType := NewIntegerType;
end;
 
 
 
© 2017 Turbo Pascal | Privacy Policy