PreviousUpNext

15.4.387  src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.pkg

## adl-raw-syntax-form.pkg

# Compiled by:
#     src/lib/compiler/back/low/tools/sml-ast.lib



###                     "If I have seen further than others, it is
###                      by standing upon the shoulders of giants."
###
###                                           -- Isaac Newton 



package   adl_raw_syntax_form
: (weak)  Adl_Raw_Syntax_Form                                                   # Adl_Raw_Syntax_Form   is from   src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.api
{
    Loc  = line_number_database::Location;

    Declaration
      = SUMTYPE_DECL     (List( Sumtype ), List( Type_Alias ))          # One or more possibly mutually recursive sumtypes.  The List(Type_Alias) is for the 'withtype...' clause, if any.
      | EXCEPTION_DECL     List( Exception )
      | FUN_DECL           List( Fun )
      | RTL_DECL          (Pattern, Expression, Loc)
      | RTL_SIG_DECL       (List( Id ), Type)
      | VAL_DECL           List( Named_Value )
      | VALUE_API_DECL   (List( Id ), Type) 
      | TYPE_API_DECL    (Id, List( Typevar_Ref ))
      | LOCAL_DECL         (List( Declaration ), List( Declaration ))
      | SEQ_DECL           List( Declaration )
      | PACKAGE_DECL       (Id, List( Declaration ), Null_Or( Package_Cast ), Package_Exp)
      | GENERIC_DECL       (Id, List( Declaration ), Null_Or( Package_Cast ), Package_Exp)
      | PACKAGE_API_DECL    (Id, Api_Exp)
      | API_DECL          (Id, Api_Exp)
      | SHARING_DECL       List( Share )
      | OPEN_DECL          List( Ident )
      | GENERIC_ARG_DECL    (Id, Package_Cast)
      | INCLUDE_API_DECL  Api_Exp
      | INFIX_DECL         (Int, List( Id ))
      | INFIXR_DECL        (Int, List( Id ))
      | NONFIX_DECL        List( Id )
      | SOURCE_CODE_REGION_FOR_DECLARATION      (Loc, Declaration)
      #
      # Architecture-Description (MD) extensions:
      #
      | ARCHITECTURE_DECL               (Id, List( Declaration ))                       # Architecture spec 
      | VERBATIM_CODE                   List( String )                                  # Verbatim code.
      | BITS_ORDERING_DECL              Range                                           # Declare bits ordering.
      #
      | INSTRUCTION_FORMATS_DECL        (Null_Or(Int), List(Instruction_Format))        # Declare instruction formats.
      | BIG_VS_LITTLE_ENDIAN_DECL       Endian                                          # Little- vs big-endian.
      | REGISTERS_DECL                  List( Register_Set )                            # Register/set declarations.
      #
      | SPECIAL_REGISTERS_DECL          List( Special_Register )                        # Represents stuff like the   "eax = $r[0]"    line in   src/lib/compiler/back/low/intel32/one_word_int.architecture-description
      | ARCHITECTURE_NAME_DECL          String                                          # Name of architecture.
      #
      | ASSEMBLY_CASE_DECL              Assemblycase                                    # Should assembly code be forced to uppercase or lowercase -- or left as-is?
      | BASE_OP_DECL                    List( Constructor )                             # Holds contents of 'base_op...' statement from .adl file. Same format as sumtype constructor list.
      | DEBUG_DECL                      Id                                              # Turn on debugging.
      #
      | RESOURCE_DECL                   List( Id )                                      # Resource declaration.
      | CPU_DECL                        List( Cpu )                                     # Cpu declaration 
      | PIPELINE_DECL                   List( Pipeline )                                # Pipeline declaration.
      | LATENCY_DECL                    List( Latency )                                 # Latency declaration.

    also   Api_Exp  = ID_API  Ident
                  | WHERE_API      (Api_Exp, Ident, Package_Exp)
                  | WHERETYPE_API  (Api_Exp, Ident, Type)
                  | DECLARATIONS_API       List( Declaration )

    also   Share   = TYPE_SHARE     List( Ident )
                  | PACKAGE_SHARE   List( Ident )

    also   Literal = UNT_LIT    Unt
                  | UNT1_LIT  one_word_unt::Unt
                  | INT_LIT     Int
                  | INT1_LIT   one_word_int::Int
                  | INTEGER_LIT  multiword_int::Int
                  | STRING_LIT  String
                  | CHAR_LIT    Char
                  | BOOL_LIT    Bool
                  | FLOAT_LIT    String

    also
    Expression    = LITERAL_IN_EXPRESSION       Literal
                  | ID_IN_EXPRESSION            Ident
                  | CONSTRUCTOR_IN_EXPRESSION   (Ident, Null_Or( Expression ))
                  | LIST_IN_EXPRESSION          (List( Expression ), Null_Or( Expression ))
                  #
                  | TUPLE_IN_EXPRESSION         List( Expression )
                  | VECTOR_IN_EXPRESSION        List( Expression )
                  #
                  | RECORD_IN_EXPRESSION        List ((Id, Expression))
                  | APPLY_EXPRESSION            (Expression, Expression)
                  | IF_EXPRESSION               (Expression, Expression, Expression)
                  | LET_EXPRESSION              (List( Declaration ), List( Expression ))
                  #
                  | SEQUENTIAL_EXPRESSIONS      List( Expression )
                  | RAISE_EXPRESSION            Expression 
                  #
                  | EXCEPT_EXPRESSION           (Expression, List(Clause))
                  | CASE_EXPRESSION             (Expression, List(Clause))
                  | TYPED_EXPRESSION            (Expression, Type)
                  #
                  | FN_IN_EXPRESSION                    List( Clause )                                  # Represents   \\ foo => bar; zot => bap; ... end;
                  | SOURCE_CODE_REGION_FOR_EXPRESSION  (Loc, Expression)

                  # These are architecture-description-language
                  # extensions to the base SML syntax:
                  # 
                  | BITFIELD_IN_EXPRESSION      (Expression, List(Range))                               # Represents   foo at [16..18]
                  | REGISTER_IN_EXPRESSION      (Id, Expression, Null_Or(Id))                           # Represents   '$r[0]'
                  | ASM_IN_EXPRESSION           Assembly                                                # Represents stuff like (the quotes are not metasyntax here!):   ``enter\t<put_operand src1>, <put_operand src2>''
                  | TYPE_IN_EXPRESSION          Type                                                    # Represents   #foo
                  | RTL_IN_EXPRESSION           Rtl                                                     # Appears intended to represent  [[ rtlstuff ]]  -- except lexer is not configured to produce LLBRACKET or RRBRACKET, curiously.
                  #
                  | MATCH_FAIL_EXCEPTION_IN_EXPRESSION  (Expression, Id)                                # Some odd extension -- 'Id' names an exception 'FOO', from surface syntax   <pattern> <guard> exception FOO => <expression>;   
                                                                                                        # This is used (only) in fun rename_rule in   src/lib/compiler/back/low/tools/match-compiler/match-gen-g.pkg
                                                                                                        # whence it passes to    fun rename      in   src/lib/compiler/back/low/tools/match-compiler/match-compiler-g.pkg
                                                                                                        # -- which completely ignores it.
                                                                                                        # The idea might have been to allow user selection of the exception generated on a match failure.

    also Assemblycase = LOWERCASE | UPPERCASE | VERBATIM

    also Package_Exp = IDSEXP           Ident
                  | APPSEXP          (Package_Exp, Package_Exp)
                  | DECLSEXP         List( Declaration )
                  | CONSTRAINEDSEXP  (Package_Exp, Api_Exp)

    also  Type = IDTY       Ident
               | TYVARTY           Typevar_Ref
               | INTVARTY          Int
               | TYPEVAR_TYPE     (Tvkind, Int, Ref( Int ), Ref(  Null_Or( Type ) ))
               | APPTY             (Ident, List( Type ))
               | FUNTY             (Type, Type)
               | TUPLETY           List( Type )
               | RECORDTY          List ((Id, Type))
               | TYPESCHEME_TYPE (List( Type ), Type)
               | LAMBDATY         (List( Type ), Type)
               | REGISTER_TYPE  Id                                                                      # We use this (with Id == "bar") for something declared   foo: $bar   -- the '$' distinguishes register types from regular types.

    also    Tvkind = INTKIND | TYPEKIND

    also    Pattern  = IDPAT  Id
                     | WILDCARD_PATTERN
                     | CONSPAT         (Ident, Null_Or( Pattern ))
                     | ASPAT           (Id, Pattern)
                     | LITPAT          Literal
                     | LISTPAT         (List( Pattern ), Null_Or( Pattern ))
                     | TUPLEPAT        List( Pattern )
                     | VECTOR_PATTERN  List( Pattern )
                     | RECORD_PATTERN  (List ((Id, Pattern)), Bool)
                     | TYPEDPAT        (Pattern, Type)
                     | NOTPAT          Pattern
                     | OR_PATTERN      List( Pattern )
                     | ANDPAT          List( Pattern )
                     | WHEREPAT        (Pattern, Expression) 
                     | NESTEDPAT       (Pattern, Expression, Pattern)

    also    Ident = IDENT  (List( Id ), Id) 

    also    Clause = CLAUSE  (List( Pattern ), Guard, Expression)

    also    Fun = FUN  (Id, List( Clause ))                                             # Represents  "fun id pat1 => exp1;  id pat2 => exp2; ... end;"

    also    Register_Set
                = 
                REGISTER_SET
                  { name:       Id,
                    nickname:   Id,
                    #
                    from:       Ref( Int ),
                    to:         Ref( Int ),
                    #
                    alias:      Null_Or( Id ),
                    count:      Null_Or( Int ),
                    #
                    bits:       Int,
                    print:      Expression,
                    aggregable: Bool,
                    defaults:   List( ((Int,Expression)) )
                  }

    also    Special_Register = SPECIAL_REGISTER (Id, Null_Or( Pattern ), Expression)    # Represents stuff like the   "eax = $r[0]"    line in   src/lib/compiler/back/low/intel32/one_word_int.architecture-description

    also    Endian = LITTLE | BIG

    also    Instruction_Format
                =
                INSTRUCTION_FORMAT
                  (
                    Id,
                    List( Instruction_Bitfield ),
                    Null_Or( Expression )
                  )

    also    Instruction_Bitfield                                                        # Bitfield within a binary instruction format.
                =
                INSTRUCTION_BITFIELD
                  { id:         Id,
                    width:      Width,
                    sign:       Signedness,
                    cnv:        Cnv,
                    value:      Null_Or( one_word_unt::Unt )
                  }

    also          Width = WIDTH  Int | RANGE  (Int, Int)

    also   Cnv = NOCNV
              | CELLCNV  Id
              | FUNCNV  Id

    also   Sumtype = SUMTYPE  
              { name:           Id,
                typevars: List( Typevar_Ref ),
                mc:             Opcode_Encoding,                                # Will be    THE [ 0x20, 0x21, 0x22, 0x23 ]   for input   sumtype fload[0x20..0x23]! = LDF | LDG | LDS | LDT
                asm:            Bool,                                           # Set TRUE iff sumtype name had '!' suffix or any constructor has assembly annotation -- e.g. "addc" or ``addc''.
                field':         Null_Or( Id ),
                cbs:            List( Constructor )                             # "cbs" == "constructor binding s"
              }
         | SUMTYPE_ALIAS
            { name:             Id,
              typevars: List( Typevar_Ref ),
              type:             Type
            }

    also   Exception    = EXCEPTION         (Id, Null_Or(Type))
                        | EXCEPTION_ALIAS   (Id, Ident)

    also    Constructor =   CONSTRUCTOR 
                                  { name:       Id,
                                    #   
                                    type:       Null_Or( Type ),
                                    mc:         Null_Or( Mc ),                          # "mc" == "machine code"
                                    asm:        Null_Or( Assembly ),
                                    rtl:        Null_Or( Expression ),                  # We use "Register Transfer Language" to define instruction semantics.
                                    #   
                                    nop:        Flag,
                                    nullified:  Flag,
                                    #   
                                    delayslot:  Null_Or( Expression ),
                                    delayslot_candidate:        Null_Or( Expression ),
                                    sdi:        Null_Or( Expression ),
                                    #   
                                    latency:    Null_Or( Expression ),   
                                    pipeline:   Null_Or( Expression ),
                                    #
                                    loc:        Loc
                                  }

    also    Flag      = FLAGON | FLAGOFF | FLAGID  (Id, Bool, Expression)

    also    Delayslot = DELAY_ERROR
                      | DELAY_NONE
                      | DELAY_ALWAYS
                      | DELAY_TAKEN
                      | DELAY_NONTAKEN
                      | DELAY_IF  (Branching, Delayslot, Delayslot)

    also    Branching = BRANCHFORWARDS
                      | BRANCHBACKWARDS

    also    Mc        = WORDMC  one_word_unt::Unt                                               # "Mc" == "machine code"
                      | EXPMC  Expression

    also    Assembly  = STRINGASM  String
                      | ASMASM     List( Asm )

    also    Asm       = TEXTASM  String
                      | EXPASM   Expression 

    also    Type_Alias  = TYPE_ALIAS  (Id, List( Typevar_Ref ), Type)                   # Used for 'type ... ' statements, also 'withtype... ' qualifiers to sumtype declarations.

    also    Named_Value   = NAMED_VARIABLE  (Pattern, Expression)

    also    Signedness   = SIGNED | UNSIGNED

    also    Typevar_Ref       = VARTV  Id
                      | INTTV  Id

    also    Rtlterm     = LITRTL  Id
                      | IDRTL   Id
                      | COMPOSITERTL  Id

    also    Cpu         = CPU { name:           Id,                                     # Define a CPU: Number of ALUs, floating point units, max simultaneous instruction issues etc.
                                aliases:        List( String ),
                                max_issues:     Int, 
                                resources:      List( (Int, Id) )
                              }

    also    Pipeline = PIPELINE  (Id, List ((Pattern, Pipeline_Cycles)))

    also    Latency  = LATENCY  (Id, List ((Pattern, Expression)))

    also    Pipeline_Cycles  = PIPELINE_CYCLES  List( Pipeline_Cycle )

    also    Pipeline_Cycle   = OR_CYCLE      (Pipeline_Cycle, Pipeline_Cycle)
                             | REPEAT_CYCLE  (Pipeline_Cycle, Int)
                             | ID_CYCLE  Id 


    withtype Range = (Int, Int)
    also      Id    = String
    also      Guard = Null_Or( Expression )
    also      Opcode_Encoding = Null_Or( List( Int ) )
    also      Rtl     = List( Rtlterm )
    also      Package_Cast = { abstract: Bool, api_expression: Api_Exp };

};  


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext