summaryrefslogtreecommitdiff
blob: 6b0d906119b3da5cb2a8be738b52ca32e4a3fbca (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
package hastabel_sol_printer;

import hastabel.World;
import hastabel.lang.Formula;
import hastabel.lang.Element;
import hastabel.lang.Predicate;
import hastabel.lang.Type;

import java.util.Map;
import java.util.HashMap;
import java.util.List;

import java.util.stream.Collectors;

import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

   public static void main (final String... args)
   {
      final Map<String, Map<Element, Element>> str_funs;
      final Map<Element, Element> waveforms;
      final Parameters params;
      final World world;

      str_funs = new HashMap<String, Map<Element, Element>>();
      waveforms = new HashMap<Element, Element>();

      System.out.println("#### HaStABeL Solutions Pretty Printer ####");
      System.out.println("# Parsing parameters...");

      params = new Parameters(args);

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

      world = new World();

      System.out.println("# Loading model...");

      load_model(world, params);

      if (!world.is_valid())
      {
         System.out.println("# Failure.");

         return;
      }

      /** FIXME: Waveforms are VHDL specific. **/
      System.out.println("# Isolating waveforms & string functions.");
      //isolate_waveforms(world, waveforms);
      //string_functions(world, waveforms, str_funs);

      /* I don't think this is needed */
      //System.out.println("# Modeling graphs in first-order...");
      //world.ensure_first_order();

      for (final String pred_name: params.get_target_predicates())
      {
         final String pp_file;

         pp_file = params.get_pretty_print_file_for(pred_name);

         if (pp_file == null)
         {
            System.err.println
            (
               "[E] Could not find pretty print file for predicate \""
               + pred_name
               + "\"."
            );
         }
         else
         {
            print_solutions_of(world, pred_name, pp_file);
         }
      }
   }

   private static void print_solutions_of
   (
      final World world,
      final String pred_name,
      final String pp_file
   )
   {
      final List<String> naming;
      final Predicate pred;
      final String pp_template;

      pred = world.get_predicates_manager().get(pred_name);
      pp_template = null; //file_to_pp_template(pp_file);

      if (pred == null)
      {
         System.err.println("[E] Could not find predicate \"" + pred + "\".");

         return;
      }

      if (pp_template == null)
      {
         return;
      }

      naming = pred.get_naming();

      for (final List<Element> member: pred.get_members())
      {
         for (int i = (member.size() - 1); i >= 0; i--)
         {
         }
      }
   }

   private static void load_file (final World world, final String filename)
   {
      try
      {
         System.out.println("# Loading \"" + filename + "\"...");
         world.load(filename);
      }
      catch (final IOException ioe)
      {
         System.err.println
         (
            "[E] IOException when loading \""
            + filename
            + "\":\n"
            + ioe.getMessage()
         );

         world.invalidate();
      }
   }

   private static void load_model
   (
      final World world,
      final Parameters params
   )
   {
      for (final String level_file: params.get_level_files())
      {
         load_file(world, level_file);

         if (!world.is_valid())
         {
            return;
         }
      }

      for (final String model_file: params.get_model_files())
      {
         load_file(world, model_file);

         if (!world.is_valid())
         {
            return;
         }
      }
   }

   private static void isolate_waveforms
   (
      final World world,
      final Map<Element, Element> waveforms
   )
   {
      final Predicate is_waveform_of;

      is_waveform_of = world.get_predicates_manager().get("is_waveform_of");
   }
}