summaryrefslogtreecommitdiff
blob: 52c3a8e56c8bfb2e841d6a8300033b9ab600a70d (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
118
119
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;

import java.util.Collection;
import java.util.Stack;

public class Main
{
   private static final XPathExpression XPE_FIND_ALL_VHDL_FILES;
   private static Parameters PARAMETERS;

   static
   {
      XPE_FIND_ALL_VHDL_FILES =
         XMLManager.compile_or_die
            (
               "./*/*/el[@kind=\"design_file\"][@file]"
         );
   }

   public static void main (final String... args)
   {
      final Document root;
      final Collection<Node> vhdl_files;

      PARAMETERS = new Parameters(args);

      if (!PARAMETERS.are_valid())
      {
         return;
      }

      try
      {
         root = XMLManager.get_document(PARAMETERS.get_xml_file());
      }
      catch (final Exception e)
      {
         System.err.println
         (
            "[E] Could not load XML file \""
            + PARAMETERS.get_xml_file()
            + "\":"
         );

         e.printStackTrace();

         return;
      }

      try
      {
         vhdl_files =
            XMLManager.node_list_to_node_collection
            (
               (NodeList) XPE_FIND_ALL_VHDL_FILES.evaluate
               (
                  root,
                  XPathConstants.NODESET
               )
            );
      }
      catch (final XPathExpressionException xpee)
      {
         System.err.println
         (
            "[E] Something went wrong when looking for the VHDL files:"
         );

         xpee.printStackTrace();

         return;
      }
   }

   private static void parse_content (final Collection<Node> vhdl_files)
   {
      /* Stack highly recommended over FIFO (you don't want to grow large). */
      final Stack<ParsableXML> waiting_list;

      waiting_list = new Stack<ParsableXML>();

      for (final Node f: vhdl_files)
      {
         waiting_list.push(new VHDLFile(null, f));
      }

      while (!waiting_list.isEmpty())
      {
         final Collection<ParsableXML> children;

         try
         {
            children = waiting_list.pop().parse();
         }
         catch (final XPathExpressionException xpee)
         {
            System.err.println
            (
               "[E] Something went wrong while parsing the XML file:"
            );

            xpee.printStackTrace();

            return;
         }

         for (final ParsableXML c: children)
         {
            waiting_list.push(c);
         }
      }
   }
}