+
    jI$                     <    R t ^ RIt ! R R]4      t ! R R4      tR# )aX  
riscv_extension_analyzer

This module provides functionality for analyzing and parsing RISC-V extension
strings.

Key Features:
- Validate RISC-V extension strings to ensure they conform to the expected
  format.
- Parse extension strings to extract base ISA information and supported
  extensions.

Author: Heinrich Schuchardt
Version: 0.0.1
Nc                   6   a a ] tR t^t oRtV 3R ltRtVtV ;t# )RiscvProfileExceptiona  
Exception raised for errors related to RISC-V extensions.

This exception is a subclass of RuntimeError and is used to indicate
issues specifically related to the RISC-V instruction set architecture
extensions.

Attributes:
    message (str): A description of the error.
c                &   < \         SV `  V4       R # )N)super__init__)selfmessage	__class__s   &&:/usr/lib/python3/dist-packages/DistUpgrade/RiscvProfile.pyr   RiscvProfileException.__init__!   s    !     )	__name__
__module____qualname____firstlineno____doc__r   __static_attributes____classdictcell____classcell__)r	   __classdict__s   @@r
   r   r      s     	" "r   r   c                   d   a  ] tR t^%t o RtR tR tR tR tR t	R t
]R 4       tR	 tR
 tRtV tR# )RiscvProfilez`
RiscvProfile

This class provides functionality to analyze and parse RISC-V extension
strings.
c                H   . RNRNRNRNRNRNRNRNR	NR
NRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NR#NR$NR%NR&NR'NR(NR)NR*NR+NR,NR-NR.NR/NR0NR1NR2NR3NR4NR5NR6NR7NR8NR9NR:NR;NR<NR=NR>NR?NR@NRANRBNRCNRDNRENRFNRGNpV P                  V4       V# )Hz
Gets the extensions published by the Linux kernel

Returns: List of extensions

Raises:
    RiscvExtException: If the provided ISA string is invalid.
imafdqcvzicbomzicbozziccrsezicntrzicondzicsrzifencei	zihintntlzihintpausezihpmzimopzabhazacaszawrszfazfhzfhminzcazcbzcdzcfzcmopzbazbbzbczbkbzbkczbkxzbszkzknzkndzknezknhzkrzkszktzksedzkshztsozvbbzvbczve32fzve32xzve64dzve64fzve64xzvfhzvfhminzvkbzvkgzvknzvknczvknedzvkngzvknhazvknhbzvkszvksczvksedzvkshzvksgzvktadd_implied_extensions)r   
linux_6_14s   & r
   linux_supportedRiscvProfile.linux_supported-   s   




 #
%(
*-
/2
4<
>F


!)
+2
4>
 
 '
 )0
 29
 ;B
 DK
 	
 	
 "	
 $,	
 .3	
 5:	
 <A	
 CH	

 

 

 "

 $)

 +1

 39

 ;A

 CH
 
 
  
 "(
 *0
 27
 9>
 @E
 
 
 $
 &,
 .4
 6>
 @H
 
 
 !)
 +1
 3<
 >D
 FL
 
 
 &
 (/
 19
 ;C
 EK
 
 
  '
 )0
 28

 	##J/r   c                    . RNRNRNRNRNRNRNRNR	NR
NRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNRNR NR!NR"NpV P                  V4       V# )#z
Gets the mandatory extensions for the RVA23U64 profile

Returns: List of extensions

Raises:
    RiscvExtException: If the provided ISA string is invalid.
r   r   r   r   r   r    br!   zic64br"   zicbopr#   ziccamoaziccifzicclsmr$   r%   r&   r'   r)   r*   r+   r,   za64rsr/   r0   r2   r4   r7   rJ   rR   r`   rF   supmra   )r   rva23s   & r
   rva23_requiredRiscvProfile.rva23_requiredG   sW   




 #
%(
*-
/2
4<
>F


 *
,4
6?
AJ
 
 
 !(
 *5
 7D
 FM
 	
 	
  '	
 ).	
 08	
 :?	
 AH	

 

 

  &

 (-

 /5
 	##E*r   c                    V P                  4       pV P                  4       pV Uu. uF  q3V9   g   K  VNK  	  up# u upi )z
Gets the required RVA23 extensions published by the Linux kernel

Returns: List of extensions

Raises:
    RiscvExtException: If the provided ISA string is invalid.
)rd   rp   )r   linuxcheckexts   &   r
   rva23_to_checkRiscvProfile.rva23_to_check\   s>     $$&##%$5uuu555s   ;;c                    R^R^@R^ /pRpVP                  4        F.  w  rEVP                  V4      '       g   K  TpV\        V4      R p M	  Vf   \        R4      hVX3# )ad  
Checks the base instruction set architecture (ISA) provided by a
RISC-V extension string.

Args:
    isa_string (str): The RISC-V extension string to analyze.

Returns:
    bitness (int): Bitness of base ISA.
    remainder (str): Remaining ISA string.

Raises:
    RiscvProfileException:
    If the string does not start with a valid base ISA identifier.
