/// <summary> /// We compute index in array. /// </summary> /// <param name="array"></param> /// <param name="index"></param> /// <returns></returns> public Operand IndexInArray([NotNull] Operand array, [NotNull] Operand index) { // We optimize if array is fixed. if (array.IsFixed) { // TODO: for now ignore. } // We can perform some validation if array size is known. if (index.IsFixed && array.ArraySize != Pin.DynamicArray) { // We allow UInt and Int indices. if (index.Format == PinFormat.Integer) { if ((int)index.Value < 0 || (int)index.Value >= array.ArraySize) { throw new IndexOutOfRangeException("Access out of range is detected at compile time."); } } else if (index.Format == PinFormat.Integerx2) { if ((uint)index.Value >= array.ArraySize) { throw new IndexOutOfRangeException("Access out of range is detected at compile time."); } } } // We emit operation. Operand ret = CreateTemporary(array.Format, Pin.NotArray); compiler.IndexInArray(array.Name, index.Name, ret.Name); return(ret); }