Example #1
0
	def test_resolve_non_wsp_define(self):
		"""First test to see if the system will replace a define that isn't separated by whitespaces"""
		import sappreproc	
		import saputils
		#first get the filename
		filename = saputils.find_rtl_file_location("wb_ddr.v")
		filestring = ""
		try:
			f = open(filename)
			filestring = f.read()
			f.close()
		except:
			print "Failed to open test file"
			self.assertEqual(True, False)
			return

		define_dict = sappreproc.generate_define_table(filestring)
		#print "number of defines: " + str(len(define_dict.keys()))
		result = sappreproc.resolve_defines("`WB_ADR_WIDTH:0", define_dict, debug = self.dbg)

		self.assertEqual(len(result) > 0, True)
Example #2
0
	def test_resolve_non_wsp_define(self):
		"""First test to see if the system will replace a define that isn't separated by whitespaces"""
		import sappreproc	
		import saputils
		#first get the filename
		filename = saputils.find_rtl_file_location("wb_ddr.v")
		filestring = ""
		try:
			f = open(filename)
			filestring = f.read()
			f.close()
		except:
			print "Failed to open test file"
			self.assertEqual(True, False)
			return

		define_dict = sappreproc.generate_define_table(filestring)
		#print "number of defines: " + str(len(define_dict.keys()))
		result = sappreproc.resolve_defines("`WB_ADR_WIDTH:0", define_dict, debug = self.dbg)

		self.assertEqual(len(result) > 0, True)
Example #3
0
	def test_resolve_multiple_defines(self):
		"""second easiest test, this one requires multiple passes of the 
		replacement string"""
		import sappreproc	
		import saputils
		#first get the filename
		filename = saputils.find_rtl_file_location("wb_ddr.v")
		filestring = ""
		try:
			f = open(filename)
			filestring = f.read()
			f.close()
		except:
			print "Failed to open test file"
			self.assertEqual(True, False)
			return

		define_dict = sappreproc.generate_define_table(filestring)
		#print "number of defines: " + str(len(define_dict.keys()))
		result = sappreproc.resolve_defines("`WB_ADR_WIDTH:`WB_SEL_WIDTH", define_dict, debug = self.dbg)

		self.assertEqual(len(result) > 0, True)
Example #4
0
	def test_resolve_multiple_defines(self):
		"""second easiest test, this one requires multiple passes of the 
		replacement string"""
		import sappreproc	
		import saputils
		#first get the filename
		filename = saputils.find_rtl_file_location("wb_ddr.v")
		filestring = ""
		try:
			f = open(filename)
			filestring = f.read()
			f.close()
		except:
			print "Failed to open test file"
			self.assertEqual(True, False)
			return

		define_dict = sappreproc.generate_define_table(filestring)
		#print "number of defines: " + str(len(define_dict.keys()))
		result = sappreproc.resolve_defines("`WB_ADR_WIDTH:`WB_SEL_WIDTH", define_dict, debug = self.dbg)

		self.assertEqual(len(result) > 0, True)
