blob: b5213244843de9cfc651afb18f0251ec2d19f6c5 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
 | /* FIXME: Finer imports */
import java.util.*;
import java.io.*;
public class Main
{
   private static Parameters PARAMETERS;
   public static void main (final String... args)
   {
      final FileWriter output;
      PARAMETERS = new Parameters(args);
      if (!PARAMETERS.are_valid())
      {
         return;
      }
      try
      {
         ModelFile.load_file(PARAMETERS.get_model_file());
      }
      catch (final Exception e)
      {
         System.err.println
         (
            "[E] Could not load model file \""
            + PARAMETERS.get_model_file()
            + "\":"
         );
         e.printStackTrace();
         return;
      }
      create_instances();
   }
   private static void create_instances ()
   {
      final Collection<VHDLEntity> futur_candidates;
      final Deque<VHDLEntity> candidates;
      final Collection<VHDLEntity> processed_candidates;
      boolean is_stuck;
      futur_candidates = new ArrayList<VHDLEntity>();
      candidates = new ArrayDeque<VHDLEntity>();
      processed_candidates = new ArrayList<VHDLEntity>();
      futur_candidates.addAll(VHDLEntity.get_all());
      while (!futur_candidates.isEmpty())
      {
         is_stuck = true;
         candidates.addAll(futur_candidates);
         futur_candidates.clear();
         while (!candidates.isEmpty())
         {
            final VHDLEntity e;
            boolean is_ready;
            e = candidates.pop();
            is_ready = true;
            for (final VHDLComponent cmp: e.get_architecture().get_components())
            {
               if (!processed_candidates.contains(cmp.get_destination()))
               {
                  is_ready = false;
                  break;
               }
            }
            if (is_ready)
            {
               is_stuck = false;
               e.generate_instance();
               processed_candidates.add(e);
            }
            else
            {
               futur_candidates.add(e);
            }
         }
         if (is_stuck)
         {
            System.err.println("[F] Unable to create all the instances...");
            System.err.println
            (
               "[E] The following entites might form a circular dependency:"
            );
            for (final VHDLEntity e: futur_candidates)
            {
               System.err.println("[E] Entity " + e.get_id());
            }
            System.exit(-1);
         }
      }
   }
   public static Parameters get_parameters ()
   {
      return PARAMETERS;
   }
}
 |