a
    Lg                  	   @   s   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ eee dddZdeeeeeeddddZedddZdS )zZ
QAPI Generator

This is the main entry point for generating C code from the QAPI schema.
    N)Optional   )gen_commands)
must_match)	QAPIError)
gen_events)gen_introspect)
QAPISchema)	gen_types)	gen_visit)prefixreturnc                 C   s*   t d| }| t| kr&| |  S d S )Nz([A-Za-z_.-][A-Za-z0-9_.-]*)?)r   endlen)r   match r   </home2/Puru_Virtio_Blk/virtio-demo/qemu/scripts/qapi/main.pyinvalid_prefix_char   s    
r   F)schema_file
output_dirr   unmaskbuiltinsgen_tracingr   c                 C   s`   t |du sJ t| }t|||| t|||| t|||| t||| t|||| dS )a  
    Generate C code for the given schema into the target directory.

    :param schema_file: The primary QAPI schema file.
    :param output_dir: The output directory to store generated code.
    :param prefix: Optional C-code prefix for symbol names.
    :param unmask: Expose non-ABI names through introspection?
    :param builtins: Generate code for built-in types?

    :raise QAPIError: On failures.
    N)r   r	   r
   r   r   r   r   )r   r   r   r   r   r   schemar   r   r   generate   s    r   )r   c               
   C   s  t jdd} | jddddd | jdd	d
ddd | jddd
ddd | jdddddd | jdddd | jdd
d |  }t|j}|rd| d}ttjd  d| tj	d dS z&t
|j|j|j|j|j|j d  W n6 ty } zt|tj	d W Y d!}~dS d!}~0 0 dS )"z
    gapi-gen executable entry point.
    Expects arguments via sys.argv, see --help for details.

    :return: int, 0 on success, 1 on failure.
    z Generate code from a QAPI schema)Zdescriptionz-bz
--builtinsZ
store_truez generate code for built-in types)actionhelpz-oz--output-dirZstore z$write output to directory OUTPUT_DIR)r   defaultr   z-pz--prefixzprefix for symbolsz-uz--unmask-non-abi-namesr   z%expose non-ABI names in introspection)r   Zdestr   z--suppress-tracingz,suppress adding trace events to qmp marshalsr   )r   zfunny character 'z' in argument of --prefixr   z: )filer   )r   r   r   r   r   N)argparseZArgumentParserZadd_argumentZ
parse_argsr   r   printsysargvstderrr   r   r   r   r   Zsuppress_tracingr   )ZparserargsZ
funny_charmsgerrr   r   r   main:   sP    





r(   )FFF)__doc__r    r"   typingr   Zcommandsr   commonr   errorr   Zeventsr   Z
introspectr   r   r	   typesr
   Zvisitr   strr   boolr   intr(   r   r   r   r   <module>   s.   
   