WARNING: Implementing a smarter parser/solver approach, this will break the…

WARNING: Implementing a smarter parser/solver approach, this will break the system from this commit onwards
parent 03ed1d33
......@@ -138,7 +138,6 @@ class File(object):
ext = tmp[len(tmp)-1]
return ext
class DepFile(File):
def __init__(self, file_path, module, include_paths=None):
from .module import Module
......@@ -152,6 +151,10 @@ class DepFile(File):
self._outputs = set()
self.depends_on = set() # set of files that the file depends on, items of type DepFile
self.dep_level = None
self.provided_architectures = []
self.provided_entities = []
self.used_packages = []
self.is_parsed = False
if include_paths is None:
......
......@@ -75,6 +75,33 @@ def solve(fileset):
#logging.info("- relation: %s" % rel)
#logging.info("- direction: %s" % rel.direction)
# Only analyze USE relations, we are looking for dependencies
if isinstance(investigated_file, VHDLFile) :
print("These are the dependency parameters for a VHDL file")
print("Dump provided architectures from solver!")
for architecture_test in investigated_file.provided_architectures:
print("--------------------------")
print("architecture_test.model")
print(architecture_test.model)
print("architecture_test.components")
print(architecture_test.components)
print("architecture_test.entities")
print(architecture_test.entities)
print("--------------------------")
print("Dump provided entities from solver!")
for entity_test in investigated_file.provided_entities:
print("--------------------------")
print(entity_test)
print("--------------------------")
print("Dump used packages from solver!")
for package_test in investigated_file.used_packages:
print("--------------------------")
print(package_test)
print("--------------------------")
if rel.direction == DepRelation.USE:
satisfied_by = set()
for dep_file in fset:
......@@ -121,9 +148,11 @@ def make_dependency_set(fileset, top_level_entity):
top_rel_vhdl = DepRelation("%s.%s" % ("work", top_level_entity), DepRelation.PROVIDE, DepRelation.ENTITY)
top_rel_vlog = DepRelation("%s.%s" % ("work", top_level_entity), DepRelation.PROVIDE, DepRelation.MODULE)
top_file = None
logging.debug("Look for top level unit: %s." % top_level_entity)
for chk_file in fset:
for rel in chk_file.rels:
if ((rel == top_rel_vhdl) or (rel == top_rel_vlog)):
logging.debug("Found the top level file providing top level unit: %s." % chk_file)
top_file = chk_file
break;
if top_file:
......
......@@ -47,6 +47,12 @@ class VHDLPreprocessor(object):
return self._preprocess_file(file_content = buf, file_name = file_path, library = vhdl_file.library)
class Architecture():
def __init__(self):
self.model = None;
self.components = None;
self.entities = None;
class VHDLParser(DepParser):
def __init__(self, dep_file):
......@@ -59,7 +65,8 @@ class VHDLParser(DepParser):
if dep_file.is_parsed:
return
logging.info("Parsing %s" % dep_file.path)
# Preprocess file
buf = self.preprocessor.preprocess(dep_file)
#use packages
......@@ -72,31 +79,45 @@ class VHDLParser(DepParser):
logging.debug("use package %s.%s" % (s.group(1), s.group(2)) )
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))
use_packages = use_pattern.findall(buf)
print('use package:\n %s' % use_packages)
dep_file.used_packages = use_packages
buf = re.sub(use_pattern, do_use, buf)
#new entity
# Provide entity
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) :
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)),
DepRelation.PROVIDE,
DepRelation.ENTITY))
return "<hdlmake entity_pattern %s.%s>" % (dep_file.library, s.group(1))
buf = re.sub(entity_pattern, do_entity, buf)
provided_entities = entity_pattern.findall(buf)
print('provide entities:\n %s' % provided_entities)
dep_file.provided_entities = provided_entities
#new architecture
# Provide architecture
architecture_pattern = re.compile("^\s*architecture\s+(\w+)\s+of\s+(\w+)\s+is", re.DOTALL | re.MULTILINE | re.IGNORECASE )
def do_architecture(s) :
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)),
DepRelation.PROVIDE,
DepRelation.ARCHITECTURE))
dep_file.add_relation(DepRelation("%s.%s" % (dep_file.library, s.group(2)),
DepRelation.USE,
DepRelation.ENTITY))
return "<hdlmake architecture %s.%s>" % (dep_file.library, s.group(2))
buf = re.sub(architecture_pattern, do_architecture, buf)
provided_architectures = architecture_pattern.findall(buf)
print('provide architectures:\n %s' % provided_architectures)
for architecture in provided_architectures:
architecture_aux = Architecture();
architecture_aux.model = architecture
print('- architecture: %s(%s)' % (architecture[1], architecture[0]))
architecture_inner_pattern = re.compile("architecture\s+%s\s+of\s+%s\s+is(.*)end\s+%s" % (architecture[0], architecture[1], architecture[0]), re.DOTALL | re.MULTILINE | re.IGNORECASE )
architecture_inner_content = architecture_inner_pattern.findall(buf)
#print(architecture_inner_content)
component_pattern = re.compile("^\s*component\s+(\w+).*?end\s+component.*?;", re.DOTALL | re.MULTILINE | re.IGNORECASE )
print("Architecture dependencies:")
print("content length: %s" % len(architecture_inner_content))
if len(architecture_inner_content) == 1:
architecture_aux.components = component_pattern.findall(architecture_inner_content[0])
instances_pattern = re.compile("^\s*(\w+)\s*\:\s*(\w+)\s*(?:port\s+map.*?;|generic\s+map.*?;|\s*;)", re.DOTALL | re.MULTILINE | re.IGNORECASE )
architecture_aux.entities = instances_pattern.findall(architecture_inner_content[0])
dep_file.provided_architectures.append(architecture_aux)
#print("Dump architectures")
#for architecture_test in dep_file.architectures:
# print("--------------------------")
# print(architecture_test.model)
# print(architecture_test.components)
# print(architecture_test.entities)
# print("--------------------------")
#new package
package_pattern = re.compile("^\s*package\s+(\w+)\s+is", re.DOTALL | re.MULTILINE | re.IGNORECASE )
def do_package(s) :
......
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