Advertisement
Guest User

Untitled

a guest
Apr 10th, 2024
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
OCaml 9.46 KB | None | 0 0
  1. module Absyn = struct
  2.   type expr = {
  3.     kind: expr_kind;
  4.     tags: aug_tag list;
  5.   }
  6.  
  7.   and stmt = {
  8.     kind: stmt_kind;
  9.     tags: aug_tag list;
  10.   }
  11.  
  12.   and expr_kind =
  13.     | Primary of primary_factor
  14.     | Unary of { factor: primary_factor; op: unary_op; }
  15.     | Subscript of { factor: primary_factor; op: subscript_op; }
  16.     | Binary of { left_factor: expr; right_factor: expr; op: binary_op; }
  17.     | Ternary of { cond: expr; if_true: expr; if_false: expr; }
  18.     | Assignment of { lvalue: expr; rvalue: expr; op: assign_op; }
  19.     | StmtExpr of stmt
  20.  
  21.   and stmt_kind =
  22.     | Expr of expr option
  23.     | VarDecl of { attr: var_attr option; storage: storage_cls; tydecl: type_decl; declarators: declarator list option; }
  24.     | For of { init: stmt option; cond: expr list option; iter: stmt option; body: stmt; }
  25.     | DoWhile of { body: stmt; cond: expr; }
  26.     | While of { cond: expr; body: stmt; }
  27.     | If of { if_clause: if_clause; elsif_clauses: if_clause list option; else_clause: stmt option; }
  28.     | Switch of { main_discrim: const_expr; case_clauses: (const_expr * stmt) list; default_clause: stmt option; }
  29.     | InlineAsm of { asm: string; inputs: asm_cons list option; outputs: asm_cons list option; clobbers: string list option; }
  30.     | NestedFunc of { proto: func_proto; name: string; body: stmt; }
  31.     | ControlFlow of control_flow_stmt
  32.     | Compound of compound_stmt
  33.     | Labeled of label * stmt list
  34.  
  35.  
  36.   and literal =
  37.       ConstLiteral of const_lit | CompoundLiteral of compound_lit
  38.  
  39.   and const_lit =
  40.     | IntConst of int * int_suffix option
  41.     | FloatConst of float * float_suffix option
  42.     | CharConst of char * charset_prefix option
  43.     | StrConst of string * charset_prefix option
  44.     | EnumConst of enum_const
  45.  
  46.   and int_suffix =
  47.       Long | LongLong | Unsigned | UnsignedLong | UnsignedLongLong
  48.  
  49.   and float_suffix =
  50.       Double | LongDouble
  51.  
  52.   and charset_prefix =
  53.       Local | U8 | U16 | U32
  54.  
  55.   and compound_lit =
  56.     | ArrayCompound of init_type * init_item list
  57.     | StructCompound of init_type * init_item list
  58.     | UnionCompound of init_type * init_item list
  59.  
  60.   and init_item =
  61.     | RegularInit of expr
  62.     | DesignatedInit of designated_init * expr
  63.  
  64.   and designated_init =
  65.     | ConstExpr of const_expr
  66.     | Ident of string
  67.  
  68.   and init_type = type_decl
  69.  
  70.   and enum_const =
  71.     { name: string; value: const_expr option; }
  72.  
  73.  
  74.   and const_expr =
  75.     | ConstFactor of literal
  76.     | ConstRange of const_expr * const_expr
  77.     | UnaryConstExpr of { factor: literal; op: unary_op; }
  78.     | BinaryConstExpr of { left_factor: literal; right_factor: literal; op: binary_op; }
  79.  
  80.  
  81.   and primary_factor =
  82.       Identifier of string | NestedExpr of expr | Literal of literal
  83.  
  84.  
  85.   and prefix_unary_op =
  86.     | Negate            
  87.     | LogicalNegate    
  88.     | BitwiseNot        
  89.     | AddressOf
  90.     | AddressOfLabel
  91.     | Dereference      
  92.     | PreIncrement      
  93.     | PreDecrement  
  94.     | Sizeof
  95.     | Typeof
  96.  
  97.   and postfix_unary_op =
  98.     | PostIncrement    
  99.     | PostDecrement
  100.  
  101.   and unary_op =
  102.     | PrefixOp of prefix_unary_op
  103.     | PostfixOp of postfix_unary_op
  104.  
  105.   and subscript_op =
  106.     | Index of expr
  107.     | DotMember of expr
  108.     | ArrowMember of expr
  109.     | FunctionCall of expr list
  110.  
  111.   and binary_op =
  112.     | Add              
  113.     | Subtract          
  114.     | Multiply          
  115.     | Divide            
  116.     | Modulo            
  117.     | BitwiseAnd        
  118.     | Bitwise7Or        
  119.     | BitwiseXor        
  120.     | ShiftLeft        
  121.     | ShiftRight        
  122.     | LogicalAnd        
  123.     | LogicalOr        
  124.     | Equal            
  125.     | NotEqual          
  126.     | LessThan          
  127.     | LessThanOrEqual  
  128.     | GreaterThan      
  129.     | GreaterThanOrEqual
  130.  
  131.   and assign_op =
  132.     | Assignment        
  133.     | AddAssign        
  134.     | SubtractAssign    
  135.     | MultiplyAssign    
  136.     | DivideAssign      
  137.     | ModuloAssign      
  138.     | AndAssign        
  139.     | OrAssign          
  140.     | XorAssign        
  141.     | ShiftLeftAssign  
  142.     | ShiftRightAssign
  143.  
  144.  
  145.   and type_decl =
  146.     { attr: type_attr option; qual: type_qual list; value: type_value; }
  147.  
  148.   and type_qual =
  149.       Const | Volatile
  150.  
  151.   and type_value =
  152.     | IntegeralType of type_int
  153.     | AtomicType of type_int
  154.     | RationalType of type_float
  155.     | PointerType of type_pointer
  156.     | ArrayType of type_array
  157.     | EnumType of type_enum
  158.     | StructType of type_struct
  159.     | UnionType of type_union
  160.     | FuncType of type_func
  161.     | ComplexType of type_complex
  162.     | VoidType
  163.  
  164.   and type_int =
  165.     { signage: int_signage option; word: int_word; }
  166.  
  167.   and int_word =
  168.     | Char
  169.     | Short
  170.     | Int
  171.     | Long
  172.     | LongLong
  173.     | UChar
  174.     | UShort
  175.     | UInt
  176.     | ULong
  177.     | ULongLong
  178.  
  179.   and int_signage =
  180.       Signed | Unsgiend
  181.  
  182.   and type_float =
  183.     | Float
  184.     | Double
  185.     | LongDouble
  186.  
  187.   and type_pointer =
  188.     { base: type_decl; depth: int; qual: pointer_qual; }
  189.  
  190.   and pointer_qual =
  191.       Const | Volatile | Restrict
  192.  
  193.   and type_array = {
  194.     arr_type: type_decl;
  195.     arr_size: int option;
  196.   }
  197.  
  198.   and type_struct = {
  199.     struct_tag: string option;
  200.     struct_fields: field_item list;
  201.   }
  202.  
  203.   and type_union = {
  204.     union_name: string option;
  205.     union_fields: field_item list;
  206.   }
  207.  
  208.   and field_item = {
  209.     name: string;
  210.     typ: type_decl;
  211.   }
  212.  
  213.   and type_enum = {
  214.     enum_name: string option;
  215.     enum_values: enum_const list;
  216.   }
  217.  
  218.   and type_complex =
  219.     | ComplexFloat
  220.     | ComplexDouble
  221.     | ComplexLongDouble
  222.  
  223.   and type_func = {
  224.     func_return_type: type_decl;
  225.     func_params: (string option * type_decl) list;
  226.     func_is_variadic: bool;
  227.   }
  228.  
  229.   and storage_cls =
  230.       Extern | Auto | Register | Static
  231.  
  232.   and declarator =
  233.     | Assigned of expr * expr
  234.     | Unassigned of expr
  235.  
  236.   and if_clause =
  237.     { cond: expr; body: stmt; }
  238.  
  239.   and asm_cons =
  240.     { reg: string; value: expr option; }
  241.  
  242.   and control_flow_stmt =
  243.     | Continue
  244.     | Break
  245.     | Goto of label
  246.     | Return of expr option
  247.  
  248.   and label = string
  249.  
  250.   and compound_stmt = stmt list
  251.  
  252.  
  253.   and toplvl_stmt =
  254.     | TypeDef of { tydecl: type_decl; alias: expr; }
  255.     | FuncDef of {  proto: func_proto; name: string; body: stmt; }
  256.     | GlobDecl of toplvl_decl
  257.  
  258.  
  259.   and toplvl_storage =
  260.       Extern | Auto | Static
  261.  
  262.   and func_proto =
  263.     { attr: func_attr option; typ: type_func; storage: toplvl_storage; inline: bool; }
  264.  
  265.   and toplvl_decl =
  266.     | FunDecl of func_proto
  267.     | StructDecl of type_struct
  268.     | UnionDecl of type_union
  269.     | EnumDecl of type_union
  270.  
  271.  
  272.   and trans_unit = toplvl_stmt list
  273.  
  274.  
  275.   and func_attr =
  276.     | Noreturn
  277.     | Format of string * int * int
  278.     | Pure
  279.     | Const
  280.     | Deprecated
  281.     | Used
  282.     | Unused
  283.     | Weak
  284.     | Alias of string
  285.     | Visibility of string
  286.     | No_instrument_function
  287.     | Constructor
  288.     | Destructor
  289.     | Nonnull of int list
  290.     | Malloc
  291.     | Section of string
  292.     | Nothrow
  293.     | Always_inline
  294.     | Noinline
  295.  
  296.  
  297.   and var_attr =
  298.     | Deprecated
  299.     | Unused
  300.     | Weak
  301.     | Aligned of int option
  302.     | Packed
  303.     | Section of string
  304.     | Used
  305.     | Cleanup of string
  306.     | Transparent_union
  307.  
  308.  
  309.   and type_attr =
  310.     | Packed
  311.     | Aligned of int option
  312.     | Deprecated
  313.  
  314.   and aug_tag =
  315.     | TypeTag of type_info
  316.     | CategoryTag of value_category_info
  317.     | ControlFlowTag of control_flow_info
  318.     | DataFlowTag of data_flow_info
  319.     | SSATag of ssa_info
  320.     | RegAllocTag of reg_alloc_info
  321.     | LocationTag of location_info
  322.     | OptimizationInfo of optimization_info
  323.     | DiagnosticTag of diagnostic_info
  324.     | DependencyTag of dependency_info
  325.     | MemoryAccessTag of memory_access_info
  326.     | InterproceduralInfo of interprocedural_info
  327.     | ScopeTag of scope_info
  328.     | LinkageTag of linkage_info
  329.  
  330.   and value_category_info =
  331.     | LocatorVal
  332.     | ReadVal
  333.  
  334.   and type_info = {
  335.     mutable_type: bool;
  336.     type_size: int;
  337.     type_align: int;
  338.   }
  339.  
  340.   and control_flow_info = {
  341.     entering_blocks: string list;
  342.     exiting_blocks: string list;
  343.   }
  344.  
  345.   and data_flow_info = {
  346.     defs: (string * location_info) list;
  347.     uses: (string * location_info) list;
  348.     live_in: string list;
  349.     live_out: string list;
  350.   }
  351.  
  352.   and ssa_info = {
  353.     version: int option;
  354.   }
  355.  
  356.   and reg_alloc_info = {
  357.     assigned_register: string option;
  358.   }
  359.  
  360.   and location_info = {
  361.     file: input_source;
  362.     line_no: int;
  363.     line_token_no: int;
  364.     line_char_no: int;
  365.     total_token_no: int;
  366.     total_char_no: int;
  367.   }
  368.  
  369.   and input_source = STDIN | File of string
  370.  
  371.   and optimization_info = {
  372.     loop_unrolling_factor: int option;
  373.     should_inline: bool;
  374.     vectorization_hint: bool;
  375.   }
  376.  
  377.  
  378.   and diagnostic_info = {
  379.     severity: diagnostic_severity;
  380.     message: string;
  381.     suggestion: string option;
  382.   }
  383.  
  384.   and diagnostic_severity = Error | Warning | Info
  385.  
  386.   and dependency_info = {
  387.     depends_on: string list;
  388.     used_by: string list;
  389.   }
  390.  
  391.  
  392.   and memory_access_info = {
  393.     access_pattern: memory_access_pattern;
  394.     stride: int option;
  395.   }
  396.  
  397.   and memory_access_pattern = Sequential | Random | Strided
  398.  
  399.   and interprocedural_info = {
  400.     call_graph_node: string list;
  401.     has_side_effects: bool;
  402.   }
  403.  
  404.   and scope_info = {
  405.     level: scope_level;
  406.     defined_in: scope_level;
  407.   }
  408.  
  409.   and scope_level =
  410.     | GlobalScope
  411.     | FunctionScope of string
  412.     | BlockScope of string
  413.  
  414.   and linkage_info =
  415.     | External
  416.     | Internal
  417.  
  418.  
  419. end
  420.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement