OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [ssbccUtil.py] - Diff between revs 2 and 3

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 2 Rev 3
Line 5... Line 5...
# Utilities required by ssbcc
# Utilities required by ssbcc
#
#
################################################################################
################################################################################
 
 
import math
import math
 
import os
import re
import re
 
 
################################################################################
################################################################################
#
#
# Classes
# Classes
Line 71... Line 72...
 
 
def IntValue(v):
def IntValue(v):
  """
  """
  Convert a Verilog format integer into an integer value.
  Convert a Verilog format integer into an integer value.
  """
  """
 
  save_v = v;
 
  if re.match(r'([1-9]\d*)?\'[bodh]',v):
 
    length = 0;
 
    while v[0] != '\'':
 
      length *= 10;
 
      length += ord(v[0]) - ord('0');
 
      v = v[1:];
 
    v=v[1:];
 
    if v[0] == 'b':
 
      base = 2;
 
    elif v[0] == 'o':
 
      base = 8;
 
    elif v[0] == 'd':
 
      base = 10;
 
    elif v[0] == 'h':
 
      base = 16;
 
    else:
 
      raise Exception('Program bug -- unrecognized base:  "%c"' % v[0]);
 
    v = v[1:];
 
  else:
 
    length = 0;
 
    base = 10;
  ov = 0;
  ov = 0;
  for vv in [v[i] for i in range(len(v)) if '0' <= v[i] <= '9']:
  for vv in [v[i] for i in range(len(v)) if v[i] != '_']:
    ov *= 10;
    ov *= base;
    ov += ord(vv)-ord('0');
    try:
 
      dv = int(vv,base);
 
    except:
 
      raise SSBCCException('Malformed parameter value:  "%s"' % save_v);
 
    ov += dv;
 
  if length > 0 and ov >= 2**length:
 
    raise SSBCCException('Paramter length and value don\'t match:  "%s"' % save_v);
  return ov;
  return ov;
 
 
def IsPowerOf2(v):
def IsPowerOf2(v):
  """
  """
  Indicate whether or not the argument is a power of 2.
  Indicate whether or not the argument is a power of 2.
  """
  """
  return v == 2**int(math.log(v,2)+0.5);
  return v == 2**int(math.log(v,2)+0.5);
 
 
def LoadFile(filename):
def LoadFile(filename,config):
  """
  """
  Load the file into a list with the line contents and line numbers.\n
  Load the file into a list with the line contents and line numbers.\n
  filename is either the name of the file or a file object.\n
  filename is either the name of the file or a file object.\n
  Note:  The file object is closed in either case.
  Note:  The file object is closed in either case.
  """
  """
  if type(filename) == str:
  if type(filename) == str:
 
    for path in config.includepaths:
 
      fullfilename = os.path.join(path,filename);
 
      if os.path.isfile(fullfilename):
    try:
    try:
      filename = file(filename);
          fp = file(fullfilename);
    except:
    except:
      raise SSBCCException('Error opening "%s"' % filename);
      raise SSBCCException('Error opening "%s"' % filename);
 
        break;
 
    else:
 
      raise SSBCCException('.INCLUDE file "%s" not found' % filename);
  elif type(filename) == file:
  elif type(filename) == file:
    pass;
    fp = filename;
  else:
  else:
    raise Exception('Unexpected argument type:  %s' % type(filename))
    raise Exception('Unexpected argument type:  %s' % type(filename))
  v = list();
  v = list();
  ixLine = 0;
  ixLine = 0;
  for tmpLine in filename:
  for tmpLine in fp:
    ixLine += 1;
    ixLine += 1;
    while tmpLine and tmpLine[-1] in ('\n','\r',):
    while tmpLine and tmpLine[-1] in ('\n','\r',):
      tmpLine = tmpLine[0:-1];
      tmpLine = tmpLine[0:-1];
    v.append((tmpLine,ixLine,));
    v.append((tmpLine,ixLine,));
  filename.close();
  fp.close();
  return v;
  return v;
 
 
################################################################################
################################################################################
#
#
# Unit test.
# Unit test.

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.