PreviousUpNext

15.3.161  src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.api

## adl-raw-syntax-form.api
#
# Raw syntax parsetrees for the MDGen machine architecture definition language. 
# It contains a large subset of SML, including SML/NJ extensions.
#
# A parsetree per this definition gets built in
#
#     src/lib/compiler/back/low/tools/parser/architecture-description-language.grammar
#
# and then processed into internal form in
#
#     src/lib/compiler/back/low/tools/arch/architecture-description.pkg
#
# after which it drives the per-source-file code-generation packages
#
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-machcode-xxx-package.pkg
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-registerkinds-xxx-package.pkg
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-translate-machcode-to-asmcode-xxx-g-package.pkg
#     src/lib/compiler/back/low/tools/arch/make-sourcecode-for-translate-machcode-to-execode-xxx-g-package.pkg
#     ...
#
# which generate corresponding backend packages such as
#
#     src/lib/compiler/back/low/intel32/code/machcode-intel32.codemade.api
#     src/lib/compiler/back/low/intel32/code/machcode-intel32-g.codemade.pkg
#     src/lib/compiler/back/low/intel32/code/registerkinds-intel32.codemade.pkg
#     src/lib/compiler/back/low/intel32/emit/translate-machcode-to-asmcode-intel32-g.codemade.pkg
#     src/lib/compiler/back/low/intel32/emit/translate-machcode-to-execode-intel32-g.codemade.pkg.unused
#     ...

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

# This api is implemented in:
#     src/lib/compiler/back/low/tools/adl-syntax/adl-raw-syntax-form.pkg

api Adl_Raw_Syntax_Form {
    #
    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))                                         # Declare 'Id's to be left-associative infix.  Int is syntactic precedence (1-100).
          | INFIXR_DECL         (Int, List(Id))                                         # Declare 'Id's to be left-associative infix.  Int is syntactic precedence (1-100).
          | NONFIX_DECL         List(Id)                                                # Declare 'Id's not to be infix.
          #
          | SOURCE_CODE_REGION_FOR_DECLARATION        (Loc, Declaration)

            # Syntax extensions for architecture descriptions:
            #
          | ARCHITECTURE_DECL           (Id, List( Declaration ))                       # architecture description. 'Id' is architecture name: "INTEL32", "PWRPC32" or "SPARC32".
          | 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.  'Int' is 'instruction-size-in-bits'. For intel32 we have 8, 16 and 32-bit instructions.
          | BIG_VS_LITTLE_ENDIAN_DECL   Endian                                  # Little- vs big- endian.
          | REGISTERS_DECL              List( Register_Set )                            # Register/set declarations.
          #
          | SPECIAL_REGISTERS_DECL      List( Special_Register )                        # Location declarations.
          | ARCHITECTURE_NAME_DECL      String                                          # Name of architecture.
          #
          | ASSEMBLY_CASE_DECL          Assemblycase                                    # Should assembly code be forced to uppercase, forced to 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. Used to declare number of integer and floating point ALUs etc.
          #
          | 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))         # Second arg has no surface syntax presence; it is always initially NULL, but gets used internally later.
                  #
                  | TUPLE_IN_EXPRESSION         List( Expression )
                  | VECTOR_IN_EXPRESSION        List( Expression )
                  #
                  | RECORD_IN_EXPRESSION        List( (Id, Expression) )                        # List of (fieldname, value) pairs.
                  | 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)                              # foo: Bar
                  | 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. -- 2011-04-23 CrT

    also    Assemblycase = LOWERCASE | UPPERCASE | VERBATIM                                     # Should assembly code be in uppercase, lowercase, or left as-is?

    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)
                  | RECORDTY          List( (Id, Type) )
                  | TUPLETY           List( 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
                  = WILDCARD_PATTERN
                  | CONSPAT         (Ident, Null_Or( Pattern ))
                  | IDPAT           Id
                  | 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)                                             # The 'List(Id)' (typically []) holds package lookup path;  The 'Id' is the actual value/type/... name.

    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                                                          # Define one binary execode instruction format for architecture.
                =                                                                       # This gets used (only) in   src/lib/compiler/back/low/tools/arch/make-sourcecode-for-translate-machcode-to-execode-xxx-g-package.pkg
                INSTRUCTION_FORMAT
                  ( Id,
                    List( Instruction_Bitfield ),
                    Null_Or(Expression)
                  )

    also   Instruction_Bitfield
                =
                INSTRUCTION_BITFIELD
                  { id:         Id,
                    width:      Width,
                    sign:       Signedness,
                    cnv:        Cnv,                                                    # The only use of '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                                                                     # Handles   sumtype Foo = BAR | ZOT
              { 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 ),                                          # Will be    THE (ID "Bar")   for input   sumtype foo: Bar = ...
                cbs:            List( Constructor )                                     # "cbs" == "constructor binding s"
              }

         | SUMTYPE_ALIAS                                                                # Handles   sumtype Foo = Bar
              { name:           Id,
                typevars: List( Typevar_Ref ),
                type:           Type
              }

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

    also    Constructor =   CONSTRUCTOR 
                                  { name:                       Id,                     # Name of constructor.
                                    type:                       Null_Or( Type ),        # Type of constructor.
                                    #   
                                    mc:                         Null_Or( Mc ),          # Define binary   representation if constructor defines a machine instruction. ("mc" == "machine code".)
                                    asm:                        Null_Or( Assembly ),    # Define assembly representation if constructor defines a machine instruction.
                                    rtl:                        Null_Or( Expression ),  # Define semantics               if constructor defines a machine instruction. ("rtl" == "Register Transfer Language".)
                                    #   
                                    nop:                        Flag,
                                    nullified:                  Flag,
                                    #   
                                    delayslot:                  Null_Or( Expression ),
                                    delayslot_candidate:        Null_Or( Expression ),
                                    sdi:                        Null_Or( Expression ),  # "sdi" == "span dependent instruction" -- one whose binary encoding length varies. E.g., a relative branch whose length depends on target address.
                                    #   
                                    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                                                # The parser will currently never generate this.
                        | BRANCHBACKWARDS                                               # The parser will currently never generate this.

    also    Mc          = WORDMC  one_word_unt::Unt                                             # Here 'mc' is 'machine code', i.e. binary machine language.
                        | 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)))                      # Used (only) three times, in    src/lib/compiler/back/low/sparc32/sparc32.architecture-description

    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