1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System; 8 using ELFSharp.ELF.Sections; 9 10 namespace Antmicro.Renode.Peripherals.Bus 11 { 12 public static class ISymbolEntryExtensions 13 { GetValue(this ISymbolEntry @this)14 public static ulong GetValue(this ISymbolEntry @this) 15 { 16 if(@this is SymbolEntry<uint> entryUInt32) 17 { 18 return entryUInt32.Value; 19 } 20 if(@this is SymbolEntry<ulong> entryUInt64) 21 { 22 return entryUInt64.Value; 23 } 24 throw new ArgumentException(ExceptionMessage); 25 } 26 GetSize(this ISymbolEntry @this)27 public static ulong GetSize(this ISymbolEntry @this) 28 { 29 if(@this is SymbolEntry<uint> entryUInt32) 30 { 31 return entryUInt32.Size; 32 } 33 if(@this is SymbolEntry<ulong> entryUInt64) 34 { 35 return entryUInt64.Size; 36 } 37 throw new ArgumentException(ExceptionMessage); 38 } 39 40 private const string ExceptionMessage = "Unsupported SymbolEntry type"; 41 } 42 } 43