o
    i                     @  s   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	m
Z
mZ G dd deZG dd	 d	eZG d
d deZe	eeeef  ZeG dd dZeZeeeeef ZG dd deZeG dd dZG dd deZeeef ZeG dd dZdS )z#Representation of assembly programs    )annotations)	dataclass)Enumauto)ListOptionalUnionc                      "   e Zd ZdZd fddZ  ZS )	ImmediatezImmediate operands like $3returnstrc                   s   dt    S )N$super__str__self	__class__ e/home/gtoal/gtoal.com/languages/algol60/new-unicode-parser/lang/c/tests4/test_framework/parser/asm.pyr      s   zImmediate.__str__r   r   __name__
__module____qualname____doc__r   __classcell__r   r   r   r   r
          r
   c                   @  s   e Zd Ze Ze Ze Ze Ze Ze Z	e Z
e Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Z e Z!e Z"e Z#e Z$dddZ%dS )Registerr   r   c                 C  s   d| j  S )N%)namer   r   r   r   r   5   s   zRegister.__str__Nr   )&r   r   r   r   AXBXCXDXDISIR8R9R10R11R12R13R14R15BPSPIPXMM0XMM1XMM2XMM3XMM4XMM5XMM6XMM7XMM8XMM9XMM10XMM11XMM12XMM13XMM14XMM15r   r   r   r   r   r      sF    r   c                   @  s,   e Zd ZdZe Ze Ze ZdddZdS )Operatorz+,-, and @ operators, which can appear in memory displacement expressions like:
    -4(%rbp)
    foo+10(%rbp)
    bar@GOTPCREL(%rip)
    r   r   c                 C  s2   | t jkrdS | t jkrdS | t jkrdS td)N+-@zwhat operator is this???)rC   PLUSMINUSATNotImplementedErrorr   r   r   r   r   D   s   


zOperator.__str__Nr   )	r   r   r   r   r   rG   rH   rI   r   r   r   r   r   rC   9   s    rC   c                   @  sL   e Zd ZU dZdZded< dZded< dZded< dZd	ed
< dddZ	dS )Memoryz8Memory operands (including RIP-relative, stack, indexed)NzOptional[Expr]dispzOptional[Register]baseidx   intscaler   r   c                 C  sj   d tt| jpg }| js| jdkr| d| jpd dS | d| jp%d d| jp+d d| jp1d dS )N rO   (), )joinmapr   rL   rN   rQ   rM   )r   disp_strr   r   r   r   ]   s   .zMemory.__str__r   )
r   r   r   r   rL   __annotations__rM   rN   rQ   r   r   r   r   r   rK   T   s   
 rK   c                   @  s   e Zd ZdZe Ze Ze Ze Ze Z	e Z
e Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Ze Z e Z!e Z"e Z#dddZ$dS )OpcodezAll instructions we recognize

    Simplified, e.g. we don't distinguish between different conditional jumps
    consider further simplification, like using the same opcode for all unary computations
    (not, shr, neg, etc)r   r   c                 C  s
   | j  S )N)r!   lowerr   r   r   r   r      s   
zOpcode.__str__Nr   )%r   r   r   r   r   MOVPUSHPOPLEAMOVSMOVZ	CVTTSD2SICVTSI2SDADDSUBIDIVDIVIMULANDORXORSHRNOTNEGCDQCDQEJMPJMPCCSETCCCMPCMOVTESTCALLRETLEAVEUNKNOWNr   r   r   r   r   rZ   m   sD    rZ   c                   @  ,   e Zd ZU dZded< ded< ddd	Zd
S )InstructionzDAn assembly instruction consists of an opcode and a list of operandsrZ   opcodezlist[Operand]operandsr   r   c                 C  s$   d tt| j}d| j d| S )NrU   	 )rV   rW   r   r~   r}   )r   str_operandsr   r   r   r      s   zInstruction.__str__Nr   r   r   r   r   rY   r   r   r   r   r   r|      
   
 r|   c                      r	   )Labelz#A label within an assembly functionr   r   c                   s   t   d S )N:r   r   r   r   r   r      s   zLabel.__str__r   r   r   r   r   r   r      r   r   c                   @  r{   )AssemblyFunctionzVAn assembly function consists of a name and a list of instructions and internal labelsr   r!   zlist[AsmItem]instructionsr   r   c                 C  s   | j  ddtt| j S )N
)r!   rV   rW   r   r   r   r   r   r   r      s   zAssemblyFunction.__str__Nr   r   r   r   r   r   r      r   r   N)r   
__future__r   dataclassesr   enumr   r   typingr   r   r   rP   r
   r   rC   r   ExprrK   TargetOperandrZ   r|   r   AsmItemr   r   r   r   r   <module>   s(    '0