Example #5
0
def get_module_tags(filename="", bus="", keywords=[], debug=False):
    """Gets the tags for the module within the specified filename

  Given a module within a filename search through the module and 
  find:
    metadata
      \"DRT_ID\"
      \"DRT_FLAGS\"
    ports: Inputs/Outputs of this module
    module: Name of the module
    parameters: Configuration parameters within the module
    arbitrator_masters: Any arbitrator masters within the module

  Args:
    filename: Name of the module to interrogate
    bus: A string declaring the bus type, this can be
      \"wishbone\" or \"axie\"
    keywords:
      Besides the standard metadata any additional values to search for

  Returns:
    A dictionary of module tags

  Raises
    Nothing
  """
    tags = {}
    tags["keywords"] = {}
    tags["ports"] = {}
    tags["module"] = ""
    tags["parameters"] = {}
    tags["arbitrator_masters"] = []
    raw_buf = ""

    #need a more robust way of openning the slave

    #  keywords = [
    #    "DRT_ID",
    #    "DRT_FLAGS",
    #  ]

    ports = ["input", "output", "inout"]

    #XXX only working with verilog at this time, need to extend to VHDL
    with open(filename) as slave_file:
        buf = slave_file.read()
        raw_buf = buf

    #find all the metadata
    for key in keywords:
        index = buf.find(key)
        if (index == -1):
            if debug:
                print "didn't find substring for " + key
            continue
        if debug:
            print "found substring for " + key

        substring = buf.__getslice__(index, len(buf)).splitlines()[0]
        if debug:
            print "substring: " + substring

        if debug:
            print "found " + key + " substring: " + substring

        substring = substring.strip()
        substring = substring.strip("//")
        substring = substring.strip("/*")
        tags["keywords"][key] = substring.partition(":")[2]

    #remove all the comments from the code
    buf = remove_comments(buf)
    #print "no comments: \n\n" + buf

    for substring in buf.splitlines():
        if (len(substring.partition("module")[1]) == 0):
            continue
        module_string = substring.partition("module")[2]
        module_string = module_string.strip(" ")
        module_string = module_string.strip("(")
        index = module_string.find(" ")

        if (index != -1):
            tags["module"] = module_string.__getslice__(0, index)
        else:
            tags["module"] = module_string

        if debug:
            print "module name: " + module_string
            print tags["module"]

        break

    #find all the ports
    #find the index of all the processing block
    substrings = buf.splitlines()

    input_count = buf.count("input")
    output_count = buf.count("output")
    inout_count = buf.count("inout")

    if debug:
        print "filename: " + filename

    filestring = ""
    try:
        f = open(filename)
        filestring = f.read()
        f.close()


#XXX: This should probably allow the calling function to handle a failure
    except:
        print "Failed to open test filename"
        return

    ldebug = debug
    define_dict = sappreproc.generate_define_table(filestring, ldebug)

    #find all the IO's
    for io in ports:
        tags["ports"][io] = {}
        substrings = buf.splitlines()
        for substring in substrings:
            #      if debug:
            #        print "working on substring: " + substring
            substring = substring.strip()
            #if line doesn't start with an input/output or inout
            if (not substring.startswith(io)):
                continue
            #if the line does start with input/output or inout but is used in a name then bail
            if (not substring.partition(io)[2][0].isspace()):
                continue
            #one style will declare the port names after the ports list
            if (substring.endswith(";")):
                substring = substring.rstrip(";")
            #the other stile will include the entire port definition within the port declaration
            if (substring.endswith(",")):
                substring = substring.rstrip(",")
            if debug:
                print "substring: " + substring
            substring = substring.partition(io)[2]
            if (len(substring.partition("reg")[1]) != 0):
                substring = substring.partition("reg")[2]
            substring = substring.strip()
            max_val = -1
            min_val = -1
            if (len(substring.partition("]")[2]) != 0):
                #we have a range to work with?
                length_string = substring.partition("]")[0] + "]"
                substring = substring.partition("]")[2]
                substring = substring.strip()
                length_string = length_string.strip()
                if debug:
                    print "length string: " + length_string

                ldebug = debug

                length_string = sappreproc.resolve_defines(length_string,
                                                           define_dict,
                                                           debug=ldebug)
                length_string = sappreproc.evaluate_range(length_string)
                length_string = length_string.partition("]")[0]
                length_string = length_string.strip("[")
                if debug:
                    print "length string: " + length_string
                max_val = string.atoi(length_string.partition(":")[0])
                min_val = string.atoi(length_string.partition(":")[2])

            tags["ports"][io][substring] = {}

            if (max_val != -1):
                tags["ports"][io][substring]["max_val"] = max_val
                tags["ports"][io][substring]["min_val"] = min_val
                tags["ports"][io][substring]["size"] = (max_val + 1) - min_val
            else:
                tags["ports"][io][substring]["size"] = 1

            #print io + ": " + substring

    #find all the USER_PARAMETER declarations
    user_parameters = []
    substrings = raw_buf.splitlines()
    for substring in substrings:
        substring = substring.strip()
        if "USER_PARAMETER" in substring:
            name = substring.partition(":")[2].strip()
            user_parameters.append(name)

    #find all the parameters
    substrings = buf.splitlines()
    for substring in substrings:
        substring = substring.strip()
        if ("parameter" in substring):
            if debug:
                print "found parameter!"
            substring = substring.partition("parameter")[2].strip()
            parameter_name = substring.partition("=")[0].strip()
            parameter_value = substring.partition("=")[2].strip()
            parameter_value = parameter_value.partition(";")[0].strip()
            if debug:
                print "parameter name: " + parameter_name
                print "parameter value: " + parameter_value
            if parameter_name in user_parameters:
                tags["parameters"][parameter_name] = parameter_value

    tags["arbitrator_masters"] = saparbitrator.get_number_of_arbitrator_hosts(
        tags)

    if debug:
        print "input count: " + str(input_count)
        print "output count: " + str(output_count)
        print "inout count: " + str(inout_count)
        print "\n"

    if debug:
        print "module name: " + tags["module"]
        for key in tags["keywords"].keys():
            print "key: " + key + ":" + tags["keywords"][key]
        for io in ports:
            for item in tags["ports"][io].keys():
                print io + ": " + item
                for key in tags["ports"][io][item].keys():
                    value = tags["ports"][io][item][key]
                    if (isinstance(value, int)):
                        value = str(value)
                    print "\t" + key + ":" + value

    return tags
