<s> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> import sys <EOL> import os <EOL> import math <EOL> import re <EOL> import functools <EOL> from jinja2 import Environment , FileSystemLoader <EOL> from pyverilog . vparser . ast import * <EOL> from pyverilog . utils . op2mark import op2mark <EOL> from pyverilog . utils . op2mark import op2order <EOL> DEFAULT_TEMPLATE_DIR = os . path . dirname ( os . path . abspath ( __file__ ) ) + '<STR_LIT>' <EOL> try : <EOL> import textwrap <EOL> indent = textwrap . indent <EOL> except : <EOL> def indent ( text , prefix , predicate = None ) : <EOL> if predicate is None : predicate = lambda x : x and not x . isspace ( ) <EOL> ret = [ ] <EOL> for line in text . split ( '<STR_LIT:\n>' ) : <EOL> if predicate ( line ) : <EOL> ret . append ( prefix ) <EOL> ret . append ( line ) <EOL> ret . append ( '<STR_LIT:\n>' ) <EOL> return '<STR_LIT>' . join ( ret [ : - <NUM_LIT:1> ] ) <EOL> def indent_multiline_assign ( text ) : <EOL> ret = [ ] <EOL> texts = text . split ( '<STR_LIT:\n>' ) <EOL> if len ( texts ) <= <NUM_LIT:1> : <EOL> return text <EOL> try : <EOL> p = texts [ <NUM_LIT:0> ] . index ( '<STR_LIT:=>' ) <EOL> except : <EOL> return text <EOL> ret . append ( texts [ <NUM_LIT:0> ] ) <EOL> ret . append ( '<STR_LIT:\n>' ) <EOL> ret . append ( indent ( '<STR_LIT:\n>' . join ( texts [ <NUM_LIT:1> : ] ) , '<STR_LIT:U+0020>' * ( p + <NUM_LIT:2> ) ) ) <EOL> return '<STR_LIT>' . join ( ret ) <EOL> class ConvertVisitor ( object ) : <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 generic_visit ( self , node ) : <EOL> ret = [ ] <EOL> for c in node . children ( ) : <EOL> ret . append ( self . visit ( c ) ) <EOL> return '<STR_LIT>' . join ( ret ) <EOL> def getfilename ( node ) : <EOL> return node . __class__ . __name__ . lower ( ) + '<STR_LIT>' <EOL> def escape ( s ) : <EOL> if s . startswith ( '<STR_LIT:\\>' ) : <EOL> return s + '<STR_LIT:U+0020>' <EOL> return s <EOL> def del_paren ( s ) : <EOL> if s . startswith ( '<STR_LIT:(>' ) and s . endswith ( '<STR_LIT:)>' ) : <EOL> return s [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> return s <EOL> def del_space ( s ) : <EOL> return s . replace ( '<STR_LIT:U+0020>' , '<STR_LIT>' ) <EOL> class ASTCodeGenerator ( ConvertVisitor ) : <EOL> def __init__ ( self , indentsize = <NUM_LIT:2> ) : <EOL> self . env = Environment ( loader = FileSystemLoader ( DEFAULT_TEMPLATE_DIR ) ) <EOL> self . indent = functools . partial ( indent , prefix = '<STR_LIT:U+0020>' * indentsize ) <EOL> self . template_cache = { } <EOL> def get_template ( self , filename ) : <EOL> if filename in self . template_cache : <EOL> return self . template_cache [ filename ] <EOL> template = self . env . get_template ( filename ) <EOL> self . template_cache [ filename ] = template <EOL> return template <EOL> def visit_Source ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:description>' : self . visit ( node . description ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Description ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : [ self . visit ( definition ) for definition in node . definitions ] , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_ModuleDef ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> paramlist = self . indent ( self . visit ( node . paramlist ) ) if node . paramlist is not None else '<STR_LIT>' <EOL> portlist = self . indent ( self . visit ( node . portlist ) ) if node . portlist is not None else '<STR_LIT>' <EOL> template_dict = { <EOL> '<STR_LIT>' : escape ( node . name ) , <EOL> '<STR_LIT>' : paramlist , <EOL> '<STR_LIT>' : portlist , <EOL> '<STR_LIT>' : [ self . indent ( self . visit ( item ) ) for item in node . items ] if node . items else ( ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Paramlist ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> params = [ self . visit ( param ) . replace ( '<STR_LIT:;>' , '<STR_LIT>' ) for param in node . params ] <EOL> template_dict = { <EOL> '<STR_LIT>' : params , <EOL> '<STR_LIT>' : len ( params ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Portlist ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> ports = [ self . visit ( port ) for port in node . ports ] <EOL> template_dict = { <EOL> '<STR_LIT>' : ports , <EOL> '<STR_LIT>' : len ( ports ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Port ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Width ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_space ( del_paren ( self . visit ( node . msb ) ) ) , <EOL> '<STR_LIT>' : del_space ( del_paren ( self . visit ( node . lsb ) ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Length ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_space ( del_paren ( self . visit ( node . msb ) ) ) , <EOL> '<STR_LIT>' : del_space ( del_paren ( self . visit ( node . lsb ) ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Identifier ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . scope is None else self . visit ( node . scope ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Value ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:value>' : node . value , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Constant ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:value>' : node . value , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_IntConst ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:value>' : node . value , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_FloatConst ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:value>' : node . value , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_StringConst ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:value>' : node . value , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Variable ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Input ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Output ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Inout ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Tri ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Wire ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Reg ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_WireArray ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : self . visit ( node . length ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_RegArray ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None else self . visit ( node . width ) , <EOL> '<STR_LIT>' : self . visit ( node . length ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Integer ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Real ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Genvar ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Ioport ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : node . first . __class__ . __name__ . lower ( ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . second is None else node . second . __class__ . __name__ . lower ( ) , <EOL> '<STR_LIT:name>' : escape ( node . first . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . first . width is None else self . visit ( node . first . width ) , <EOL> '<STR_LIT>' : node . first . signed or ( node . second is not None and node . second . signed ) <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Parameter ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> value = self . visit ( node . value ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None or ( value . startswith ( '<STR_LIT:">' ) and value . endswith ( '<STR_LIT:">' ) ) else self . visit ( node . width ) , <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Localparam ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> value = self . visit ( node . value ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:width>' : '<STR_LIT>' if node . width is None or ( value . startswith ( '<STR_LIT:">' ) and value . endswith ( '<STR_LIT:">' ) ) else self . visit ( node . width ) , <EOL> '<STR_LIT:value>' : value , <EOL> '<STR_LIT>' : node . signed , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Decl ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : [ self . visit ( item ) for item in node . list ] , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Concat ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> items = [ del_paren ( self . visit ( item ) ) for item in node . list ] <EOL> template_dict = { <EOL> '<STR_LIT>' : items , <EOL> '<STR_LIT>' : len ( items ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_LConcat ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> items = [ del_paren ( self . visit ( item ) ) for item in node . list ] <EOL> template_dict = { <EOL> '<STR_LIT>' : items , <EOL> '<STR_LIT>' : len ( items ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Repeat ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:value>' : del_paren ( self . visit ( node . value ) ) , <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . times ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Partselect ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . var ) , <EOL> '<STR_LIT>' : del_space ( del_paren ( self . visit ( node . msb ) ) ) , <EOL> '<STR_LIT>' : del_space ( del_paren ( self . visit ( node . lsb ) ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Pointer ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . var ) , <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . ptr ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Lvalue ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . var ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Rvalue ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . var ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Operator ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> order = op2order ( node . __class__ . __name__ ) <EOL> lorder = op2order ( node . left . __class__ . __name__ ) <EOL> rorder = op2order ( node . right . __class__ . __name__ ) <EOL> left = self . visit ( node . left ) <EOL> right = self . visit ( node . right ) <EOL> if ( ( not isinstance ( node . left , ( Sll , Srl , Sra , <EOL> LessThan , GreaterThan , LessEq , GreaterEq , <EOL> Eq , NotEq , Eql , NotEql ) ) ) and <EOL> ( lorder is not None and lorder <= order ) ) : <EOL> left = del_paren ( left ) <EOL> if ( ( not isinstance ( node . right , ( Sll , Srl , Sra , <EOL> LessThan , GreaterThan , LessEq , GreaterEq , <EOL> Eq , NotEq , Eql , NotEql ) ) ) and <EOL> ( rorder is not None and order > rorder ) ) : <EOL> right = del_paren ( right ) <EOL> template_dict = { <EOL> '<STR_LIT:left>' : left , <EOL> '<STR_LIT:right>' : right , <EOL> '<STR_LIT>' : op2mark ( node . __class__ . __name__ ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_UnaryOperator ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> right = self . visit ( node . right ) <EOL> template_dict = { <EOL> '<STR_LIT:right>' : right , <EOL> '<STR_LIT>' : op2mark ( node . __class__ . __name__ ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Uplus ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Uminus ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Ulnot ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Unot ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Uand ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Unand ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Uor ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Unor ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Uxor ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Uxnor ( self , node ) : <EOL> return self . visit_UnaryOperator ( node ) <EOL> def visit_Power ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Times ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Divide ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Mod ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Plus ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Minus ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Sll ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Srl ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Sra ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_LessThan ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_GreaterThan ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_LessEq ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_GreaterEq ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Eq ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_NotEq ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Eql ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_NotEql ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_And ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Xor ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Xnor ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Or ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Land ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Lor ( self , node ) : <EOL> return self . visit_Operator ( node ) <EOL> def visit_Cond ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> true_value = del_paren ( self . visit ( node . true_value ) ) <EOL> false_value = del_paren ( self . visit ( node . false_value ) ) <EOL> if isinstance ( node . false_value , Cond ) : <EOL> false_value = '<STR_LIT>' . join ( [ '<STR_LIT:\n>' , false_value ] ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . cond ) ) , <EOL> '<STR_LIT>' : true_value , <EOL> '<STR_LIT>' : false_value , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Assign ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:left>' : self . visit ( node . left ) , <EOL> '<STR_LIT:right>' : self . visit ( node . right ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> rslt = indent_multiline_assign ( rslt ) <EOL> return rslt <EOL> def visit_Always ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . sens_list ) , <EOL> '<STR_LIT>' : self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_SensList ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> items = [ self . visit ( item ) for item in node . list ] <EOL> template_dict = { <EOL> '<STR_LIT>' : items , <EOL> '<STR_LIT>' : len ( items ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Sens ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT:*>' if node . type == '<STR_LIT:all>' else self . visit ( node . sig ) , <EOL> '<STR_LIT:type>' : node . type if node . type == '<STR_LIT>' or node . type == '<STR_LIT>' else '<STR_LIT>' <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Substitution ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:left>' : self . visit ( node . left ) , <EOL> '<STR_LIT:right>' : self . visit ( node . right ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . ldelay is None else self . visit ( node . ldelay ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . rdelay is None else self . visit ( node . rdelay ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> rslt = indent_multiline_assign ( rslt ) <EOL> return rslt <EOL> def visit_BlockingSubstitution ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:left>' : self . visit ( node . left ) , <EOL> '<STR_LIT:right>' : self . visit ( node . right ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . ldelay is None else self . visit ( node . ldelay ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . rdelay is None else self . visit ( node . rdelay ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> rslt = indent_multiline_assign ( rslt ) <EOL> return rslt <EOL> def visit_NonblockingSubstitution ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:left>' : self . visit ( node . left ) , <EOL> '<STR_LIT:right>' : self . visit ( node . right ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . ldelay is None else self . visit ( node . ldelay ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . rdelay is None else self . visit ( node . rdelay ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> rslt = indent_multiline_assign ( rslt ) <EOL> return rslt <EOL> def visit_IfStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> true_statement = '<STR_LIT>' if node . true_statement is None else self . visit ( node . true_statement ) <EOL> false_statement = '<STR_LIT>' if node . false_statement is None else self . visit ( node . false_statement ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . cond ) ) , <EOL> '<STR_LIT>' : true_statement , <EOL> '<STR_LIT>' : false_statement , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_ForStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' if node . pre is None else del_space ( self . visit ( node . pre ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . cond is None else del_space ( del_paren ( self . visit ( node . cond ) ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . post is None else del_space ( self . visit ( node . post ) . replace ( '<STR_LIT:;>' , '<STR_LIT>' ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . statement is None else self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_WhileStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' if node . cond is None else del_paren ( self . visit ( node . cond ) ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . statement is None else self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_CaseStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . comp ) ) , <EOL> '<STR_LIT>' : [ self . indent ( self . visit ( case ) ) for case in node . caselist ] , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_CasexStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . comp ) ) , <EOL> '<STR_LIT>' : [ self . indent ( self . visit ( case ) ) for case in node . caselist ] , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Case ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> condlist = [ '<STR_LIT:default>' ] if node . cond is None else [ del_paren ( self . visit ( c ) ) for c in node . cond ] <EOL> cond = [ ] <EOL> for c in condlist : <EOL> cond . append ( c ) <EOL> cond . append ( '<STR_LIT:U+002CU+0020>' ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' . join ( cond [ : - <NUM_LIT:1> ] ) , <EOL> '<STR_LIT>' : self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Block ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' if node . scope is None else escape ( node . scope ) , <EOL> '<STR_LIT>' : [ self . indent ( self . visit ( statement ) ) for statement in node . statements ] , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Initial ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_EventStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . senslist ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_WaitStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : del_paren ( self . visit ( node . cond ) ) , <EOL> '<STR_LIT>' : self . visit ( node . statement ) if node . statement else '<STR_LIT>' , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_ForeverStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_DelayStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . delay ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_InstanceList ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> parameterlist = [ self . indent ( self . visit ( param ) ) for param in node . parameterlist ] <EOL> instances = [ self . visit ( instance ) for instance in node . instances ] <EOL> template_dict = { <EOL> '<STR_LIT>' : escape ( node . module ) , <EOL> '<STR_LIT>' : parameterlist , <EOL> '<STR_LIT>' : len ( parameterlist ) , <EOL> '<STR_LIT>' : instances , <EOL> '<STR_LIT>' : len ( instances ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Instance ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> array = '<STR_LIT>' if node . array is None else self . visit ( node . array ) <EOL> portlist = [ self . indent ( self . visit ( port ) ) for port in node . portlist ] <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT>' : array , <EOL> '<STR_LIT>' : portlist , <EOL> '<STR_LIT>' : len ( portlist ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_ParamArg ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' if node . paramname is None else escape ( node . paramname ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . argname is None else del_paren ( self . visit ( node . argname ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_PortArg ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' if node . portname is None else escape ( node . portname ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . argname is None else del_paren ( self . visit ( node . argname ) ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Function ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> statement = [ self . indent ( self . visit ( s ) ) for s in node . statement ] <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT>' : self . visit ( node . retwidth ) , <EOL> '<STR_LIT>' : statement , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_FunctionCall ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> args = [ self . visit ( arg ) for arg in node . args ] <EOL> template_dict = { <EOL> '<STR_LIT:name>' : self . visit ( node . name ) , <EOL> '<STR_LIT:args>' : args , <EOL> '<STR_LIT>' : len ( args ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Task ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> statement = [ self . indent ( self . visit ( s ) ) for s in node . statement ] <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT>' : statement , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_GenerateStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : [ self . visit ( item ) for item in node . items ] <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_SystemCall ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> args = [ self . visit ( arg ) for arg in node . args ] <EOL> template_dict = { <EOL> '<STR_LIT>' : escape ( node . syscall ) , <EOL> '<STR_LIT:args>' : args , <EOL> '<STR_LIT>' : len ( args ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_IdentifierScopeLabel ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT>' : '<STR_LIT>' if node . loop is None else self . visit ( node . loop ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_IdentifierScope ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> scopes = [ self . visit ( scope ) for scope in node . labellist ] <EOL> template_dict = { <EOL> '<STR_LIT>' : scopes , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Pragma ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . entry ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_PragmaEntry ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . name ) , <EOL> '<STR_LIT:value>' : '<STR_LIT>' if node . value is None else self . visit ( node . value ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_Disable ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT:name>' : escape ( node . dest ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_ParallelBlock ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : '<STR_LIT>' if node . scope is None else escape ( node . scope ) , <EOL> '<STR_LIT>' : [ self . indent ( self . visit ( statement ) ) for statement in node . statements ] , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt <EOL> def visit_SingleStatement ( self , node ) : <EOL> filename = getfilename ( node ) <EOL> template = self . get_template ( filename ) <EOL> template_dict = { <EOL> '<STR_LIT>' : self . visit ( node . statement ) , <EOL> } <EOL> rslt = template . render ( template_dict ) <EOL> return rslt </s>
