| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 16:51:09 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-08-29 16:51:09 +0200 |
| commit | ea11fdc81ed7a8df14868476c04bf2fe7c7b6393 (patch) | |
| tree | b71364022fb3d670fb011916c9395781a5082306 | |
| parent | 9a5e79dfd1c6829b052ab7cf0cb7a79afd25eb72 (diff) | |
Most of the program's logic seems to be there...
| -rw-r--r-- | Makefile | 7 | ||||
| -rw-r--r-- | instance-calculator/Makefile | 11 | ||||
| -rw-r--r-- | instance-calculator/src/Main.java | 104 | ||||
| -rw-r--r-- | instance-calculator/src/ModelFile.java | 8 | ||||
| -rw-r--r-- | instance-calculator/src/Parameters.java | 6 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLArchitecture.java | 5 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLComponent.java | 5 | ||||
| -rw-r--r-- | instance-calculator/src/VHDLEntity.java | 19 |
8 files changed, 120 insertions, 45 deletions
@@ -12,6 +12,7 @@ SOL_DIR = $(TMP_DIR)/sol ## Sub-programs ################################################################ AST_TO_INSTR = ast-to-instr +INST_CALC = instance-calculator SOLVER = instr-to-kodkod PRETTY_PRINTER = sol-pretty-printer @@ -24,31 +25,37 @@ all: $(TMP_DIR) $(MODEL_DIR) $(SOL_DIR) compile: $(MAKE) -C $(AST_TO_INSTR) compile + $(MAKE) -C $(INST_CALC) compile $(MAKE) -C $(SOLVER) compile $(MAKE) -C $(PRETTY_PRINTER) compile model: $(MAKE) -C $(AST_TO_INSTR) model + $(MAKE) -C $(INST_CALC) model $(MAKE) -C $(SOLVER) model $(MAKE) -C $(PRETTY_PRINTER) model solutions: $(TMP_DIR) $(MODEL_DIR) $(SOL_DIR) $(MAKE) -C $(AST_TO_INSTR) solutions + $(MAKE) -C $(INST_CALC) solutions $(MAKE) -C $(SOLVER) solutions $(MAKE) -C $(PRETTY_PRINTER) solutions clean: $(MAKE) -C $(AST_TO_INSTR) clean + $(MAKE) -C $(INST_CALC) clean $(MAKE) -C $(SOLVER) clean $(MAKE) -C $(PRETTY_PRINTER) clean clean_model: $(MAKE) -C $(AST_TO_INSTR) clean_model + $(MAKE) -C $(INST_CALC) clean_model $(MAKE) -C $(SOLVER) clean_model $(MAKE) -C $(PRETTY_PRINTER) clean_model clean_solutions: $(MAKE) -C $(AST_TO_INSTR) clean_solutions + $(MAKE) -C $(INST_CALC) clean_solutions $(MAKE) -C $(SOLVER) clean_solutions $(MAKE) -C $(PRETTY_PRINTER) clean_solutions diff --git a/instance-calculator/Makefile b/instance-calculator/Makefile index 8da7891..356b681 100644 --- a/instance-calculator/Makefile +++ b/instance-calculator/Makefile @@ -6,7 +6,7 @@ endif #### Where to store the Instance model ifndef INSTANCE_MODEL_DIR -INSTANCE_MODEL_DIR = +INSTANCE_MODEL_DIR = $(MODEL_DIR)/instance/ endif #### Binaries @@ -43,7 +43,7 @@ CLASSPATH = "./src/" ## Makefile Magic ############################################################## SOURCES = $(wildcard src/*.java) CLASSES = $(SOURCES:.java=.class) -MODEL_FILES = $(MODEL_DIR)/structural.mod +MODEL_FILE = $(MODEL_DIR)/structural.mod OUTPUT_FILE = $(INSTANCE_MODEL_DIR)/instances.mod ## Makefile Rules ############################################################## @@ -51,18 +51,23 @@ compile: $(CLASSES) model: $(CLASSES) $(INSTANCE_MODEL_DIR) $(OUTPUT_FILE) +solutions: + clean: rm -f $(CLASSES) rm -f $(PATH_MODEL_DIR)/*.mod clean_model: rm -f $(PATH_MODEL_DIR)/*.mod + +clean_solutions: + ######## %.class: %.java $(JAVAC) -cp $(CLASSPATH) $< $(OUTPUT_FILE): $(MODEL_FILE) $(CLASSES) - $(JAVA) -cp $(CLASSPATH) Main $< $@ + $(JAVA) -cp $(CLASSPATH) Main $(MODEL_FILE) "inst_" $@ $(INSTANCE_MODEL_DIR): mkdir -p $(INSTANCE_MODEL_DIR) diff --git a/instance-calculator/src/Main.java b/instance-calculator/src/Main.java index 3835c16..b521324 100644 --- a/instance-calculator/src/Main.java +++ b/instance-calculator/src/Main.java @@ -35,45 +35,79 @@ public class Main return; } + + create_instances(); } 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(); - * - * if (a.has_components_not_in(ProcessedCandidates)) - * { - * FuturCandidates.push(a); - * } - * else - * { - * is_stuck = False; - * - * a.create_instance(); - * - * ProcessedCandidates.add(a); - * } - * } - * - * if (is_stuck) - * { - * Error. - * } - * } - */ + 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 () diff --git a/instance-calculator/src/ModelFile.java b/instance-calculator/src/ModelFile.java index 929c348..b873c3b 100644 --- a/instance-calculator/src/ModelFile.java +++ b/instance-calculator/src/ModelFile.java @@ -120,19 +120,19 @@ public class ModelFile return false; } - if (input.equals("entity")) + if (input[1].equals("entity")) { VHDLEntity.add_element(input[2]); } - else if (input.equals("architecture")) + else if (input[1].equals("architecture")) { VHDLArchitecture.add_element(input[2]); } - else if (input.equals("process")) + else if (input[1].equals("process")) { VHDLProcess.add_element(input[2]); } - else if (input.equals("component")) + else if (input[1].equals("component")) { VHDLComponent.add_element(input[2]); } diff --git a/instance-calculator/src/Parameters.java b/instance-calculator/src/Parameters.java index ce5e2cf..e01f912 100644 --- a/instance-calculator/src/Parameters.java +++ b/instance-calculator/src/Parameters.java @@ -22,7 +22,7 @@ public class Parameters public Parameters (final String... args) { - if (args.length != 4) + if (args.length != 3) { print_usage(); @@ -35,8 +35,8 @@ public class Parameters else { model_file = args[0]; - id_prefix = args[2]; - output_file = args[3]; + id_prefix = args[1]; + output_file = args[2]; are_valid = true; } } diff --git a/instance-calculator/src/VHDLArchitecture.java b/instance-calculator/src/VHDLArchitecture.java index 0a61a24..09576e3 100644 --- a/instance-calculator/src/VHDLArchitecture.java +++ b/instance-calculator/src/VHDLArchitecture.java @@ -87,6 +87,11 @@ public class VHDLArchitecture } } + public Collection<VHDLComponent> get_components () + { + return components; + } + public void add_waveform (final VHDLWaveform wfm) { if (!waveforms.contains(wfm)) diff --git a/instance-calculator/src/VHDLComponent.java b/instance-calculator/src/VHDLComponent.java index b0f8de2..6803a57 100644 --- a/instance-calculator/src/VHDLComponent.java +++ b/instance-calculator/src/VHDLComponent.java @@ -56,6 +56,11 @@ public class VHDLComponent destination = dest; } + public VHDLEntity get_destination () + { + return destination; + } + public void set_architecture (final VHDLArchitecture arch) { parent = arch; diff --git a/instance-calculator/src/VHDLEntity.java b/instance-calculator/src/VHDLEntity.java index e5ab4eb..7c29e63 100644 --- a/instance-calculator/src/VHDLEntity.java +++ b/instance-calculator/src/VHDLEntity.java @@ -9,6 +9,11 @@ public class VHDLEntity FROM_ID = new HashMap<String, VHDLEntity>(); } + public static Collection<VHDLEntity> get_all () + { + return FROM_ID.values(); + } + public static void add_element (final String id) { if (!FROM_ID.containsKey(id)) @@ -64,6 +69,11 @@ public class VHDLEntity this.waveform_instances = new ArrayList<VHDLWaveform.Instance>(); } + public String get_id () + { + return id; + } + public void add_port (final String pt) { if (!ports.contains(pt)) @@ -77,6 +87,11 @@ public class VHDLEntity architecture = arch; } + public VHDLArchitecture get_architecture () + { + return architecture; + } + public Collection<VHDLProcess.Instance> get_process_instances () { return process_instances; @@ -86,4 +101,8 @@ public class VHDLEntity { return waveform_instances; } + + public void generate_instance () + { + } } |


