| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 00:05:39 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 00:05:39 +0200 |
| commit | f1dfb1eb04a705521238dba64e09bb9ecdea794f (patch) | |
| tree | e8cd8d7349cd5008160e4a19c1e788241dd11b7b | |
| parent | ee9d405bc917be3f596ccd2ffd2d7ddc01687d31 (diff) | |
Starting to get an idea of how it's going to work.
| -rw-r--r-- | instance-calculator/src/Main.java | 85 | ||||
| -rw-r--r-- | instance-calculator/src/ModelFile.java | 262 | ||||
| -rw-r--r-- | instance-calculator/src/Parameters.java | 63 | ||||
| -rw-r--r-- | instance-calculator/src/ProcessInstance.java | 9 | ||||
| -rw-r--r-- | instance-calculator/src/QuickParser.java | 58 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLArchitecture.java | 30 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLComponent.java | 28 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLEntity.java | 18 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLProcess.java | 19 | ||||
| -rw-r--r-- | instance-calculator/src/Waveforms.java | 64 |
10 files changed, 635 insertions, 1 deletions
diff --git a/instance-calculator/src/Main.java b/instance-calculator/src/Main.java new file mode 100644 index 0000000..488b9bb --- /dev/null +++ b/instance-calculator/src/Main.java @@ -0,0 +1,85 @@ +/* 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; + } + } + + private static void create_instances () + { + /* + * FuturCandidates <- All Architecture. + * Candidates <- emptyset + * Set ProcessedCandidates <- emptyset. + * + * while (!isEmpty(FuturCandidates)) + * { + * is_stuck = True; + * Candidates.addAll(FuturCandidates); + * FuturCandidates.setLength(0); + * + * while (!isEmpty(candidates)) + * { + * a = Candidates.pop(); + * + * for (c: a.component) + * { + * if (!contains(c.target, ProcessedCandidates)) + * { + * FuturCandidates.push(a); + * continue; + * } + * } + * + * is_stuck = False; + * + * a.instantiate_all_processes(); + * + * for (c: a.component) + * { + * a.integrate_instanciated_processes_from(c); + * } + * + * ProcessedCandidates.add(a); + * } + * + * if (is_stuck) + * { + * Error. + * } + * } + */ + } +} diff --git a/instance-calculator/src/ModelFile.java b/instance-calculator/src/ModelFile.java new file mode 100644 index 0000000..7ca0899 --- /dev/null +++ b/instance-calculator/src/ModelFile.java @@ -0,0 +1,262 @@ +import java.io.*; + +public class ModelFile +{ + public static boolean load_file + ( + final String filename + ) + throws FileNotFoundException + { + final QuickParser qp; + String[] input; + boolean success; + + qp = new QuickParser(filename); + + for (;;) + { + try + { + input = qp.parse_line(); + + if (input == null) + { + qp.finalize(); + + return false; + } + else if (input.length == 0) + { + qp.finalize(); + + break; + } + } + catch (final IOException e) + { + System.err.println + ( + "[E] IO error while parsing file \"" + + filename + + "\":" + /* FIXME: can be null */ + + e.getMessage() + ); + + return false; + } + + if (input[0].equals("add_element")) + { + success = handle_add_element(input); + } + else if (input[0].equals("is_accessed_by")) + { + success = handle_is_accessed_by(input); + } + else if (input[0].equals("is_waveform_of")) + { + success = handle_is_waveform_of(input); + } + else if (input[0].equals("is_port_of")) + { + success = handle_is_port_of(input); + } + else if (input[0].equals("is_architecture_of")) + { + success = handle_is_architecture_of(input); + } + else if (input[0].equals("belongs_to_architecture")) + { + success = handle_belongs_to_architecture(input); + } + else if (input[0].equals("is_component_of")) + { + success = handle_is_component_of(input); + } + else if (input[0].equals("port_maps")) + { + success = handle_port_maps(input); + } + else + { + continue; + } + + if (!success) + { + System.err.println + ( + "[E] An erroneous instruction was found in file \"" + + filename + + "\"." + ); + + try + { + qp.finalize(); + } + catch (final Exception e) + { + System.err.println("[E] Additionally:"); + e.printStackTrace(); + } + + return false; + } + } + + return true; + } + + private static boolean handle_add_element + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + if (input.equals("entity")) + { + VHDLEntity.add_element(input[2]); + } + else if (input.equals("architecture")) + { + VHDLArchitecture.add_element(input[2]); + } + else if (input.equals("process")) + { + VHDLProcess.add_element(input[2]); + } + else if (input.equals("component")) + { + VHDLComponent.add_element(input[2]); + } + + return true; + } + + private static boolean handle_is_accessed_by + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + return VHDLProcess.handle_is_accessed_by(input[1], input[2]); + } + + private static boolean handle_is_waveform_of + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + Waveforms.register_map(input[1], input[2]); + + return true; + } + + private static boolean handle_is_port_of + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + VHDLEntity.handle_is_port_of(input[1], input[2]); + + return true; + } + + private static boolean handle_is_architecture_of + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + VHDLArchitecture.handle_is_architecture_of(input[1], input[2]); + + return true; + } + + private static boolean handle_belongs_to_architecture + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + VHDLArchitecture.handle_belongs_to_architecture(input[1], input[2]); + + return true; + } + + private static boolean handle_belongs_to_architecture + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + VHDLArchitecture.handle_belongs_to_architecture(input[1], input[2]); + + return true; + } + + private static boolean handle_is_component_of + ( + final String[] input + ) + { + if (input.length != 3) + { + return false; + } + + VHDLComponent.handle_is_component_of(input[1], input[2]); + + return true; + } + + private static boolean handle_port_maps + ( + final String[] input + ) + { + if (input.length != 4) + { + return false; + } + + VHDLComponent.handle_port_maps(input[1], input[2], input[3]); + + return true; + } + + private ModelFile () {} /* Utility Class */ +} diff --git a/instance-calculator/src/Parameters.java b/instance-calculator/src/Parameters.java new file mode 100644 index 0000000..ce5e2cf --- /dev/null +++ b/instance-calculator/src/Parameters.java @@ -0,0 +1,63 @@ +public class Parameters +{ + private final String model_file; + private final String id_prefix; + private final String output_file; + private final boolean are_valid; + + public static void print_usage () + { + System.out.println + ( + "Instance-Calculator\n" + + "USAGE:\n" + + "\tjava Main <INSTRUCTIONS> <ID_PREFIX> <OUTPUT_FILE>\n" + + "PARAMETERS:\n" + + "\t<INSTRUCTIONS>\tInstruction file describing the model.\n" + + "\t<ID_PREFIX>\tPrefix for the IDs of generated paths.\n" + + "\t<OUTPUT_FILE>\tFile in which to output the generated" + + " instructions." + ); + } + + public Parameters (final String... args) + { + if (args.length != 4) + { + print_usage(); + + model_file = new String(); + id_prefix = new String(); + output_file = new String(); + + are_valid = false; + } + else + { + model_file = args[0]; + id_prefix = args[2]; + output_file = args[3]; + are_valid = true; + } + } + + public String get_model_file () + { + return model_file; + } + + public String get_id_prefix () + { + return id_prefix; + } + + public String get_output_file () + { + return output_file; + } + + public boolean are_valid () + { + return are_valid; + } +} diff --git a/instance-calculator/src/ProcessInstance.java b/instance-calculator/src/ProcessInstance.java new file mode 100644 index 0000000..580df6b --- /dev/null +++ b/instance-calculator/src/ProcessInstance.java @@ -0,0 +1,9 @@ +import java.util.*; + +public class ProcessInstance +{ + private final String id; + private String process_id; + private Map<String, String> wfm_map; + +} diff --git a/instance-calculator/src/QuickParser.java b/instance-calculator/src/QuickParser.java new file mode 100644 index 0000000..47cea27 --- /dev/null +++ b/instance-calculator/src/QuickParser.java @@ -0,0 +1,58 @@ +/* FIXME: Finer imports */ +import java.io.*; +import java.util.regex.*; +import java.util.*; + +public class QuickParser +{ + private static final Pattern instr_pattern; + private final BufferedReader buffered_reader; + + static + { + instr_pattern = Pattern.compile("\\((?<list>[a-z_0-9 \"]+)\\)"); + } + public QuickParser (final String filename) + throws FileNotFoundException + { + buffered_reader = new BufferedReader(new FileReader(filename)); + } + + public void finalize () + throws IOException + { + buffered_reader.close(); + } + + public String[] parse_line () + throws IOException + { + final List<String> result; + final Matcher matcher; + String line; + + do + { + line = buffered_reader.readLine(); + + if (line == null) + { + return new String[0]; + } + + line = line.replaceAll("\\s+"," "); + } + while (line.length() < 3 || line.startsWith(";")); + + matcher = instr_pattern.matcher(line); + + if (!matcher.find()) + { + System.err.println("[E] Invalid instruction \"" + line + "\""); + + return null; + } + + return matcher.group(1).split(" |\t"); + } +} diff --git a/instance-calculator/src/VHDLArchitecture.java b/instance-calculator/src/VHDLArchitecture.java index ffd678c..2834ab3 100644 --- a/instance-calculator/src/VHDLArchitecture.java +++ b/instance-calculator/src/VHDLArchitecture.java @@ -9,6 +9,33 @@ public class VHDLArchitecture FROM_ID = new HashMap<String, VHDLArchitecture>(); } + public static void add_element (final String id) + { + if (!FROM_ID.containsKey(id)) + { + FROM_ID.put(id, new VHDLArchitecture(id)); + } + } + + public static boolean handle_belongs_to_architecture + ( + final String unknown_id, + final String arch_id + ) + { + return false; + } + + public static boolean handle_is_architecture_of + ( + final String arch_id, + final String e_id + ) + { + return false; + } + +/******************************************************************************/ private final List<String> processes; private final List<String> components; private final String id; @@ -17,6 +44,7 @@ public class VHDLArchitecture { this.id = id; - ports = new ArrayList<String>(); + processes = new ArrayList<String>(); + components = new ArrayList<String>(); } } diff --git a/instance-calculator/src/VHDLComponent.java b/instance-calculator/src/VHDLComponent.java index 29261a7..493ba22 100644 --- a/instance-calculator/src/VHDLComponent.java +++ b/instance-calculator/src/VHDLComponent.java @@ -9,6 +9,34 @@ public class VHDLComponent FROM_ID = new HashMap<String, VHDLComponent>(); } + public static void add_element (final String id) + { + if (!FROM_ID.containsKey(id)) + { + FROM_ID.put(id, new VHDLComponent(id)); + } + } + + public static boolean handle_is_component_of + ( + final String cmp_id, + final String e_id + ) + { + return false; + } + + public static boolean handle_port_maps + ( + final String cmp_id, + final String pt_id, + final String wfm_id + ) + { + return false; + } + +/******************************************************************************/ private final Map<String, String> port_map; private final String id; diff --git a/instance-calculator/src/VHDLEntity.java b/instance-calculator/src/VHDLEntity.java index c8fa332..a5ba28c 100644 --- a/instance-calculator/src/VHDLEntity.java +++ b/instance-calculator/src/VHDLEntity.java @@ -9,6 +9,24 @@ public class VHDLEntity FROM_ID = new HashMap<String, VHDLEntity>(); } + public static void add_element (final String id) + { + if (!FROM_ID.containsKey(id)) + { + FROM_ID.put(id, new VHDLEntity(id)); + } + } + + public static boolean handle_is_port_of + ( + final String pt_id, + final String e_id + ) + { + return false; + } + +/******************************************************************************/ private final List<String> ports; private final String id; diff --git a/instance-calculator/src/VHDLProcess.java b/instance-calculator/src/VHDLProcess.java index f2f27e7..a017ef4 100644 --- a/instance-calculator/src/VHDLProcess.java +++ b/instance-calculator/src/VHDLProcess.java @@ -9,6 +9,25 @@ public class VHDLProcess FROM_ID = new HashMap<String, VHDLProcess>(); } + public static void add_element (final String id) + { + if (!FROM_ID.containsKey(id)) + { + FROM_ID.put(id, new VHDLProcess(id)); + } + } + + public static boolean handle_is_accessed_by + ( + final String wfm_id, + final String ps_id + ) + { + return false; + } + +/******************************************************************************/ + private final List<String> accessed_wfm; private final String id; diff --git a/instance-calculator/src/Waveforms.java b/instance-calculator/src/Waveforms.java new file mode 100644 index 0000000..e7a4c8c --- /dev/null +++ b/instance-calculator/src/Waveforms.java @@ -0,0 +1,64 @@ +import java.util.Map; +import java.util.HashMap; + +public class Waveforms +{ + private static final Map<String, String> FROM_WAVEFORM; + private static final Map<String, String> TO_WAVEFORM; + + static + { + FROM_WAVEFORM = new HashMap<String, String>(); + TO_WAVEFORM = new HashMap<String, String>(); + } + + private Waveforms () {} /* Utility class. */ + + public static void register_map (final String wfm_id, final String elem_id) + { + FROM_WAVEFORM.put(wfm_id, elem_id); + TO_WAVEFORM.put(elem_id, wfm_id); + } + + public static String get_id_from_waveform_id (final String wfm_id) + { + final String result; + + result = FROM_WAVEFORM.get(wfm_id); + + if (result == null) + { + System.err.println + ( + "[F] There is no element associated with waveform \"" + + wfm_id + + "\". Is the model complete?" + ); + + System.exit(-1); + } + + return result; + } + + public static String get_waveform_id_from_id (final String src_id) + { + final String result; + + result = TO_WAVEFORM.get(src_id); + + if (result == null) + { + System.err.println + ( + "[F] There is no waveform associated with the element \"" + + src_id + + "\". Is the model complete?" + ); + + System.exit(-1); + } + + return result; + } +} |


