예제 #1
0
def main():
    INFO = "Verilog Preprocessor"
    VERSION = pyverilog.utils.version.VERSION
    USAGE = "Usage: python example_preprocessor.py file ..."

    def showVersion():
        print(INFO)
        print(VERSION)
        print(USAGE)
        sys.exit()

    optparser = OptionParser()
    optparser.add_option(
        "-v", "--version", action="store_true", dest="showversion", default=False, help="Show the version"
    )
    optparser.add_option("-I", "--include", dest="include", action="append", default=[], help="Include path")
    optparser.add_option("-D", dest="define", action="append", default=[], help="Macro Definition")
    (options, args) = optparser.parse_args()

    filelist = args
    if options.showversion:
        showVersion()

    for f in filelist:
        if not os.path.exists(f):
            raise IOError("file not found: " + f)

    if len(filelist) == 0:
        showVersion()

    text = preprocess(filelist, include=options.include, define=options.define)

    print(text)
예제 #2
0
def main():
    INFO = "Verilog Lexer"
    VERSION = pyverilog.__version__
    USAGE = "Usage: python example_lexer.py file ..."

    def showVersion():
        print(INFO)
        print(VERSION)
        print(USAGE)
        sys.exit()

    optparser = OptionParser()
    optparser.add_option("-v",
                         "--version",
                         action="store_true",
                         dest="showversion",
                         default=False,
                         help="Show the version")
    optparser.add_option("-I",
                         "--include",
                         dest="include",
                         action="append",
                         default=[],
                         help="Include path")
    optparser.add_option("-D",
                         dest="define",
                         action="append",
                         default=[],
                         help="Macro Definition")
    (options, args) = optparser.parse_args()

    filelist = args
    if options.showversion:
        showVersion()

    for f in filelist:
        if not os.path.exists(f):
            raise IOError("file not found: " + f)

    if len(filelist) == 0:
        showVersion()

    text = preprocess(filelist, include=options.include, define=options.define)

    dump = dump_tokens(text)

    print(dump)
예제 #3
0
파일: hierarchy.py 프로젝트: shuolai/fasoc
def verilog_reader(verilog_file,include_line_number,start_keywords):
	lex_dict = defaultdict(list)
	parse_dict = defaultdict(list)
	veri_parse_line_no_arr = []
	nospace_line_arr = []
	line_array_dict = defaultdict(list)
	start_line_dict = dict.fromkeys(list(start_keywords.keys()),0)# Initializing

# Parsing Verilog
# ==============================================================================
	output_buf = 'preprocess.out'
	output_buf = StringIO()
	ast, directives = parse(verilog_file,
                        preprocess_include=options.include,
                        preprocess_define=options.define)
	ast.show(buf=output_buf)
	parser_result = output_buf.getvalue()

	lex = preprocess(verilog_file,
                  include=options.include,
                  define=options.define)
	lex_result = dump_tokens(lex)

# Parsing Verilog Lines
# ==============================================================================
	for line in parser_result.splitlines():
		nospace_line = re.sub(r'\s','',line)
		veri_parse_line_no = int((re.findall(r'\(at(\d+)\)',nospace_line))[0]) - include_line_number #250 is line numbers of cmsdk_mcu_defs.v and 55 is line numbers of cmsdk_ahb_memory_defs.v for destination

		veri_parse_line_no_arr.append(veri_parse_line_no)
		nospace_line_arr.append(nospace_line)

		veri_parse_left_subject = (nospace_line.split(':'))[0]
		veri_parse_right_subject = (re.findall(r'(\S+)\(at\d+\)',(nospace_line.split(':'))[-1]))
		if veri_parse_right_subject != []:
			veri_parse_right_subject = veri_parse_right_subject[0]

		for task in start_keywords:
			start_left_keyword = start_keywords[task][0]
			start_line_offset = start_keywords[task][1] # start_keywords[task][1] is line offset: is 1 for source with Moduledef keyword
			start_right_flag = start_keywords[task][2] # start_keywords[task][2] determines whether should we consider veri_parse_src_right_subject as we do for source with options.module_name for Instantiation keyword
			start_right_keyword = start_keywords[task][3]
			array_line_keyword = start_keywords[task][4]

			if not start_right_flag:
				if veri_parse_left_subject == start_left_keyword:
					start_line = veri_parse_line_no + start_line_offset
					start_line_dict[task] = start_line
			else:
				if (veri_parse_left_subject == start_left_keyword) and (veri_parse_right_subject == start_right_keyword):
					start_line = veri_parse_line_no + start_line_offset
					start_line_dict[task] = start_line

			if veri_parse_left_subject == array_line_keyword:
				line_array_dict[task].append(veri_parse_line_no)

		parse_dict[veri_parse_line_no].append([veri_parse_left_subject, veri_parse_right_subject])

	for line in lex_result.splitlines():
		veri_lex_line_no = int((re.findall(r'\S+\s\S+\s(\d+)',line))[0]) - include_line_number #250 is line numbers of cmsdk_mcu_defs.v and 55 is line numbers of cmsdk_ahb_memory_defs.v
		veri_lex_subject = (re.findall(r'\S+\s(\S+)\s\d+',line))[0]
		lex_dict[veri_lex_line_no].append(veri_lex_subject)

	# values = np.array(veri_parse_line_no_arr)
	# desired_index = (np.where(values==96))[0]
	# print(np.array(nospace_line_arr)[desired_index])

	return start_line_dict, parse_dict, line_array_dict, lex_dict
예제 #4
0
파일: lexer.py 프로젝트: hoangt/Pyverilog-1
        print(VERSION)
        print(USAGE)
        sys.exit()

    optparser = OptionParser()
    optparser.add_option("-v","--version",action="store_true",dest="showversion",
                         default=False,help="Show the version")
    optparser.add_option("-I","--include",dest="include",action="append",
                         default=[],help="Include path")
    optparser.add_option("-D",dest="define",action="append",
                         default=[],help="Macro Definition")
    (options, args) = optparser.parse_args()

    filelist = args
    if options.showversion:
        showVersion()

    for f in filelist:
        if not os.path.exists(f): raise IOError("file not found: " + f)

    if len(filelist) == 0:
        showVersion()
        
    text = preprocess(filelist, 
                      preprocess_include=options.include,
                      preprocess_define=options.define)

    dump = dump_tokens(text)
    
    print(dump)
예제 #5
0
        print(VERSION)
        print(USAGE)
        sys.exit()

    optparser = OptionParser()
    optparser.add_option("-v","--version",action="store_true",dest="showversion",
                         default=False,help="Show the version")
    optparser.add_option("-I","--include",dest="include",action="append",
                         default=[],help="Include path")
    optparser.add_option("-D",dest="define",action="append",
                         default=[],help="Macro Definition")
    (options, args) = optparser.parse_args()

    filelist = args
    if options.showversion:
        showVersion()

    for f in filelist:
        if not os.path.exists(f): raise IOError("file not found: " + f)

    if len(filelist) == 0:
        showVersion()
        
    text = preprocess(filelist, 
                      preprocess_include=options.include,
                      preprocess_define=options.define)

    dump = dump_tokens(text)
    
    print(dump)