Example #6
0
def get_module_tags(filename="", bus="", keywords=[], debug=False):
    """Gets the tags for the module within the specified filename

  Given a module within a filename search through the module and 
  find:
    metadata
      \"DRT_ID\"
      \"DRT_FLAGS\"
    ports: Inputs/Outputs of this module
    module: Name of the module
    parameters: Configuration parameters within the module
    arbitrator_masters: Any arbitrator masters within the module

  Args:
    filename: Name of the module to interrogate
    bus: A string declaring the bus type, this can be
      \"wishbone\" or \"axie\"
    keywords:
      Besides the standard metadata any additional values to search for

  Returns:
    A dictionary of module tags

  Raises
    Nothing
  """
    tags = {}
    tags["keywords"] = {}
    tags["ports"] = {}
    tags["module"] = ""
    tags["parameters"] = {}
    tags["arbitrator_masters"] = []
    raw_buf = ""

    # need a more robust way of openning the slave

    #  keywords = [
    #    "DRT_ID",
    #    "DRT_FLAGS",
    #  ]

    ports = ["input", "output", "inout"]

    # XXX only working with verilog at this time, need to extend to VHDL
    with open(filename) as slave_file:
        buf = slave_file.read()
        raw_buf = buf

    # find all the metadata
    for key in keywords:
        index = buf.find(key)
        if index == -1:
            if debug:
                print "didn't find substring for " + key
            continue
        if debug:
            print "found substring for " + key

        substring = buf.__getslice__(index, len(buf)).splitlines()[0]
        if debug:
            print "substring: " + substring

        if debug:
            print "found " + key + " substring: " + substring

        substring = substring.strip()
        substring = substring.strip("//")
        substring = substring.strip("/*")
        tags["keywords"][key] = substring.partition(":")[2]

    # remove all the comments from the code
    buf = remove_comments(buf)
    # print "no comments: \n\n" + buf

    for substring in buf.splitlines():
        if len(substring.partition("module")[1]) == 0:
            continue
        module_string = substring.partition("module")[2]
        module_string = module_string.strip(" ")
        module_string = module_string.strip("(")
        index = module_string.find(" ")

        if index != -1:
            tags["module"] = module_string.__getslice__(0, index)
        else:
            tags["module"] = module_string

        if debug:
            print "module name: " + module_string
            print tags["module"]

        break

    # find all the ports
    # find the index of all the processing block
    substrings = buf.splitlines()

    input_count = buf.count("input")
    output_count = buf.count("output")
    inout_count = buf.count("inout")

    if debug:
        print "filename: " + filename

    filestring = ""
    try:
        f = open(filename)
        filestring = f.read()
        f.close()
    # XXX: This should probably allow the calling function to handle a failure
    except:
        print "Failed to open test filename"
        return

    ldebug = debug
    define_dict = sappreproc.generate_define_table(filestring, ldebug)

    # find all the IO's
    for io in ports:
        tags["ports"][io] = {}
        substrings = buf.splitlines()
        for substring in substrings:
            #      if debug:
            #        print "working on substring: " + substring
            substring = substring.strip()
            # if line doesn't start with an input/output or inout
            if not substring.startswith(io):
                continue
            # if the line does start with input/output or inout but is used in a name then bail
            if not substring.partition(io)[2][0].isspace():
                continue
            # one style will declare the port names after the ports list
            if substring.endswith(";"):
                substring = substring.rstrip(";")
            # the other stile will include the entire port definition within the port declaration
            if substring.endswith(","):
                substring = substring.rstrip(",")
            if debug:
                print "substring: " + substring
            substring = substring.partition(io)[2]
            if len(substring.partition("reg")[1]) != 0:
                substring = substring.partition("reg")[2]
            substring = substring.strip()
            max_val = -1
            min_val = -1
            if len(substring.partition("]")[2]) != 0:
                # we have a range to work with?
                length_string = substring.partition("]")[0] + "]"
                substring = substring.partition("]")[2]
                substring = substring.strip()
                length_string = length_string.strip()
                if debug:
                    print "length string: " + length_string

                ldebug = debug

                length_string = sappreproc.resolve_defines(length_string, define_dict, debug=ldebug)
                length_string = sappreproc.evaluate_range(length_string)
                length_string = length_string.partition("]")[0]
                length_string = length_string.strip("[")
                if debug:
                    print "length string: " + length_string
                max_val = string.atoi(length_string.partition(":")[0])
                min_val = string.atoi(length_string.partition(":")[2])

            tags["ports"][io][substring] = {}

            if max_val != -1:
                tags["ports"][io][substring]["max_val"] = max_val
                tags["ports"][io][substring]["min_val"] = min_val
                tags["ports"][io][substring]["size"] = (max_val + 1) - min_val
            else:
                tags["ports"][io][substring]["size"] = 1

            # print io + ": " + substring

    # find all the USER_PARAMETER declarations
    user_parameters = []
    substrings = raw_buf.splitlines()
    for substring in substrings:
        substring = substring.strip()
        if "USER_PARAMETER" in substring:
            name = substring.partition(":")[2].strip()
            user_parameters.append(name)

    # find all the parameters
    substrings = buf.splitlines()
    for substring in substrings:
        substring = substring.strip()
        if "parameter" in substring:
            if debug:
                print "found parameter!"
            substring = substring.partition("parameter")[2].strip()
            parameter_name = substring.partition("=")[0].strip()
            parameter_value = substring.partition("=")[2].strip()
            parameter_value = parameter_value.partition(";")[0].strip()
            if debug:
                print "parameter name: " + parameter_name
                print "parameter value: " + parameter_value
            if parameter_name in user_parameters:
                tags["parameters"][parameter_name] = parameter_value

    tags["arbitrator_masters"] = saparbitrator.get_number_of_arbitrator_hosts(tags)

    if debug:
        print "input count: " + str(input_count)
        print "output count: " + str(output_count)
        print "inout count: " + str(inout_count)
        print "\n"

    if debug:
        print "module name: " + tags["module"]
        for key in tags["keywords"].keys():
            print "key: " + key + ":" + tags["keywords"][key]
        for io in ports:
            for item in tags["ports"][io].keys():
                print io + ": " + item
                for key in tags["ports"][io][item].keys():
                    value = tags["ports"][io][item][key]
                    if isinstance(value, int):
                        value = str(value)
                    print "\t" + key + ":" + value

    return tags
