Adding support for defining input and output with the same location in LPCBeremiz
--- a/LPCBeremiz.py Mon Dec 07 10:25:33 2009 +0100
+++ b/LPCBeremiz.py Mon Dec 07 14:43:27 2009 +0100
@@ -72,6 +72,17 @@
# LPCModule Class
#-------------------------------------------------------------------------------
+LOCATION_TYPES = {"I": LOCATION_VAR_INPUT,
+ "Q": LOCATION_VAR_OUTPUT,
+ "M": LOCATION_VAR_MEMORY}
+
+LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()])
+
+LOCATION_SIZES = {}
+for size, types in LOCATIONDATATYPES.iteritems():
+ for type in types:
+ LOCATION_SIZES[type] = size
+
def _GetModuleChildren(module):
children = []
for child in module["children"]:
@@ -96,9 +107,9 @@
return child
return None
-def _GetModuleVariable(module, location):
+def _GetModuleVariable(module, location, direction):
for child in _GetModuleChildren(module):
- if child["location"] == location:
+ if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
return child
return None
@@ -110,17 +121,6 @@
if group["type"] == LOCATION_GROUP and child in group["children"]:
group["children"].remove(child)
-LOCATION_TYPES = {"I": LOCATION_VAR_INPUT,
- "Q": LOCATION_VAR_OUTPUT,
- "M": LOCATION_VAR_MEMORY}
-
-LOCATION_DIRS = dict([(dir, size) for size, dir in LOCATION_TYPES.iteritems()])
-
-LOCATION_SIZES = {}
-for size, types in LOCATIONDATATYPES.iteritems():
- for type in types:
- LOCATION_SIZES[type] = size
-
BUS_TEXT = """/* Code generated by LPCBus plugin */
/* LPCBus plugin includes */
@@ -893,7 +893,7 @@
for child in _GetModuleChildren(module):
if child["name"] == name:
return "Error: A variable named %s already exists" % name
- if child["location"] == location:
+ if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
return "Error: A variable with location %s already exists" % ".".join(map(str, location))
_GetLastModuleGroup(module).append({"name": name,
"location": location,
@@ -911,7 +911,7 @@
return "Error: No parent found"
variable = None
for child in _GetModuleChildren(module):
- if child["location"] == location:
+ if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
variable = child
elif child["name"] == new_name:
return "Error: A variable named %s already exists" % new_name
@@ -929,11 +929,11 @@
variable["description"] = new_description
self.RestartTimer()
- def RemoveVariable(self, parent, location):
+ def RemoveVariable(self, parent, location, direction):
module = self.PluginRoot.GetChildByIECLocation(parent)
if module is None:
return "Error: No parent found"
- child = _GetModuleVariable(module, location)
+ child = _GetModuleVariable(module, location, direction)
if child is None:
return "Error: No variable found"
size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]