1 //
2 // Copyright (c) 2010-2019 Antmicro
3 //
4 //  This file is licensed under the MIT License.
5 //  Full license text is available in 'licenses/MIT.txt'.
6 //
7 
8 using System.Collections.Generic;
9 using System.Linq;
10 
11 namespace Antmicro.Renode.PlatformDescription.Syntax
12 {
13     public class IrqDestinations
14     {
IrqDestinations(IrqReceiver destinationPeripheral, IEnumerable<SingleOrMultiIrqEnd> destinations)15         public IrqDestinations(IrqReceiver destinationPeripheral, IEnumerable<SingleOrMultiIrqEnd> destinations)
16         {
17             DestinationPeripheral = destinationPeripheral;
18             Destinations = destinations;
19         }
20 
ToString()21         public override string ToString()
22         {
23             return $"{DestinationPeripheral.ToShortString()}@{PrettyPrintIrqEnds(Destinations.SelectMany(x => x.Ends))}";
24         }
25 
26         public IrqReceiver DestinationPeripheral { get; private set; }
27         public IEnumerable<SingleOrMultiIrqEnd> Destinations { get; private set; }
28 
PrettyPrintIrqEnds(IEnumerable<IrqEnd> ends)29         private static string PrettyPrintIrqEnds(IEnumerable<IrqEnd> ends)
30         {
31             if(ends.Count() == 1)
32             {
33                 return ends.Single().ToShortString();
34             }
35             return string.Format("[{0}]", ends.Select(x => x.ToShortString()).Aggregate((x, y) => x + "," + y));
36         }
37     }
38 }
39