#NEWLINE# def create_verilator_py_wrapper( model , wrapper_filename , lib_file , cdefs , vlinetrace ) : #NEWLINE# #INDENT# template_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) #NEWLINE# template_filename = ( ( template_dir + os . path . sep ) + 'verilator_wrapper.templ.py' ) #NEWLINE# port_defs = [ ] #NEWLINE# set_inputs = [ ] #NEWLINE# set_comb = [ ] #NEWLINE# set_next = [ ] #NEWLINE# from cpp_helpers import recurse_port_hierarchy #NEWLINE# for x in model . get_ports ( preserve_hierarchy = True ) : #NEWLINE# #INDENT# recurse_port_hierarchy ( x , port_defs ) #NEWLINE# #UNINDENT# for port in model . get_inports ( ) : #NEWLINE# #INDENT# if ( port . name == 'clk' ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# input_ = set_input_stmt ( port ) #NEWLINE# set_inputs . extend ( input_ ) #NEWLINE# #UNINDENT# for port in model . get_outports ( ) : #NEWLINE# #INDENT# ( comb , next_ ) = set_output_stmt ( port ) #NEWLINE# set_comb . extend ( comb ) #NEWLINE# set_next . extend ( next_ ) #NEWLINE# #UNINDENT# indent_four = '\n    ' #NEWLINE# indent_six = '\n      ' #NEWLINE# with open ( template_filename , 'r' ) as template , open ( wrapper_filename , 'w' ) as output : #NEWLINE# #INDENT# py_src = template . read ( ) #NEWLINE# py_src = py_src . format ( model_name = model . class_name , port_decls = cdefs , lib_file = lib_file , port_defs = indent_four . join ( port_defs ) , set_inputs = indent_six . join ( set_inputs ) , set_comb = indent_six . join ( set_comb ) , set_next = indent_six . join ( set_next ) , vlinetrace = ( '1' if vlinetrace else '0' ) ) #NEWLINE# output . write ( py_src )