コード例 #1
0
ファイル: build.py プロジェクト: mgolokhov/autohdl
def load(file = buildFilePath, _cache = {}, cacheEnable = True):
  path = os.path.abspath(file)
  if cacheEnable and _cache.get(path):
    return _cache.get(path)
  else:
    try:
      with open(file) as f:
        content = yaml.load(f.read())
        _toAbsolute(content, path)
        return content
    except IOError as e:
      log.warning(e)
      logging.warning('Cant open file ' + path)
      return {}
コード例 #2
0
ファイル: cache.py プロジェクト: mgolokhov/autohdl
def load(file):
  if not CACHE_LOAD:
    return
  file = cache_path(file)
  y = None
  try:
    y = yaml.load(open(file))
  except IOError as e:
    logging.debug(e)
  except Exception as e:
    logging.warning(e)
  try:
    if shaOK(y) and versionOK(y):
      return y
  except IOError as e:
    logging.debug(e)
コード例 #3
0
ファイル: vpreprocessor.py プロジェクト: mgolokhov/autohdl
 def prepInclude(self, iLine):
   res = re.search(r'`include\s+"(.+?)"', iLine)
   if res:
     inclFile = res.group(1)
     searchPaths = build.load().get('include_path', '.')
     if type(searchPaths) is not list:
       searchPaths = [searchPaths]
     searchPaths += [os.path.dirname(self.path)]
     for path in searchPaths:
       fullPath = os.path.join(path, inclFile)
       if os.path.exists(fullPath):
         self.includes['paths'].append(os.path.relpath(fullPath))
         inclContent = self.readContent(fullPath)
         return inclContent.splitlines()
   logging.warning('Cannot resolve {} in file: {}'.format(iLine,
                                                          os.path.abspath(self.path)))
   return []
コード例 #4
0
ファイル: vpreprocessor.py プロジェクト: mgolokhov/autohdl
  def prepBranch(self, iLine, iContentIter):
    blocks = OrderedDict()
    branch = iLine
    blocks[branch] = []
    nested = 0
    while True:
      line = iContentIter.next()
      if '`ifdef' in line or '`ifndef' in line:
        nested += 1
      elif nested and '`endif' in line:
        nested -= 1
        blocks[branch].append(line)
        continue
      if not nested:
        if '`endif' in line:
          break # formed branches
        elif {'`elsif', '`else'} & set(line.split()):
          branch = line
          blocks[branch] = []
        else:
          blocks[branch].append(line)
      else:
        blocks[branch].append(line)


    for k, v in blocks.iteritems():
      words = k.split()
      if len(words) >= 2:
        if '`ifndef' in k:
          if words[1] not in  self.defines:
            return v
        elif words[1] in self.defines:
          return v
      elif '`else' in k:
        return v
      else:
        logging.warning('Error in macro ' + k)

    return []