@@ -27,7 +27,7 @@ use move_binary_format::{
2727 AccessKind as FFAccessKind , AddressSpecifier as FFAddressSpecifier , FunctionAttribute ,
2828 FunctionDefinitionIndex , FunctionHandleIndex , MemberCount ,
2929 ResourceSpecifier as FFResourceSpecifier , SignatureToken , StructDefinitionIndex ,
30- StructHandleIndex , TableIndex , VariantIndex , Visibility ,
30+ StructFieldInformation , StructHandleIndex , TableIndex , VariantIndex , Visibility ,
3131 } ,
3232 internals:: ModuleIndex ,
3333 views:: {
@@ -479,6 +479,64 @@ impl<'a> BinaryModuleLoader<'a> {
479479 . make ( well_known:: MODULE_LOCK_ATTRIBUTE ) ;
480480 attributes. push ( Attribute :: Apply ( node_id, sym, vec ! [ ] ) ) ;
481481 } ,
482+ FunctionAttribute :: Pack ( struct_definition_index) => {
483+ let node_id = self . env . new_node ( Loc :: default ( ) , Type :: Tuple ( vec ! [ ] ) ) ;
484+ let struct_def = handle_view. module ( ) . struct_def_at ( * struct_definition_index) ;
485+ let struct_handle = handle_view
486+ . module ( )
487+ . struct_handle_at ( struct_def. struct_handle ) ;
488+ let struct_name = handle_view. module ( ) . identifier_at ( struct_handle. name ) ;
489+ let module_handle = handle_view. module ( ) . module_handle_at ( struct_handle. module ) ;
490+ let module_id = handle_view. module ( ) . module_id_for_handle ( module_handle) ;
491+ let module_name = module_id. name ( ) . as_str ( ) ;
492+ let addr = module_id. address ;
493+ let sym = self . env . symbol_pool ( ) . make ( & format ! (
494+ "pack{}{}{}{}{}{}" ,
495+ well_known:: PUBLIC_STRUCT_DELIMITER ,
496+ addr,
497+ well_known:: PUBLIC_STRUCT_DELIMITER ,
498+ module_name,
499+ well_known:: PUBLIC_STRUCT_DELIMITER ,
500+ struct_name. as_str( )
501+ ) ) ;
502+ attributes. push ( Attribute :: Apply ( node_id, sym, vec ! [ ] ) ) ;
503+ } ,
504+ FunctionAttribute :: PackVariant ( struct_definition_index, variant_index) => {
505+ let node_id = self . env . new_node ( Loc :: default ( ) , Type :: Tuple ( vec ! [ ] ) ) ;
506+ let struct_def = handle_view. module ( ) . struct_def_at ( * struct_definition_index) ;
507+ if let StructFieldInformation :: DeclaredVariants ( variants) =
508+ & struct_def. field_information
509+ {
510+ if let Some ( variant) = variants. get ( * variant_index as usize ) {
511+ let struct_handle = handle_view
512+ . module ( )
513+ . struct_handle_at ( struct_def. struct_handle ) ;
514+ let struct_name =
515+ handle_view. module ( ) . identifier_at ( struct_handle. name ) ;
516+ let module_handle =
517+ handle_view. module ( ) . module_handle_at ( struct_handle. module ) ;
518+ let module_id =
519+ handle_view. module ( ) . module_id_for_handle ( module_handle) ;
520+ let module_name = module_id. name ( ) . as_str ( ) ;
521+ let addr = module_id. address ;
522+ let variant_name = variant. name ;
523+ let variant_name_str =
524+ handle_view. module ( ) . identifier_at ( variant_name) . as_str ( ) ;
525+ let sym = self . env . symbol_pool ( ) . make ( & format ! (
526+ "pack{}{}{}{}{}{}{}{}" ,
527+ well_known:: PUBLIC_STRUCT_DELIMITER ,
528+ addr,
529+ well_known:: PUBLIC_STRUCT_DELIMITER ,
530+ module_name,
531+ well_known:: PUBLIC_STRUCT_DELIMITER ,
532+ struct_name. as_str( ) ,
533+ well_known:: PUBLIC_STRUCT_DELIMITER ,
534+ variant_name_str
535+ ) ) ;
536+ attributes. push ( Attribute :: Apply ( node_id, sym, vec ! [ ] ) ) ;
537+ }
538+ }
539+ } ,
482540 }
483541 }
484542
0 commit comments