#NEWLINE# def serializeCallee( self , caller , callee , arguments , serializer , dataContainer , program ) : #NEWLINE# #INDENT# if self . invalid : #NEWLINE# #INDENT# raise CompilationException ( True , '{0} Attempting to generate code for an invalid action' , self . hliraction ) #NEWLINE# #UNINDENT# assert isinstance ( serializer , ProgramSerializer ) #NEWLINE# assert isinstance ( program , ebpfProgram . EbpfProgram ) #NEWLINE# assert isinstance ( callee , p4_action ) #NEWLINE# assert isinstance ( arguments , list ) #NEWLINE# if ( callee . name in EbpfAction . unsupported ) : #NEWLINE# #INDENT# raise NotSupportedException ( '{0}' , callee ) #NEWLINE# #UNINDENT# serializer . emitIndent ( ) #NEWLINE# args = self . transformArguments ( arguments , caller , dataContainer , program ) #NEWLINE# if ( callee . name == 'modify_field' ) : #NEWLINE# #INDENT# dst = args [ 0 ] #NEWLINE# src = args [ 1 ] #NEWLINE# size = self . checkSize ( callee , [ a . widthInBits ( ) for a in args ] , program ) #NEWLINE# if ( size is None ) : #NEWLINE# #INDENT# raise CompilationException ( True , 'Cannot infer width for arguments {0}' , callee ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( size <= 32 ) : #NEWLINE# #INDENT# serializer . appendFormat ( '{0} = {1};' , dst . asString , src . asString ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not dst . isLvalue ) : #NEWLINE# #INDENT# raise NotSupportedException ( 'Constants wider than 32-bit: {0}({1})' , dst . caller , dst . asString ) #NEWLINE# #UNINDENT# if ( not src . isLvalue ) : #NEWLINE# #INDENT# raise NotSupportedException ( 'Constants wider than 32-bit: {0}({1})' , src . caller , src . asString ) #NEWLINE# #UNINDENT# serializer . appendFormat ( 'memcpy(&{0}, &{1}, {2});' , dst . asString , src . asString , ( size / 8 ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( callee . name == 'add' ) or ( callee . name == 'bit_and' ) or ( callee . name == 'bit_or' ) or ( callee . name == 'bit_xor' ) or ( callee . name == 'subtract' ) ) : #NEWLINE# #INDENT# size = self . checkSize ( callee , [ a . widthInBits ( ) for a in args ] , program ) #NEWLINE# if ( size is None ) : #NEWLINE# #INDENT# raise CompilationException ( True , 'Cannot infer width for arguments {0}' , callee ) #NEWLINE# #UNINDENT# if ( size > 32 ) : #NEWLINE# #INDENT# raise NotSupportedException ( '{0}: Arithmetic on {1}-bits' , callee , size ) #NEWLINE# #UNINDENT# op = EbpfAction . translateActionToOperator ( callee . name ) #NEWLINE# serializer . appendFormat ( '{0} = {1} {2} {3};' , args [ 0 ] . asString , args [ 1 ] . asString , op , dataContainer [ 2 ] . asString ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( callee . name == 'add_to_field' ) or ( callee . name == 'subtract_from_field' ) ) : #NEWLINE# #INDENT# size = self . checkSize ( callee , [ a . widthInBits ( ) for a in args ] , program ) #NEWLINE# if ( size is None ) : #NEWLINE# #INDENT# raise CompilationException ( True , 'Cannot infer width for arguments {0}' , callee ) #NEWLINE# #UNINDENT# if ( size > 32 ) : #NEWLINE# #INDENT# raise NotSupportedException ( '{0}: Arithmetic on {1}-bits' , callee , size ) #NEWLINE# #UNINDENT# op = EbpfAction . translateActionToOperator ( callee . name ) #NEWLINE# serializer . appendFormat ( '{0} = {0} {1} {2};' , args [ 0 ] . asString , op , args [ 1 ] . asString ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( callee . name == 'no_op' ) : #NEWLINE# #INDENT# serializer . append ( '/* noop */' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( callee . name == 'drop' ) : #NEWLINE# #INDENT# serializer . appendFormat ( '{0} = 1;' , program . dropBit ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( callee . name == 'push' ) or ( callee . name == 'pop' ) ) : #NEWLINE# #INDENT# raise CompilationException ( True , '{0} push/pop not yet implemented' , callee ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise CompilationException ( True , 'Unexpected primitive action {0}' , callee ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# serializer . newline ( )