Example #7
0
def get_module_tags(filename="", bus="", keywords = [], debug=False):
	tags = {}
	tags["keywords"] = {}
	tags["ports"] = {}
	tags["module"] = ""
	tags["parameters"] = {}
		
	#need a more robust way of openning the slave

#	keywords = [
#		"DRT_ID",
#		"DRT_FLAGS",
#	]

	ports = [
		"input",
		"output",
		"inout"
	]

	#XXX only working with verilog at this time, need to extend to VHDL
	with open(filename) as slave_file:
		buf = slave_file.read()
	
	#find all the metadata
	for key in keywords:
		index = buf.find (key)
		if (index == -1):
			if debug:
				print "didn't find substring for " + key
			continue
		if debug:
			print "found substring for " + key

		substring = buf.__getslice__(index, len(buf)).splitlines()[0]
		if debug:
			print "substring: " + substring

		
		if debug:
			print "found " + key + " substring: " + substring

		substring = substring.strip()
		substring = substring.strip("//")
		substring = substring.strip("/*")
		tags["keywords"][key] = substring.partition(":")[2] 
			
				

	#remove all the comments from the code
	buf = remove_comments(buf)
	#print "no comments: \n\n" + buf

	for substring in buf.splitlines():
		if (len(substring.partition("module")[1]) == 0):
			continue
		module_string = substring.partition("module")[2]
		module_string = module_string.strip(" ")
		index = module_string.find(" ")

		if (index != -1):
			tags["module"] = module_string.__getslice__(0, index)
		else:
			tags["module"] = module_string

		if debug:
			print "module name: " + module_string
			print tags["module"]

		break
	
	#find all the ports
	#find the index of all the processing block
	substrings = buf.splitlines()

	input_count = buf.count("input")
	output_count = buf.count("output")
	inout_count = buf.count("inout")

	if debug:
		print "filename: " + filename
	
	filestring = ""
	try:
		f = open(filename)
		filestring = f.read()
		f.close()
	except:
		print "Failed to open test filename"
		return

	ldebug = debug
	define_dict = sappreproc.generate_define_table(filestring, ldebug)	

	#find all the IO's
	for io in ports:
		tags["ports"][io] = {}
		substrings = buf.splitlines()	
		for substring in substrings:
			if debug:
				print "working on substring: " + substring
			substring = substring.strip()
			#if line doesn't start with an input/output or inout
			if (not substring.startswith(io)):
				continue
			#if the line does start with input/output or inout but is used in a name then bail
			if (not substring.partition(io)[2][0].isspace()):
				continue
			#one style will declare the port names after the ports list
			if (substring.endswith(";")):
				substring = substring.rstrip(";")
			#the other stile will include the entire port definition within the port declaration
			if (substring.endswith(",")):
				substring = substring.rstrip(",")
			if debug:
				print "substring: " + substring
			substring = substring.partition(io)[2]
			if (len(substring.partition("reg")[1]) != 0):
				substring = substring.partition("reg")[2]
			substring = substring.strip()
			max_val = -1
			min_val = -1
			if (len(substring.partition("]")[2]) != 0):
				#we have a range to work with?
				length_string = substring.partition("]")[0] + "]"
				substring = substring.partition("]")[2] 
				substring = substring.strip()
				length_string = length_string.strip()
				if debug:
					print "length string: " + length_string

				ldebug = debug

				length_string = sappreproc.resolve_defines(length_string, define_dict, debug=ldebug)
				length_string = sappreproc.evaluate_range(length_string)
				length_string = length_string.partition("]")[0]
				length_string = length_string.strip("[")
				if debug:
					print "length string: " + length_string
				max_val = string.atoi(length_string.partition(":")[0])
				min_val = string.atoi(length_string.partition(":")[2])

			tags["ports"][io][substring] = {}

			if (max_val != -1):
				tags["ports"][io][substring]["max_val"] = max_val
				tags["ports"][io][substring]["min_val"] = min_val
				tags["ports"][io][substring]["size"] = (max_val + 1) - min_val
			else:
				tags["ports"][io][substring]["size"] = 1
			
			#print io + ": " + substring

	#find all the parameters
	substrings = buf.splitlines()
	for substring in substrings:
		substring = substring.strip()	
		if ("parameter" in substring):
			if debug:
				print "found parameter!"
			substring = substring.partition("parameter")[2].strip()
			parameter_name = substring.partition("=")[0].strip()
			parameter_value = substring.partition("=")[2].strip()
			parameter_value = parameter_value.partition(";")[0].strip()
			if debug:
				print "parameter name: " + parameter_name
				print "parameter value: " + parameter_value
			tags["parameters"][parameter_name] = parameter_value




	if debug:
		print "input count: " + str(input_count)
		print "output count: " + str(output_count)
		print "inout count: " + str(inout_count)
		print "\n"
			
	if debug:
		print "module name: " + tags["module"]
		for key in tags["keywords"].keys():
			print "key: " + key + ":" + tags["keywords"][key]
		for io in ports:
			for item in tags["ports"][io].keys():
				print io + ": " + item
				for key in tags["ports"][io][item].keys():
					value = tags["ports"][io][item][key]
					if (isinstance( value, int)):
						value = str(value)
					print "\t" + key + ":" + value
	return tags