| summaryrefslogtreecommitdiff |
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-26 14:32:28 +0200 |
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2017-07-26 14:32:28 +0200 |
| commit | 5f06e34bc24876739c1d4af1d45f7cb322a19559 (patch) | |
| tree | 38363a28b472610d5dc8391baeba2d98e731fa2c /instr-to-kodkod/src | |
| parent | 1eb79a5c6ae03500a2816a34983e5d4cc700de33 (diff) | |
First shot at (logic, not VHDL) functions.
Diffstat (limited to 'instr-to-kodkod/src')
| -rw-r--r-- | instr-to-kodkod/src/VHDLLevel.java | 14 | ||||
| -rw-r--r-- | instr-to-kodkod/src/VHDLModel.java | 52 | ||||
| -rw-r--r-- | instr-to-kodkod/src/VHDLPredicate.java | 14 |
3 files changed, 46 insertions, 34 deletions
diff --git a/instr-to-kodkod/src/VHDLLevel.java b/instr-to-kodkod/src/VHDLLevel.java index 738adaf..57bb8c4 100644 --- a/instr-to-kodkod/src/VHDLLevel.java +++ b/instr-to-kodkod/src/VHDLLevel.java @@ -60,7 +60,11 @@ public class VHDLLevel } else if (input[0].equals("add_predicate")) { - success = handle_add_predicate(input, m); + success = handle_add_predicate(input, m, false); + } + else if (input[0].equals("add_function")) + { + success = handle_add_predicate(input, m, true); } else { @@ -128,7 +132,8 @@ public class VHDLLevel private static boolean handle_add_predicate ( final String[] cmd, - final VHDLModel m + final VHDLModel m, + final boolean is_function ) { final String[] signature; @@ -137,7 +142,8 @@ public class VHDLLevel { System.err.println ( - "[E] Badly formed \"add_predicate\" instruction: \"" + "[E] Badly formed \"add_predicate\" or \"add_function\"" + + " instruction: \"" + String.join(" ", cmd) + "\"." ); @@ -152,6 +158,6 @@ public class VHDLLevel signature[i - 2] = cmd[i]; } - return m.add_predicate(cmd[1], signature); + return m.add_predicate(cmd[1], signature, is_function); } } diff --git a/instr-to-kodkod/src/VHDLModel.java b/instr-to-kodkod/src/VHDLModel.java index ea024b8..4b6e053 100644 --- a/instr-to-kodkod/src/VHDLModel.java +++ b/instr-to-kodkod/src/VHDLModel.java @@ -25,7 +25,12 @@ public class VHDLModel } } - public boolean add_predicate (final String name, final String[] signature) + public boolean add_predicate + ( + final String name, + final String[] signature, + final boolean is_function + ) { final VHDLPredicate p; final VHDLType[] true_signature; @@ -55,7 +60,11 @@ public class VHDLModel if (p == null) { - predicates.put(name, new VHDLPredicate(name, true_signature)); + predicates.put + ( + name, + new VHDLPredicate(name, true_signature, false) + ); } else { @@ -113,7 +122,15 @@ public class VHDLModel } else if (input[0].equals("set_function")) { - success = handle_set_function(input); + if (input.length < 2) + { + success = false; + } + success = + handle_predicate + ( + Arrays.copyOfRange(input, 1, input.length) + ); } else { @@ -126,7 +143,9 @@ public class VHDLModel ( "[E] An erroneous instruction was found in file \"" + filename - + "\"." + + "\": \"(" + + String.join(" ", input) + + ")\")" ); try @@ -186,30 +205,6 @@ public class VHDLModel return true; } - private boolean handle_set_function (final String... cmd) - { - if (cmd.length != 4) - { - System.err.println - ( - "[E] Badly formed \"set_function\" instruction: \"" - + String.join(" ", cmd) - + "\"." - ); - - return false; - } - - /* - System.err.println - ( - "[W] \"set_function\" instructions are ignored." - ); - */ - - return true; - } - private boolean handle_predicate (final String... cmd) { final VHDLPredicate p; @@ -256,7 +251,6 @@ public class VHDLModel for (int i = 0; i < params.length; ++i) { - /* TODO: check if the IDs are registered in the corresponding type. */ params[i] = cmd[i + 1]; if (!p.accepts_as_nth_param(i, params[i])) diff --git a/instr-to-kodkod/src/VHDLPredicate.java b/instr-to-kodkod/src/VHDLPredicate.java index 3605e76..0ff388b 100644 --- a/instr-to-kodkod/src/VHDLPredicate.java +++ b/instr-to-kodkod/src/VHDLPredicate.java @@ -14,11 +14,18 @@ public class VHDLPredicate private final String name; private final int arity; private final Relation as_relation; + private final boolean is_function; private boolean is_used; - public VHDLPredicate (final String name, final VHDLType[] signature) + public VHDLPredicate + ( + final String name, + final VHDLType[] signature, + final boolean is_function + ) { this.name = name; + this.is_function = is_function; arity = signature.length; signatures = new ArrayList<VHDLType[]>(); @@ -45,6 +52,11 @@ public class VHDLPredicate return arity; } + public boolean is_function () + { + return is_function; + } + public Relation get_as_relation () { if (!is_used) |