rv128rv64rv32NzInvalid base ISA)items
startswithlenr   )r   
isa_string	base_isasbitnesskeyvalue	remainders   &&     r
   check_base_isaRiscvProfile.check_base_isak   s{    $ SBB	
 #//+JC$$S))&s3xy1		 , ?'(:;;	!!r   c                   RR.RR.RR.RR.RR.R	R.R
R./pR. ROR. ROR. ROR. ROR. R OR. R!ORRR.RRR.R. R"ORRR.RRR./pRpV'       dR   RpV FG  pWS9   g   K  W5,           F  pWa9  g   K  VP                  V4       K  	  VP                  V4       Rp KU  	  KY  RpV'       dI   RpV F>  pWR9   d+   W%,           F  pWa9  g   K  VP                  V4       RpK   	  V'       g   K=   KL  	  KP  R# )#zG
Adds implied extensions

Args:
    extensions: iterable of extensions
r   zmmulr   zaamor   r'   r   r   r!   r1   r2   rg   gr?   r@   rE   rU   rV   rK   rX   rT   r[   r\   r_   TFN)r8   r9   r>   )r   r   r   r   r   r'   r(   )r@   rD   rF   )r;   r<   r=   rB   rA   rC   )r;   r<   r=   rG   rH   )rW   rZ   rS   r`   )r]   r^   rS   r`   )appendremove)r   
extensionsimplies	shorthandupdate	extensionimplieds   &&     r
   rb   #RiscvProfile.add_implied_extensions   sI    '''###H:
 &?'C<8ff%ff%7ff%ff%
	 F'	)#,#7#7"4&--g6 $8 %%i0!F ( F'	'#*#5#5"4&--g6%)F $6 6 ( r   c                   Rp. p\        V4      ^ 8  EdC   VP                  R4      '       d   VR,          pV'       g   \        R4      hMV'       d   \        R4      hV^ ,          R9   d   RpV'       d   \        P                  ! RV4      pM\        P                  ! R	V4      pV'       g   \        R
4      hVP                  4       pWP                  4       R pVR9  dR   \        P                  ! RV4      pV'       g   \        P                  ! RV4      pV'       d   VRVP                  4        pV'       g   \        R4      hVP                  V4       EKS  V P                  V4       V# )z
Parse RISC-V ISA string

args:
    isa_string: ISA string without base ISA (e.g. rv64)

Raises:
    RiscvExtException: If the provided ISA string is invalid.
F_:   NNzMissing extensionzExpecting underscoresxzTz^[^_]+z^\D\d+p\d+|\D\d+|\DzExpecting extensionNz\d+p\d+$z\d+$zZero length extension>   sv32sv39sv48sv59)r~   r}   r   rematchgroupendsearchstartr   rb   )r   r   multi_characterr   r   r   s   &&    r
   parse_isa_stringRiscvProfile.parse_isa_string   s(     
*o!$$S))'^
!/0CDD " +,BCC!}%"&J7!7D+,ABBI#IIKL1J @@		+y9IIgy9E ).5;;= 9I+,CDDi(##J/r   c                     \        RR4      ;_uu_ 4       p V P                  4       pRRR4       XP	                  RRR7      P                  4       pT F?  p\        P                  ! RT4      pT'       g   K$  \        YEP                  4       R 4      u # 	  \        R	4      h  + '       g   i     L; i  \         d   p\        R4      ThRp?ii ; i)
z
Gets the extensions listed in /proc/cpuinfo as common for all harts

Returns: List of extensions

Raises:
    RiscvExtException: If the ISA string is invalid or cannot be found
z/proc/cpuinforbNzCan't read /proc/cpuinfozutf-8ignore)errorsz
isa\s*:\s*zNo ISA information)
openreadOSErrorr   decode
splitlinesr   r   r   r   )filebinary_contentexlinesliner   s         r
   read_cpuinfoRiscvProfile.read_cpuinfo   s    	Mot,,!% -
 %%gh%?JJLDHH]D1Eu#D$677 
 $$899 -, 	M'(CD"L	Ms3   B3 B B3  B0	+B3 0B3 3C>C

Cc                t    V P                  4       pV F!  pW P                  9  g   K  \        RV 24      h	  R# )ze
Check if the system is RVA23 ready

Raises:
    RiscvExtException: If the system is not RVA23 ready
zMissing extension N)rv   r   r   )r   expectedru   s   &  r
   assert_rva23_readyRiscvProfile.assert_rva23_ready  s9     &&(C//)+.@,FGG r   c                    VP                  4       pV P                  V4      w  V n        pV P                  V4      V n        R# )z
Initializes a RiscvProfile object with a given RISC-V ISA
string.

Args:
    isa_string (str): The RISC-V ISA string to analyze.

Raises:
    RiscvExtException: If the provided ISA string is invalid.
N)lowerr   r   r   r   )r   r   r   s   && r
   r   RiscvProfile.__init__  s;      %%'
"&"5"5j"Ai//	:r   )r   r   N)r   r   r   r   r   rd   rp   rv   r   rb   r   staticmethodr   r   r   r   r   )r   s   @r
   r   r   %   sO     4*6 "D8t/b : :0H; ;r   r   )r   r   RuntimeErrorr   r   r   r   r
   <module>r      s'     
"L " G; G;r   