Skip to content

Commit

Permalink
prevent creating signals, etc. with the same name
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephAbbey committed Nov 1, 2022
1 parent bcd299f commit 02dd2ea
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 31 deletions.
14 changes: 11 additions & 3 deletions examples/button_driven.vhdl
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
library ieee;
use ieee.std_logic_1164.all;

entity button_driven is
port(
clk : in std_logic;
reset : in std_logic;
incr : in std_logic;
buttons : in std_logic_vector(3 downto 0);
leds : out std_logic_vector(3 downto 0)
);
end entity;



architecture scratch of led4_button4 is
architecture scratch of button_driven is

constant button_tab_c : natural := 1;

Expand All @@ -15,7 +23,7 @@ begin
process(clk)
begin
if rising_edge(clk) then
if reset = '0' then
if reset = '1' then
leds <= "0000";
else
-- If any buttons are pressed, set leds to buttons.
Expand Down
2 changes: 1 addition & 1 deletion examples/button_driven.vhdl.sbd
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"blocks":{"languageVersion":0,"blocks":[{"type":"process","id":"avqozk~ylO6~9`OoO-tF","x":388,"y":13,"extraState":{"depCount":1},"fields":{"1":{"id":"u;Fa!BiTi{j_018wO)36"}},"inputs":{"body":{"block":{"type":"controls_if","id":"7)2aH8jQ`CxLSWy}UAgr","inputs":{"IF0":{"block":{"type":"logic_rising_edge","id":"0QWfBso?I$XYQ8@mej5}","fields":{"dep":{"id":"u;Fa!BiTi{j_018wO)36"}}}},"DO0":{"block":{"type":"controls_if","id":"|iCK:,3?*n,e{^9zO]%y","extraState":{"hasElse":true},"inputs":{"IF0":{"block":{"type":"logic_compare","id":"B=Og_Cm*AO)T}CKQAZXF","fields":{"OP":"EQ"},"inputs":{"A":{"block":{"type":"variables_get","id":"Db8Ohuaw7PUe(HOT?d:%","fields":{"VAR":{"id":"k={!]s@w*z5TAx~}`{9)"}}}},"B":{"block":{"type":"value_std_logic","id":"HV[(76@,1o#o|NIyg{4L","fields":{"VALUE":0}}}}}},"DO0":{"block":{"type":"variables_set","id":"#+9/+hoAZ#@$}Xj@UfWf","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"value_std_logic_vector","id":"e;wxzA`Gn*})l|hu!d,}","fields":{"VALUE":"0000"}}}}}},"ELSE":{"block":{"type":"controls_if","id":"G-`MW2Q19@O:3dI$@8i`","icons":{"comment":{"text":"If any buttons are pressed, set leds to buttons.","pinned":false,"height":107,"width":387}},"inputs":{"IF0":{"block":{"type":"logic_operation_vector","id":"16BmZIO|$qr(z+1]f618","fields":{"OPERATION":"or"},"inputs":{"LIST":{"block":{"type":"variables_get","id":".*yYPrudmb_BZ;n|H]a2","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}},"DO0":{"block":{"type":"variables_set","id":"@2+PU)j0,=F_cLpfwji{","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"variables_get","id":".+(dqWRY[l/0K@ZwWi6E","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"clk","id":"u;Fa!BiTi{j_018wO)36"},{"name":"reset","id":"k={!]s@w*z5TAx~}`{9)"},{"name":"incr","id":"-N/%|Yb*ua~LIYg|RDXz"},{"name":"buttons","id":"xiS/W8KC[SjitA9:_W,%"},{"name":"leds","id":"j]MA]3Vu=zr|cCG^O7mG"}],"signals":{}}
{"blocks":{"languageVersion":0,"blocks":[{"type":"process","id":"avqozk~ylO6~9`OoO-tF","x":388,"y":13,"extraState":{"depCount":1},"fields":{"1":{"id":"u;Fa!BiTi{j_018wO)36"}},"inputs":{"body":{"block":{"type":"controls_if","id":"7)2aH8jQ`CxLSWy}UAgr","inputs":{"IF0":{"block":{"type":"logic_rising_edge","id":"0QWfBso?I$XYQ8@mej5}","fields":{"dep":{"id":"u;Fa!BiTi{j_018wO)36"}}}},"DO0":{"block":{"type":"controls_if","id":"|iCK:,3?*n,e{^9zO]%y","extraState":{"hasElse":true},"inputs":{"IF0":{"block":{"type":"logic_compare","id":"B=Og_Cm*AO)T}CKQAZXF","fields":{"OP":"EQ"},"inputs":{"A":{"block":{"type":"variables_get","id":"Db8Ohuaw7PUe(HOT?d:%","fields":{"VAR":{"id":"k={!]s@w*z5TAx~}`{9)"}}}},"B":{"block":{"type":"value_std_logic","id":"HV[(76@,1o#o|NIyg{4L","fields":{"VALUE":1}}}}}},"DO0":{"block":{"type":"variables_set","id":"#+9/+hoAZ#@$}Xj@UfWf","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"value_std_logic_vector","id":"e;wxzA`Gn*})l|hu!d,}","fields":{"VALUE":"0000"}}}}}},"ELSE":{"block":{"type":"controls_if","id":"G-`MW2Q19@O:3dI$@8i`","icons":{"comment":{"text":"If any buttons are pressed, set leds to buttons.","pinned":false,"height":107,"width":387}},"inputs":{"IF0":{"block":{"type":"logic_operation_vector","id":"16BmZIO|$qr(z+1]f618","fields":{"OPERATION":"or"},"inputs":{"LIST":{"block":{"type":"variables_get","id":".*yYPrudmb_BZ;n|H]a2","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}},"DO0":{"block":{"type":"variables_set","id":"@2+PU)j0,=F_cLpfwji{","fields":{"VAR":{"id":"j]MA]3Vu=zr|cCG^O7mG"}},"inputs":{"VALUE":{"block":{"type":"variables_get","id":".+(dqWRY[l/0K@ZwWi6E","fields":{"VAR":{"id":"xiS/W8KC[SjitA9:_W,%"}}}}}}}}}}}}}}}}}}]},"variables":[{"name":"clk","id":"u;Fa!BiTi{j_018wO)36"},{"name":"reset","id":"k={!]s@w*z5TAx~}`{9)"},{"name":"incr","id":"-N/%|Yb*ua~LIYg|RDXz"},{"name":"buttons","id":"xiS/W8KC[SjitA9:_W,%"},{"name":"leds","id":"j]MA]3Vu=zr|cCG^O7mG"}],"signals":{}}
64 changes: 37 additions & 27 deletions scratch-vhdl-vscode/media/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,22 +1099,26 @@ document.addEventListener('DOMContentLoaded', function () {
weight: -1,
});

const notExists = (n) => !(entity.entity.hasOwnProperty(n) || signals.hasOwnProperty(n) || constants.hasOwnProperty(n) || aliases.hasOwnProperty(n));

Blockly.ContextMenuRegistry.registry.register({
displayText: "Add port",
preconditionFn() {
return "enabled";
},
callback() {
prompt("New port name: ").then((n) => {
prompt("New port direction: ").then((d) => {
prompt("New port type: ").then((t) => {
entity.entity[n] = [d, t];
vscode.postMessage({
type: "updateEntity",
body: JSON.stringify(entity)
if (notExists(n))
prompt("New port direction: ").then((d) => {
prompt("New port type: ").then((t) => {
entity.entity[n] = [d, t];
vscode.postMessage({
type: "updateEntity",
body: JSON.stringify(entity)
});
});
});
});
else this.callback()
});
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
Expand Down Expand Up @@ -1189,16 +1193,18 @@ document.addEventListener('DOMContentLoaded', function () {
},
callback() {
prompt("New constant name: ").then((n) => {
prompt("New constant type: ").then((t) => {
prompt("New constant value: ").then((v) => {
entity.constants = entity.constants || {};
entity.constants[n] = [t, v];
vscode.postMessage({
type: "updateEntity",
body: JSON.stringify(entity)
if (notExists(n))
prompt("New constant type: ").then((t) => {
prompt("New constant value: ").then((v) => {
entity.constants = entity.constants || {};
entity.constants[n] = [t, v];
vscode.postMessage({
type: "updateEntity",
body: JSON.stringify(entity)
});
});
});
});
else this.callback()
});
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
Expand Down Expand Up @@ -1231,14 +1237,16 @@ document.addEventListener('DOMContentLoaded', function () {
},
callback() {
prompt("New alias name: ").then((n) => {
prompt("New alias value: ").then((v) => {
entity.aliases = entity.aliases || {};
entity.aliases[n] = v;
vscode.postMessage({
type: "updateEntity",
body: JSON.stringify(entity)
if (notExists(n))
prompt("New alias value: ").then((v) => {
entity.aliases = entity.aliases || {};
entity.aliases[n] = v;
vscode.postMessage({
type: "updateEntity",
body: JSON.stringify(entity)
});
});
});
else this.callback()
});
},
scopeType: Blockly.ContextMenuRegistry.ScopeType.WORKSPACE,
Expand Down Expand Up @@ -1279,12 +1287,14 @@ document.addEventListener('DOMContentLoaded', function () {
old(...args);
if (!args[2] && args[0] == "CREATE_VARIABLE") {
ws.removeButtonCallback("CREATE_VARIABLE");
ws.registerButtonCallback("CREATE_VARIABLE", (d) => {
ws.registerButtonCallback("CREATE_VARIABLE", function c(d) {
prompt("New variable name: ").then((n) => {
prompt("New variable type: ").then((t) => {
d.getTargetWorkspace().createVariable(n);
signals[n] = t;
});
if (notExists(n))
prompt("New variable type: ").then((t) => {
d.getTargetWorkspace().createVariable(n);
signals[n] = t;
});
else c(d);
});
}, true);
}
Expand Down

0 comments on commit 02dd2ea

Please sign in to comment.