Commit 0477b892 authored by Will Kamp's avatar Will Kamp

Move entity_name.lower() into DepRelation __init__()

Make the code cleaner and less likely to break in the future.
parent 62de78de
...@@ -41,7 +41,7 @@ class DepRelation(object): ...@@ -41,7 +41,7 @@ class DepRelation(object):
assert rel_type in [DepRelation.ENTITY, DepRelation.PACKAGE, DepRelation.INCLUDE, DepRelation.ARCHITECTURE] assert rel_type in [DepRelation.ENTITY, DepRelation.PACKAGE, DepRelation.INCLUDE, DepRelation.ARCHITECTURE]
self.direction = direction self.direction = direction
self.rel_type = rel_type self.rel_type = rel_type
self.obj_name = obj_name self.obj_name = obj_name.lower()
def satisfies(self, rel_b): def satisfies(self, rel_b):
if rel_b.direction == DepRelation.PROVIDE or self.direction == DepRelation.USE: if rel_b.direction == DepRelation.PROVIDE or self.direction == DepRelation.USE:
...@@ -205,5 +205,5 @@ class DepFile(File): ...@@ -205,5 +205,5 @@ class DepFile(File):
# recurse, to find the largest number of levels below. # recurse, to find the largest number of levels below.
self.dep_level = 1 + max([dep.get_dep_level() for dep in self.depends_on]); self.dep_level = 1 + max([dep.get_dep_level() for dep in self.depends_on]);
elif self.dep_level < 0: elif self.dep_level < 0:
raise Exception("Probably run into a circular reference of file dependencies.") raise Exception("Probably run into a circular reference of file dependencies. It appears %d depends on itself, indirectly via atleast one other file." % self.filename())
return self.dep_level return self.dep_level
...@@ -67,10 +67,10 @@ class VHDLParser(DepParser): ...@@ -67,10 +67,10 @@ class VHDLParser(DepParser):
def do_use(s) : def do_use(s) :
if ( s.group(1).lower() == "work" ) : #work is the current library in VHDL if ( s.group(1).lower() == "work" ) : #work is the current library in VHDL
logging.debug("use package %s.%s" % (dep_file.library, s.group(2) ) ) logging.debug("use package %s.%s" % (dep_file.library, s.group(2) ) )
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2).lower() ) , DepRelation.USE, DepRelation.PACKAGE)) dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2) ) , DepRelation.USE, DepRelation.PACKAGE))
else : else :
logging.debug("use package %s.%s" % (s.group(1), s.group(2)) ) logging.debug("use package %s.%s" % (s.group(1), s.group(2)) )
dep_file.add_relation(DepRelation("%s.%s" % (s.group(1).lower(), s.group(2).lower()), DepRelation.USE, DepRelation.PACKAGE)) dep_file.add_relation(DepRelation("%s.%s" % (s.group(1), s.group(2)), DepRelation.USE, DepRelation.PACKAGE))
return "<hdlmake use_pattern %s.%s>" % (s.group(1), s.group(2)) return "<hdlmake use_pattern %s.%s>" % (s.group(1), s.group(2))
buf = re.sub(use_pattern, do_use, buf) buf = re.sub(use_pattern, do_use, buf)
...@@ -78,7 +78,7 @@ class VHDLParser(DepParser): ...@@ -78,7 +78,7 @@ class VHDLParser(DepParser):
entity_pattern = re.compile("^\s*entity\s+(?P<name>\w+)\s+is\s+(?:port|generic|end).*?(?P=name)\s*;", re.DOTALL | re.MULTILINE | re.IGNORECASE ) entity_pattern = re.compile("^\s*entity\s+(?P<name>\w+)\s+is\s+(?:port|generic|end).*?(?P=name)\s*;", re.DOTALL | re.MULTILINE | re.IGNORECASE )
def do_entity(s) : def do_entity(s) :
logging.debug("found entity %s.%s" % ( dep_file.library, s.group(1) ) ) logging.debug("found entity %s.%s" % ( dep_file.library, s.group(1) ) )
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(1).lower()), dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(1)),
DepRelation.PROVIDE, DepRelation.PROVIDE,
DepRelation.ENTITY)) DepRelation.ENTITY))
return "<hdlmake entity_pattern %s.%s>" % (dep_file.library, s.group(1)) return "<hdlmake entity_pattern %s.%s>" % (dep_file.library, s.group(1))
...@@ -88,10 +88,10 @@ class VHDLParser(DepParser): ...@@ -88,10 +88,10 @@ class VHDLParser(DepParser):
architecture_pattern = re.compile("^\s*architecture\s+(\w+)\s+of\s+(\w+)\s+is", re.DOTALL | re.MULTILINE | re.IGNORECASE ) architecture_pattern = re.compile("^\s*architecture\s+(\w+)\s+of\s+(\w+)\s+is", re.DOTALL | re.MULTILINE | re.IGNORECASE )
def do_architecture(s) : def do_architecture(s) :
logging.debug("found architecture %s of entity %s.%s" % ( s.group(1), dep_file.library, s.group(2) ) ) logging.debug("found architecture %s of entity %s.%s" % ( s.group(1), dep_file.library, s.group(2) ) )
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2).lower()), dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2)),
DepRelation.PROVIDE, DepRelation.PROVIDE,
DepRelation.ARCHITECTURE)) DepRelation.ARCHITECTURE))
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2).lower()), dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2)),
DepRelation.USE, DepRelation.USE,
DepRelation.ENTITY)) DepRelation.ENTITY))
return "<hdlmake architecture %s.%s>" % (dep_file.library, s.group(2)) return "<hdlmake architecture %s.%s>" % (dep_file.library, s.group(2))
...@@ -101,7 +101,7 @@ class VHDLParser(DepParser): ...@@ -101,7 +101,7 @@ class VHDLParser(DepParser):
package_pattern = re.compile("^\s*package\s+(\w+)\s+is", re.DOTALL | re.MULTILINE | re.IGNORECASE ) package_pattern = re.compile("^\s*package\s+(\w+)\s+is", re.DOTALL | re.MULTILINE | re.IGNORECASE )
def do_package(s) : def do_package(s) :
logging.debug("found package %s.%s" % (dep_file.library, s.group(1) )) logging.debug("found package %s.%s" % (dep_file.library, s.group(1) ))
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(1).lower()), dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(1)),
DepRelation.PROVIDE, DepRelation.PROVIDE,
DepRelation.PACKAGE)) DepRelation.PACKAGE))
return "<hdlmake package %s.%s>" % (dep_file.library, s.group(1)) return "<hdlmake package %s.%s>" % (dep_file.library, s.group(1))
...@@ -135,19 +135,19 @@ class VHDLParser(DepParser): ...@@ -135,19 +135,19 @@ class VHDLParser(DepParser):
def do_instance(s) : def do_instance(s) :
for lib in libraries : for lib in libraries :
logging.debug("-> instantiates %s.%s as %s" % (lib, s.group(2), s.group(1)) ) logging.debug("-> instantiates %s.%s as %s" % (lib, s.group(2), s.group(1)) )
dep_file.add_relation(DepRelation("%s.%s" % (lib, s.group(2).lower()), dep_file.add_relation(DepRelation("%s.%s" % (lib, s.group(2)),
DepRelation.USE, DepRelation.USE,
DepRelation.ARCHITECTURE)) DepRelation.ARCHITECTURE))
return "<hdlmake instance %s|%s>" % (s.group(1), s.group(2)) return "<hdlmake instance %s|%s>" % (s.group(1), s.group(2))
def do_instance_from_library(s) : def do_instance_from_library(s) :
if ( s.group(2).lower() == "work" ) : #work is the current library in VHDL if ( s.group(2).lower() == "work" ) : #work is the current library in VHDL
logging.debug("-> instantiates %s.%s as %s" % (dep_file.library, s.group(3), s.group(1)) ) logging.debug("-> instantiates %s.%s as %s" % (dep_file.library, s.group(3), s.group(1)) )
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(3).lower()), dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(3)),
DepRelation.USE, DepRelation.USE,
DepRelation.ARCHITECTURE)) DepRelation.ARCHITECTURE))
else : else :
logging.debug("-> instantiates %s.%s as %s" % (s.group(2), s.group(3), s.group(1)) ) logging.debug("-> instantiates %s.%s as %s" % (s.group(2), s.group(3), s.group(1)) )
dep_file.add_relation(DepRelation("%s.%s" % (s.group(2).lower(), s.group(3).lower()), dep_file.add_relation(DepRelation("%s.%s" % (s.group(2), s.group(3)),
DepRelation.USE, DepRelation.USE,
DepRelation.ARCHITECTURE)) DepRelation.ARCHITECTURE))
...@@ -159,7 +159,7 @@ class VHDLParser(DepParser): ...@@ -159,7 +159,7 @@ class VHDLParser(DepParser):
library_pattern = re.compile("^\s*library\s*(\w+)\s*;", re.DOTALL | re.MULTILINE | re.IGNORECASE ) library_pattern = re.compile("^\s*library\s*(\w+)\s*;", re.DOTALL | re.MULTILINE | re.IGNORECASE )
def do_library(s) : def do_library(s) :
logging.debug("use library %s" % s.group(1)) logging.debug("use library %s" % s.group(1))
libraries.add(s.group(1).lower()) libraries.add(s.group(1))
return "<hdlmake library %s>" % s.group(1) return "<hdlmake library %s>" % s.group(1)
buf = re.sub(library_pattern, do_library, buf) buf = re.sub(library_pattern, do_library, buf)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment