<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> import sys <EOL> import os <EOL> import collections <EOL> import tempfile <EOL> import veriloggen . core . vtypes as vtypes <EOL> import veriloggen . core . module as module <EOL> import veriloggen . core . function as function <EOL> import veriloggen . core . task as task <EOL> import pyverilog . vparser . ast as vast <EOL> from pyverilog . vparser . parser import VerilogCodeParser <EOL> from pyverilog . dataflow . modulevisitor import ModuleVisitor <EOL> def read_verilog_stubmodule ( * filelist , ** opt ) : <EOL> module_dict = to_module_dict ( * filelist , ** opt ) <EOL> stubs = collections . OrderedDict ( [ ( name , module . StubModule ( name ) ) <EOL> for name in module_dict . keys ( ) ] ) <EOL> return stubs <EOL> def read_verilog_module ( * filelist , ** opt ) : <EOL> module_dict = to_module_dict ( * filelist , ** opt ) <EOL> visitor = VerilogReadVisitor ( ) <EOL> modules = collections . OrderedDict ( [ ( name , visitor . visit ( m ) ) <EOL> for name , m in module_dict . items ( ) ] ) <EOL> return modules <EOL> def read_verilog_module_str ( code , encode = '<STR_LIT:utf-8>' ) : <EOL> tmp = tempfile . NamedTemporaryFile ( ) <EOL> tmp . write ( code . encode ( encode ) ) <EOL> tmp . read ( ) <EOL> filename = tmp . name <EOL> ret = read_verilog_module ( filename ) <EOL> tmp . close ( ) <EOL> return ret <EOL> def read_verilog_stubmodule_str ( code , encode = '<STR_LIT:utf-8>' ) : <EOL> tmp = tempfile . NamedTemporaryFile ( ) <EOL> tmp . write ( code . encode ( encode ) ) <EOL> tmp . read ( ) <EOL> filename = tmp . name <EOL> ret = read_verilog_stubmodule ( filename ) <EOL> tmp . close ( ) <EOL> return ret <EOL> def to_module_dict ( * filelist , ** opt ) : <EOL> ast = to_ast ( * filelist , ** opt ) <EOL> module_visitor = ModuleVisitor ( ) <EOL> module_visitor . visit ( ast ) <EOL> module_names = module_visitor . get_modulenames ( ) <EOL> moduleinfotable = module_visitor . get_moduleinfotable ( ) <EOL> moduleinfo = moduleinfotable . getDefinitions ( ) <EOL> module_dict = collections . OrderedDict ( [ ( n , d . definition ) for n , d in moduleinfo . items ( ) ] ) <EOL> return module_dict <EOL> def to_ast ( * filelist , ** opt ) : <EOL> include = opt [ '<STR_LIT>' ] if '<STR_LIT>' in opt else ( ) <EOL> define = opt [ '<STR_LIT>' ] if '<STR_LIT>' in opt else ( ) <EOL> if not isinstance ( include , tuple ) and not isinstance ( include , list ) : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> type ( include ) ) <EOL> if not isinstance ( include , tuple ) and not isinstance ( include , list ) : <EOL> raise TypeError ( '<STR_LIT>' % <EOL> type ( include ) ) <EOL> code_parser = VerilogCodeParser ( filelist , <EOL> preprocess_include = include , <EOL> preprocess_define = define ) <EOL> ast = code_parser . parse ( ) <EOL> return ast <EOL> def to_tuple ( s ) : <EOL> if not isinstance ( s , ( list , tuple ) ) : <EOL> return tuple ( [ s ] ) <EOL> return s <EOL> class VerilogReadVisitor ( object ) : <EOL> def __init__ ( self ) : <EOL> self . m = None <EOL> self . module_stack = [ ] <EOL> def push_module ( self , m ) : <EOL> self . module_stack . append ( self . m ) <EOL> self . m = m <EOL> def pop_module ( self ) : <EOL> self . m = self . module_stack . pop ( ) <EOL> def add_object ( self , obj ) : <EOL> if isinstance ( self . m , module . Module ) : <EOL> self . m . add_object ( obj ) <EOL> def generic_visit ( self , node ) : <EOL> for c in node . children ( ) : <EOL> self . visit ( c ) <EOL> def visit ( self , node ) : <EOL> method = '<STR_LIT>' + node . __class__ . __name__ <EOL> visitor = getattr ( self , method , self . generic_visit ) <EOL> return visitor ( node ) <EOL> def visit_ModuleDef ( self , node ) : <EOL> m = module . Module ( node . name ) <EOL> self . push_module ( m ) <EOL> self . generic_visit ( node ) <EOL> self . pop_module ( ) <EOL> return m <EOL> def visit_Paramlist ( self , node ) : <EOL> params = [ ] <EOL> for param in node . params : <EOL> p = self . visit ( param ) <EOL> params . append ( p ) <EOL> return params <EOL> def visit_Portlist ( self , node ) : <EOL> ports = [ ] <EOL> for port in node . ports : <EOL> p = self . visit ( port ) <EOL> ports . append ( p ) <EOL> return ports <EOL> def visit_Port ( self , node ) : <EOL> if node . type is None : <EOL> name = node . name <EOL> p = vtypes . AnyType ( name = name ) <EOL> self . add_object ( p ) <EOL> return p <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> _type = getattr ( vtypes , node . type , None ) <EOL> if _type is None : <EOL> raise TypeError ( "<STR_LIT>" % node . type ) <EOL> p = _type ( name , width ) <EOL> self . add_object ( p ) <EOL> return p <EOL> def visit_Width ( self , node ) : <EOL> msb = self . visit ( node . msb ) <EOL> width = msb + <NUM_LIT:1> <EOL> return width <EOL> def visit_Length ( self , node ) : <EOL> lsb = self . visit ( node . lsb ) <EOL> length = lsb + <NUM_LIT:1> <EOL> return length <EOL> def visit_Identifier ( self , node ) : <EOL> if node . scope is not None : <EOL> labels = self . visit ( node . scope ) <EOL> labels . append ( node . name ) <EOL> return vtypes . Scope ( * labels ) <EOL> if not isinstance ( self . m , module . Module ) : <EOL> return vtypes . AnyType ( name = node . name ) <EOL> return self . m . find_identifier ( node . name ) <EOL> def visit_IntConst ( self , node ) : <EOL> return vtypes . Int ( node . value ) <EOL> def visit_FloatConst ( self , node ) : <EOL> return vtypes . Float ( node . value ) <EOL> def visit_StringConst ( self , node ) : <EOL> return vtypes . Str ( node . value ) <EOL> def visit_Input ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Input ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Output ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Output ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Inout ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Inout ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Tri ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Tri ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Wire ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Wire ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Reg ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Reg ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_WireArray ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> length = self . visit ( node . length ) <EOL> signed = node . signed <EOL> obj = vtypes . Wire ( width , length = length , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> obj . _set_raw_length ( self . visit ( node . length . msb ) , self . visit ( node . length . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_RegArray ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> length = self . visit ( node . length ) <EOL> signed = node . signed <EOL> obj = vtypes . Reg ( width , length = length , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> obj . _set_raw_length ( self . visit ( node . length . msb ) , self . visit ( node . length . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Integer ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> obj = vtypes . Integer ( width , signed = signed , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Real ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> obj = vtypes . Real ( width , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Genvar ( self , node ) : <EOL> name = node . name <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> obj = vtypes . Genvar ( width , name = name ) <EOL> if node . width is not None : <EOL> obj . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( obj ) <EOL> return obj <EOL> def visit_Ioport ( self , node ) : <EOL> first = self . visit ( node . first ) <EOL> second = self . visit ( node . second ) if node . second is not None else None <EOL> return ( first , second ) <EOL> def visit_Parameter ( self , node ) : <EOL> name = node . name <EOL> value = self . visit ( node . value ) <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> param = vtypes . Parameter ( value , width , signed , name = name ) <EOL> if node . width is not None : <EOL> param . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( param ) <EOL> return param <EOL> def visit_Localparam ( self , node ) : <EOL> name = node . name <EOL> value = self . visit ( node . value ) <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> param = vtypes . Localparam ( value , width , signed , name = name ) <EOL> if node . width is not None : <EOL> param . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( param ) <EOL> return param <EOL> def visit_Supply ( self , node ) : <EOL> name = node . name <EOL> value = self . visit ( node . value ) <EOL> width = self . visit ( node . width ) if node . width is not None else None <EOL> signed = node . signed <EOL> param = vtypes . Supply ( value , width , signed , name = name ) <EOL> if node . width is not None : <EOL> param . _set_raw_width ( self . visit ( node . width . msb ) , self . visit ( node . width . lsb ) ) <EOL> self . add_object ( param ) <EOL> return param <EOL> def visit_Decl ( self , node ) : <EOL> decl = [ self . visit ( d ) for d in node . list ] <EOL> return decl <EOL> def visit_Concat ( self , node ) : <EOL> vars = [ self . visit ( var ) for var in node . list ] <EOL> return vtypes . Cat ( * vars ) <EOL> def visit_LConcat ( self , node ) : <EOL> vars = [ self . visit ( var ) for var in node . list ] <EOL> return vtypes . Cat ( * vars ) <EOL> def visit_Repeat ( self , node ) : <EOL> var = self . visit ( node . value ) <EOL> times = self . visit ( node . times ) <EOL> return vtypes . Repeat ( var , times ) <EOL> def visit_Partselect ( self , node ) : <EOL> var = self . visit ( node . var ) <EOL> msb = self . visit ( node . msb ) <EOL> lsb = self . visit ( node . lsb ) <EOL> return vtypes . Slice ( var , msb , lsb ) <EOL> def visit_Pointer ( self , node ) : <EOL> var = self . visit ( node . var ) <EOL> pos = self . visit ( node . ptr ) <EOL> return vtypes . Pointer ( var , pos ) <EOL> def visit_Lvalue ( self , node ) : <EOL> return self . visit ( node . var ) <EOL> def visit_Rvalue ( self , node ) : <EOL> return self . visit ( node . var ) <EOL> def visit_Uplus ( self , node ) : <EOL> return vtypes . Uplus ( self . visit ( node . right ) ) <EOL> def visit_Uminus ( self , node ) : <EOL> return vtype . Uminus ( self . visit ( node . right ) ) <EOL> def visit_Ulnot ( self , node ) : <EOL> return vtypes . Ulnot ( self . visit ( node . right ) ) <EOL> def visit_Unot ( self , node ) : <EOL> return vtypes . Unot ( self . visit ( node . right ) ) <EOL> def visit_Uand ( self , node ) : <EOL> return vtypes . Uand ( self . visit ( node . right ) ) <EOL> def visit_Unand ( self , node ) : <EOL> return vtypes . Unand ( self . visit ( node . right ) ) <EOL> def visit_Uor ( self , node ) : <EOL> return vtypes . Uor ( self . visit ( node . right ) ) <EOL> def visit_Unor ( self , node ) : <EOL> return vtypes . Unor ( self . visit ( node . right ) ) <EOL> def visit_Uxor ( self , node ) : <EOL> return vtypes . Uxor ( self . visit ( node . right ) ) <EOL> def visit_Uxnor ( self , node ) : <EOL> return vtypes . Uxnor ( self . visit ( node . right ) ) <EOL> def visit_Power ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Power ( left , right ) <EOL> def visit_Times ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Times ( left , right ) <EOL> def visit_Divide ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Divide ( left , right ) <EOL> def visit_Mod ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Mod ( left , right ) <EOL> def visit_Plus ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Plus ( left , right ) <EOL> def visit_Minus ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Minus ( left , right ) <EOL> def visit_Sll ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Sll ( left , right ) <EOL> def visit_Srl ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Srl ( left , right ) <EOL> def visit_Sra ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Sra ( left , right ) <EOL> def visit_LessThan ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . LessThan ( left , right ) <EOL> def visit_GreaterThan ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . GreaterThan ( left , right ) <EOL> def visit_LessEq ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . LessEq ( left , right ) <EOL> def visit_GreaterEq ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . GreaterEq ( left , right ) <EOL> def visit_Eq ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Eq ( left , right ) <EOL> def visit_NotEq ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . NotEq ( left , right ) <EOL> def visit_Eql ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Eql ( left , right ) <EOL> def visit_NotEql ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . NotEql ( left , right ) <EOL> def visit_And ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . And ( left , right ) <EOL> def visit_Xor ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Xor ( left , right ) <EOL> def visit_Xnor ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Xnor ( left , right ) <EOL> def visit_Or ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Or ( left , right ) <EOL> def visit_Land ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Land ( left , right ) <EOL> def visit_Lor ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> return vtypes . Lor ( left , right ) <EOL> def visit_Cond ( self , node ) : <EOL> condition = self . visit ( node . cond ) <EOL> true_value = self . visit ( node . true_value ) <EOL> false_value = self . visit ( node . false_value ) <EOL> return vtypes . Cond ( condition , true_value , false_value ) <EOL> def visit_Assign ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> ldelay = self . visit ( node . ldelay . value ) if node . ldelay is not None else None <EOL> rdelay = self . visit ( node . rdelay . value ) if node . rdelay is not None else None <EOL> subst = vtypes . Subst ( left , right , ldelay = ldelay , rdelay = rdelay ) <EOL> assign = vtypes . Assign ( subst ) <EOL> self . add_object ( assign ) <EOL> return assign <EOL> def visit_Always ( self , node ) : <EOL> self . push_module ( None ) <EOL> sensitivity = self . visit ( node . sens_list ) <EOL> statement = to_tuple ( self . visit ( node . statement ) ) <EOL> always = vtypes . Always ( * sensitivity ) <EOL> always = always ( * statement ) <EOL> self . pop_module ( ) <EOL> self . add_object ( always ) <EOL> return always <EOL> def visit_SensList ( self , node ) : <EOL> return [ self . visit ( s ) for s in node . list ] <EOL> def visit_Sens ( self , node ) : <EOL> if node . type == '<STR_LIT>' : <EOL> sig = self . visit ( node . sig ) <EOL> return vtypes . Posedge ( sig ) <EOL> if node . type == '<STR_LIT>' : <EOL> sig = self . visit ( node . sig ) <EOL> return vtypes . Negedge ( sig ) <EOL> if node . type == '<STR_LIT:all>' : <EOL> return vtypes . SensitiveAll ( ) <EOL> if node . type == '<STR_LIT>' : <EOL> sig = self . visit ( node . sig ) <EOL> return sig <EOL> raise TypeError ( "<STR_LIT>" % node . type ) <EOL> def visit_BlockingSubstitution ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> ldelay = self . visit ( node . ldelay . delay ) if node . ldelay is not None else None <EOL> rdelay = self . visit ( node . rdelay . delay ) if node . rdelay is not None else None <EOL> return vtypes . Subst ( left , right , blk = True , ldelay = ldelay , rdelay = rdelay ) <EOL> def visit_NonblockingSubstitution ( self , node ) : <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> ldelay = self . visit ( node . ldelay . delay ) if node . ldelay is not None else None <EOL> rdelay = self . visit ( node . rdelay . delay ) if node . rdelay is not None else None <EOL> return vtypes . Subst ( left , right , blk = False , ldelay = ldelay , rdelay = rdelay ) <EOL> def visit_IfStatement ( self , node ) : <EOL> if isinstance ( self . m , ( module . GenerateFor , module . GenerateIf ) ) : <EOL> return self . _visit_GenerateIf ( node ) <EOL> condition = self . visit ( node . cond ) <EOL> true_statement = self . visit ( node . true_statement ) <EOL> false_statement = ( self . visit ( node . false_statement ) <EOL> if node . false_statement is not None else None ) <EOL> true_statement = to_tuple ( true_statement ) <EOL> false_statement = ( to_tuple ( false_statement ) <EOL> if false_statement is not None else None ) <EOL> _if = vtypes . If ( condition ) <EOL> _if = _if ( * true_statement ) <EOL> if false_statement is not None : <EOL> _if = _if ( * false_statement ) <EOL> return _if <EOL> def visit_ForStatement ( self , node ) : <EOL> if isinstance ( self . m , ( module . GenerateFor , module . GenerateIf ) ) : <EOL> return self . _visit_GenerateFor ( node ) <EOL> pre = self . visit ( node . pre ) <EOL> condition = self . visit ( node . cond ) <EOL> post = self . visit ( node . post ) <EOL> statement = to_tuple ( self . visit ( node . statement ) ) <EOL> _for = vtypes . For ( pre , condition , post ) <EOL> _for = _for ( * statement ) <EOL> return _for <EOL> def visit_WhileStatement ( self , node ) : <EOL> condition = self . visit ( node . cond ) <EOL> statement = to_tuple ( self . visit ( node . statement ) ) <EOL> _while = vtypes . While ( pre , condition , post ) <EOL> _while = _while ( * statement ) <EOL> return _while <EOL> def visit_CaseStatement ( self , node ) : <EOL> comp = self . visit ( node . comp ) <EOL> statement = tuple ( [ self . visit ( case ) for case in node . caselist ] ) <EOL> case = vtypes . Case ( comp ) <EOL> case = case ( * statement ) <EOL> return case <EOL> def visit_CasexStatement ( self , node ) : <EOL> comp = self . visit ( node . comp ) <EOL> statement = tuple ( [ self . visit ( case ) for case in node . caselist ] ) <EOL> case = vtypes . Casex ( comp ) <EOL> case = case ( * statement ) <EOL> return case <EOL> def visit_Case ( self , node ) : <EOL> condition = tuple ( [ self . visit ( c ) for c in node . cond ] ) if node . cond else [ None ] <EOL> statement = to_tuple ( self . visit ( node . statement ) ) <EOL> when = vtypes . When ( * condition ) <EOL> when = when ( * statement ) <EOL> return when <EOL> def visit_Block ( self , node ) : <EOL> statements = [ self . visit ( statement ) for statement in node . statements ] <EOL> return statements <EOL> def visit_Initial ( self , node ) : <EOL> statement = to_tuple ( self . visit ( node . statement ) ) <EOL> initial = vtypes . Initial ( * statement ) <EOL> self . add_object ( initial ) <EOL> return initial <EOL> def visit_EventStatement ( self , node ) : <EOL> sensitivity = self . visit ( node . sens_list ) <EOL> event = vtypes . Event ( * sensitivity ) <EOL> return event <EOL> def visit_WaitStatement ( self , node ) : <EOL> condition = self . visit ( node . cond ) <EOL> statement = to_tuple ( self . visit ( node . statement ) ) if node . statement else None <EOL> wait = vtypes . Wait ( condition ) <EOL> if statement : wait = wait ( * statement ) <EOL> return wait <EOL> def visit_ForeverStatement ( self , node ) : <EOL> statement = to_tuple ( self . visit ( node . statement ) ) <EOL> forever = vtypes . Forever ( * statement ) <EOL> return forever <EOL> def visit_DelayStatement ( self , node ) : <EOL> value = self . visit ( node . delay ) <EOL> delay = vtypes . Delay ( value ) <EOL> return delay <EOL> def visit_InstanceList ( self , node ) : <EOL> return [ self . visit ( instance ) for instance in node . instances ] <EOL> def visit_Instance ( self , node ) : <EOL> m = module . StubModule ( node . module ) <EOL> instname = node . name <EOL> params = [ self . visit ( param ) for param in node . parameterlist ] <EOL> ports = [ self . visit ( port ) for port in node . portlist ] <EOL> if node . array is not None : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> instance = module . Instance ( m , instname , params , ports ) <EOL> self . add_object ( instance ) <EOL> return instance <EOL> def visit_ParamArg ( self , node ) : <EOL> paramname = node . paramname <EOL> argname = self . visit ( node . argname ) <EOL> return ( paramname , argname ) <EOL> def visit_PortArg ( self , node ) : <EOL> portname = node . portname <EOL> argname = self . visit ( node . argname ) if node . argname is not None else None <EOL> return ( portname , argname ) <EOL> def visit_Function ( self , node ) : <EOL> self . push_module ( None ) <EOL> name = node . name <EOL> width = self . visit ( node . retwidth ) if node . retwidth is not None else None <EOL> func = function . Function ( name , width ) <EOL> if node . retwidth is not None : <EOL> func . _set_raw_width ( self . visit ( node . retwidth . msb ) , self . visit ( node . retwidth . lsb ) ) <EOL> statement = [ self . visit ( s ) for s in node . statement ] <EOL> body = [ ] <EOL> for s in statement : <EOL> if isinstance ( s , ( tuple , list ) ) : <EOL> for d in s : <EOL> if isinstance ( d , vtypes . Input ) : <EOL> t = func . Input ( d . name , d . width , d . length , d . signed , d . value ) <EOL> if d . width_msb is not None and d . width_lsb is not None : <EOL> t . _set_raw_width ( d . width_msb , d . width_lsb ) <EOL> elif isinstance ( d , vtypes . Reg ) : <EOL> t = func . Reg ( d . name , d . width , d . length , d . signed , d . value ) <EOL> if d . width_msb is not None and d . width_lsb is not None : <EOL> t . _set_raw_width ( d . width_msb , d . width_lsb ) <EOL> elif isinstance ( d , vtypes . Integer ) : <EOL> t = func . Integer ( d . name , d . width , d . length , d . signed , d . value ) <EOL> if d . width_msb is not None and d . width_lsb is not None : <EOL> t . _set_raw_width ( d . width_msb , d . width_lsb ) <EOL> else : <EOL> body . append ( s ) <EOL> else : <EOL> body . append ( s ) <EOL> func . Body ( * body ) <EOL> self . pop_module ( ) <EOL> self . add_object ( func ) <EOL> return func <EOL> def visit_FunctionCall ( self , node ) : <EOL> name = self . visit ( node . name ) <EOL> args = tuple ( [ self . visit ( arg ) for arg in node . args ] ) <EOL> call = function . FunctionCall ( name , * args ) <EOL> return call <EOL> def visit_Task ( self , node ) : <EOL> self . push_module ( None ) <EOL> name = node . name <EOL> _task = task . Task ( name ) <EOL> statement = [ self . visit ( s ) for s in node . statement ] <EOL> body = [ ] <EOL> for s in statement : <EOL> if isinstance ( s , ( tuple , list ) ) : <EOL> for d in s : <EOL> if isinstance ( d , vtypes . Input ) : <EOL> t = _task . Input ( d . name , d . width , d . length , d . signed , d . value ) <EOL> if d . width_msb is not None and d . width_lsb is not None : <EOL> t . _set_raw_width ( d . width_msb , d . width_lsb ) <EOL> elif isinstance ( d , vtypes . Reg ) : <EOL> t = _task . Reg ( d . name , d . width , d . length , d . signed , d . value ) <EOL> if d . width_msb is not None and d . width_lsb is not None : <EOL> t . _set_raw_width ( d . width_msb , d . width_lsb ) <EOL> elif isinstance ( d , vtypes . Integer ) : <EOL> t = _task . Integer ( d . name , d . width , d . length , d . signed , d . value ) <EOL> if d . width_msb is not None and d . width_lsb is not None : <EOL> t . _set_raw_width ( d . width_msb , d . width_lsb ) <EOL> else : <EOL> body . append ( s ) <EOL> else : <EOL> body . append ( s ) <EOL> _task . Body ( * body ) <EOL> self . pop_module ( ) <EOL> self . add_object ( _task ) <EOL> return _task <EOL> def visit_TaskCall ( self , node ) : <EOL> name = self . visit ( node . name ) <EOL> args = tuple ( [ self . visit ( arg ) for arg in node . args ] ) <EOL> call = task . TaskCall ( name , args ) <EOL> return call <EOL> def _visit_GenerateFor ( self , item ) : <EOL> pre = self . visit ( item . pre ) <EOL> cond = self . visit ( item . cond ) <EOL> post = self . visit ( item . post ) <EOL> scope = ( item . statement . scope <EOL> if isinstance ( item . statement , vast . Block ) <EOL> else None ) <EOL> _for = module . GenerateFor ( self . m , pre , cond , post , scope ) <EOL> ret = _for <EOL> self . add_object ( _for ) <EOL> self . push_module ( _for ) <EOL> statement = self . visit ( item . statement ) <EOL> self . pop_module ( ) <EOL> return ret <EOL> def _visit_GenerateIf ( self , item ) : <EOL> cond = self . visit ( item . cond ) <EOL> true_scope = ( item . true_statement . scope <EOL> if isinstance ( item . true_statement , vast . Block ) <EOL> else None ) <EOL> false_scope = ( item . false_statement . scope <EOL> if isinstance ( item . false_statement , vast . Block ) <EOL> else None ) <EOL> _if_true = module . GenerateIf ( self . m , cond , true_scope ) <EOL> ret = _if_true <EOL> self . add_object ( _if_true ) <EOL> self . push_module ( _if_true ) <EOL> statement = self . visit ( item . true_statement ) <EOL> self . pop_module ( ) <EOL> _if_false = _if_true . Else ( false_scope ) <EOL> self . push_module ( _if_false ) <EOL> statement = ( self . visit ( item . false_statement ) <EOL> if item . false_statement is not None else None ) <EOL> self . pop_module ( ) <EOL> return ret <EOL> def visit_GenerateStatement ( self , node ) : <EOL> ret = [ ] <EOL> for item in node . items : <EOL> if isinstance ( item , vast . ForStatement ) : <EOL> ret . append ( self . _visit_GenerateFor ( item ) ) <EOL> elif isinstance ( item , vast . IfStatement ) : <EOL> ret . append ( self . _visit_GenerateIf ( item ) ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> return ret <EOL> def visit_SystemCall ( self , node ) : <EOL> cmd = node . syscall <EOL> args = tuple ( [ self . visit ( arg ) for arg in node . args ] ) <EOL> systask = vtypes . SystemTask ( cmd , * args ) <EOL> return systask <EOL> def visit_IdentifierScopeLabel ( self , node ) : <EOL> if node . loop is None : <EOL> return node . name <EOL> index = self . visit ( node . loop ) <EOL> return vtypes . ScopeIndex ( node . name , index ) <EOL> def visit_IdentifierScope ( self , node ) : <EOL> args = [ self . visit ( label ) for label in node . labellist ] <EOL> return args <EOL> def visit_Pragma ( self , node ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def visit_PragmaEntry ( self , node ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def visit_Disable ( self , node ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def visit_ParallelBlock ( self , node ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def visit_SingleStatement ( self , node ) : <EOL> statement = self . visit ( node . statement ) <EOL> if isinstance ( statement , vtypes . Delay ) : return statement <EOL> return vtypes . SingleStatement ( statement ) </s>
