OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [binutils-2.18.50/] [gas/] [itbl-parse.y] - Diff between revs 156 and 816

Only display areas with differences | Details | Blame | View Log

Rev 156 Rev 816
/* itbl-parse.y
/* itbl-parse.y
   Copyright 1997, 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
   Copyright 1997, 2002, 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
   This file is part of GAS, the GNU Assembler.
   This file is part of GAS, the GNU Assembler.
   GAS is free software; you can redistribute it and/or modify
   GAS is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   the Free Software Foundation; either version 3, or (at your option)
   any later version.
   any later version.
   GAS is distributed in the hope that it will be useful,
   GAS is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   GNU General Public License for more details.
   You should have received a copy of the GNU General Public License
   You should have received a copy of the GNU General Public License
   along with GAS; see the file COPYING.  If not, write to the Free
   along with GAS; see the file COPYING.  If not, write to the Free
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
   02110-1301, USA.  */
   02110-1301, USA.  */
%{
%{
/*
/*
Yacc grammar for instruction table entries.
Yacc grammar for instruction table entries.
=======================================================================
=======================================================================
Original Instruction table specification document:
Original Instruction table specification document:
            MIPS Coprocessor Table Specification
            MIPS Coprocessor Table Specification
            ====================================
            ====================================
This document describes the format of the MIPS coprocessor table.  The
This document describes the format of the MIPS coprocessor table.  The
table specifies a list of valid functions, data registers and control
table specifies a list of valid functions, data registers and control
registers that can be used in coprocessor instructions.  This list,
registers that can be used in coprocessor instructions.  This list,
together with the coprocessor instruction classes listed below,
together with the coprocessor instruction classes listed below,
specifies the complete list of coprocessor instructions that will
specifies the complete list of coprocessor instructions that will
be recognized and assembled by the GNU assembler.  In effect,
be recognized and assembled by the GNU assembler.  In effect,
this makes the GNU assembler table-driven, where the table is
this makes the GNU assembler table-driven, where the table is
specified by the programmer.
specified by the programmer.
The table is an ordinary text file that the GNU assembler reads when
The table is an ordinary text file that the GNU assembler reads when
it starts.  Using the information in the table, the assembler
it starts.  Using the information in the table, the assembler
generates an internal list of valid coprocessor registers and
generates an internal list of valid coprocessor registers and
functions.  The assembler uses this internal list in addition to the
functions.  The assembler uses this internal list in addition to the
standard MIPS registers and instructions which are built-in to the
standard MIPS registers and instructions which are built-in to the
assembler during code generation.
assembler during code generation.
To specify the coprocessor table when invoking the GNU assembler, use
To specify the coprocessor table when invoking the GNU assembler, use
the command line option "--itbl file", where file is the
the command line option "--itbl file", where file is the
complete name of the table, including path and extension.
complete name of the table, including path and extension.
Examples:
Examples:
            gas -t cop.tbl test.s -o test.o
            gas -t cop.tbl test.s -o test.o
            gas -t /usr/local/lib/cop.tbl test.s -o test.o
            gas -t /usr/local/lib/cop.tbl test.s -o test.o
            gas --itbl d:\gnu\data\cop.tbl test.s -o test.o
            gas --itbl d:\gnu\data\cop.tbl test.s -o test.o
Only one table may be supplied during a single invocation of
Only one table may be supplied during a single invocation of
the assembler.
the assembler.
Instruction classes
Instruction classes
===================
===================
Below is a list of the valid coprocessor instruction classes for
Below is a list of the valid coprocessor instruction classes for
any given coprocessor "z".  These instructions are already recognized
any given coprocessor "z".  These instructions are already recognized
by the assembler, and are listed here only for reference.
by the assembler, and are listed here only for reference.
Class   format                        instructions
Class   format                        instructions
-------------------------------------------------
-------------------------------------------------
Class1:
Class1:
        op base rt offset
        op base rt offset
                                                            LWCz rt,offset (base)
                                                            LWCz rt,offset (base)
                                                            SWCz rt,offset (base)
                                                            SWCz rt,offset (base)
Class2:
Class2:
        COPz sub rt rd 0
        COPz sub rt rd 0
                                                            MTCz rt,rd
                                                            MTCz rt,rd
                                                            MFCz rt,rd
                                                            MFCz rt,rd
                                                            CTCz rt,rd
                                                            CTCz rt,rd
                                                            CFCz rt,rd
                                                            CFCz rt,rd
Class3:
Class3:
        COPz CO cofun
        COPz CO cofun
                                                            COPz cofun
                                                            COPz cofun
Class4:
Class4:
        COPz BC br offset
        COPz BC br offset
                                                            BCzT offset
                                                            BCzT offset
                                                            BCzF offset
                                                            BCzF offset
Class5:
Class5:
        COPz sub rt rd 0
        COPz sub rt rd 0
                                                            DMFCz rt,rd
                                                            DMFCz rt,rd
                                                            DMTCz rt,rd
                                                            DMTCz rt,rd
Class6:
Class6:
        op base rt offset
        op base rt offset
                                                            LDCz rt,offset (base)
                                                            LDCz rt,offset (base)
                                                            SDCz rt,offset (base)
                                                            SDCz rt,offset (base)
Class7:
Class7:
        COPz BC br offset
        COPz BC br offset
                                                            BCzTL offset
                                                            BCzTL offset
                                                            BCzFL offset
                                                            BCzFL offset
The coprocessor table defines coprocessor-specific registers that can
The coprocessor table defines coprocessor-specific registers that can
be used with all of the above classes of instructions, where
be used with all of the above classes of instructions, where
appropriate.  It also defines additional coprocessor-specific
appropriate.  It also defines additional coprocessor-specific
functions for Class3 (COPz cofun) instructions, Thus, the table allows
functions for Class3 (COPz cofun) instructions, Thus, the table allows
the programmer to use convenient mnemonics and operands for these
the programmer to use convenient mnemonics and operands for these
functions, instead of the COPz mmenmonic and cofun operand.
functions, instead of the COPz mmenmonic and cofun operand.
The names of the MIPS general registers and their aliases are defined
The names of the MIPS general registers and their aliases are defined
by the assembler and will be recognized as valid register names by the
by the assembler and will be recognized as valid register names by the
assembler when used (where allowed) in coprocessor instructions.
assembler when used (where allowed) in coprocessor instructions.
However, the names and values of all coprocessor data and control
However, the names and values of all coprocessor data and control
register mnemonics must be specified in the coprocessor table.
register mnemonics must be specified in the coprocessor table.
Table Grammar
Table Grammar
=============
=============
Here is the grammar for the coprocessor table:
Here is the grammar for the coprocessor table:
            table -> entry*
            table -> entry*
            entry -> [z entrydef] [comment] '\n'
            entry -> [z entrydef] [comment] '\n'
            entrydef -> type name val
            entrydef -> type name val
            entrydef -> 'insn' name val funcdef ; type of entry (instruction)
            entrydef -> 'insn' name val funcdef ; type of entry (instruction)
            z -> 'p'['0'..'3']               ; processor number
            z -> 'p'['0'..'3']               ; processor number
            type -> ['dreg' | 'creg' | 'greg' ]      ; type of entry (register)
            type -> ['dreg' | 'creg' | 'greg' ]      ; type of entry (register)
        ; 'dreg', 'creg' or 'greg' specifies a data, control, or general
        ; 'dreg', 'creg' or 'greg' specifies a data, control, or general
        ;           register mnemonic, respectively
        ;           register mnemonic, respectively
            name -> [ltr|dec]*               ; mnemonic of register/function
            name -> [ltr|dec]*               ; mnemonic of register/function
            val -> [dec|hex]                 ; register/function number (integer constant)
            val -> [dec|hex]                 ; register/function number (integer constant)
            funcdef -> frange flags fields
            funcdef -> frange flags fields
                                ; bitfield range for opcode
                                ; bitfield range for opcode
                                ; list of fields' formats
                                ; list of fields' formats
            fields -> field*
            fields -> field*
            field -> [','] ftype frange flags
            field -> [','] ftype frange flags
            flags -> ['*' flagexpr]
            flags -> ['*' flagexpr]
            flagexpr -> '[' flagexpr ']'
            flagexpr -> '[' flagexpr ']'
            flagexpr -> val '|' flagexpr
            flagexpr -> val '|' flagexpr
            ftype -> [ type | 'immed' | 'addr' ]
            ftype -> [ type | 'immed' | 'addr' ]
        ; 'immed' specifies an immediate value; see grammar for "val" above
        ; 'immed' specifies an immediate value; see grammar for "val" above
                ; 'addr' specifies a C identifier; name of symbol to be resolved at
                ; 'addr' specifies a C identifier; name of symbol to be resolved at
        ;           link time
        ;           link time
            frange -> ':' val '-' val   ; starting to ending bit positions, where
            frange -> ':' val '-' val   ; starting to ending bit positions, where
                                ; where 0 is least significant bit
                                ; where 0 is least significant bit
            frange -> (null)            ; default range of 31-0 will be assumed
            frange -> (null)            ; default range of 31-0 will be assumed
            comment -> [';'|'#'] [char]*
            comment -> [';'|'#'] [char]*
            char -> any printable character
            char -> any printable character
            ltr -> ['a'..'z'|'A'..'Z']
            ltr -> ['a'..'z'|'A'..'Z']
            dec -> ['0'..'9']*                                       ; value in decimal
            dec -> ['0'..'9']*                                       ; value in decimal
            hex -> '0x'['0'..'9' | 'a'..'f' | 'A'..'F']*        ; value in hexadecimal
            hex -> '0x'['0'..'9' | 'a'..'f' | 'A'..'F']*        ; value in hexadecimal
Examples
Examples
========
========
Example 1:
Example 1:
The table:
The table:
            p1 dreg d1 1             ; data register "d1" for COP1 has value 1
            p1 dreg d1 1             ; data register "d1" for COP1 has value 1
            p1 creg c3 3             ; ctrl register "c3" for COP1 has value 3
            p1 creg c3 3             ; ctrl register "c3" for COP1 has value 3
            p3 func fill 0x1f:24-20           ; function "fill" for COP3 has value 31 and
            p3 func fill 0x1f:24-20           ; function "fill" for COP3 has value 31 and
                        ; no fields
                        ; no fields
will allow the assembler to accept the following coprocessor instructions:
will allow the assembler to accept the following coprocessor instructions:
            LWC1 d1,0x100 ($2)
            LWC1 d1,0x100 ($2)
            fill
            fill
Here, the general purpose register "$2", and instruction "LWC1", are standard
Here, the general purpose register "$2", and instruction "LWC1", are standard
mnemonics built-in to the MIPS assembler.
mnemonics built-in to the MIPS assembler.
Example 2:
Example 2:
The table:
The table:
            p3 dreg d3 3             ; data register "d3" for COP3 has value 3
            p3 dreg d3 3             ; data register "d3" for COP3 has value 3
            p3 creg c2 22            ; control register "c2" for COP3 has value 22
            p3 creg c2 22            ; control register "c2" for COP3 has value 22
            p3 func fee 0x1f:24-20 dreg:17-13 creg:12-8 immed:7-0
            p3 func fee 0x1f:24-20 dreg:17-13 creg:12-8 immed:7-0
                ; function "fee" for COP3 has value 31, and 3 fields
                ; function "fee" for COP3 has value 31, and 3 fields
                ; consisting of a data register, a control register,
                ; consisting of a data register, a control register,
                ; and an immediate value.
                ; and an immediate value.
will allow the assembler to accept the following coprocessor instruction:
will allow the assembler to accept the following coprocessor instruction:
            fee d3,c2,0x1
            fee d3,c2,0x1
and will emit the object code:
and will emit the object code:
            31-26  25 24-20 19-18  17-13 12-8  7-0
            31-26  25 24-20 19-18  17-13 12-8  7-0
            COPz   CO fun                     dreg  creg  immed
            COPz   CO fun                     dreg  creg  immed
            010011 1  11111 00       00011 10110 00000001
            010011 1  11111 00       00011 10110 00000001
            0x4ff07601
            0x4ff07601
Example 3:
Example 3:
The table:
The table:
            p3 dreg d3 3             ; data register "d3" for COP3 has value 3
            p3 dreg d3 3             ; data register "d3" for COP3 has value 3
            p3 creg c2 22            ; control register "c2" for COP3 has value 22
            p3 creg c2 22            ; control register "c2" for COP3 has value 22
            p3 func fuu 0x01f00001 dreg:17-13 creg:12-8
            p3 func fuu 0x01f00001 dreg:17-13 creg:12-8
will allow the assembler to accept the following coprocessor
will allow the assembler to accept the following coprocessor
instruction:
instruction:
            fuu d3,c2
            fuu d3,c2
and will emit the object code:
and will emit the object code:
            31-26  25 24-20 19-18  17-13 12-8  7-0
            31-26  25 24-20 19-18  17-13 12-8  7-0
            COPz   CO fun                     dreg  creg
            COPz   CO fun                     dreg  creg
            010011 1  11111 00       00011 10110 00000001
            010011 1  11111 00       00011 10110 00000001
            0x4ff07601
            0x4ff07601
In this way, the programmer can force arbitrary bits of an instruction
In this way, the programmer can force arbitrary bits of an instruction
to have predefined values.
to have predefined values.
=======================================================================
=======================================================================
Additional notes:
Additional notes:
Encoding of ranges:
Encoding of ranges:
To handle more than one bit position range within an instruction,
To handle more than one bit position range within an instruction,
use 0s to mask out the ranges which don't apply.
use 0s to mask out the ranges which don't apply.
May decide to modify the syntax to allow commas separate multiple
May decide to modify the syntax to allow commas separate multiple
ranges within an instruction (range','range).
ranges within an instruction (range','range).
Changes in grammar:
Changes in grammar:
        The number of parms argument to the function entry
        The number of parms argument to the function entry
was deleted from the original format such that we now count the fields.
was deleted from the original format such that we now count the fields.
----
----
FIXME! should really change lexical analyzer
FIXME! should really change lexical analyzer
to recognize 'dreg' etc. in context sensitive way.
to recognize 'dreg' etc. in context sensitive way.
Currently function names or mnemonics may be incorrectly parsed as keywords
Currently function names or mnemonics may be incorrectly parsed as keywords
FIXME! hex is ambiguous with any digit
FIXME! hex is ambiguous with any digit
*/
*/
#include "as.h"
#include "as.h"
#include "itbl-lex.h"
#include "itbl-lex.h"
#include "itbl-ops.h"
#include "itbl-ops.h"
/* #define DEBUG */
/* #define DEBUG */
#ifdef DEBUG
#ifdef DEBUG
#ifndef DBG_LVL
#ifndef DBG_LVL
#define DBG_LVL 1
#define DBG_LVL 1
#endif
#endif
#else
#else
#define DBG_LVL 0
#define DBG_LVL 0
#endif
#endif
#if DBG_LVL >= 1
#if DBG_LVL >= 1
#define DBG(x) printf x
#define DBG(x) printf x
#else
#else
#define DBG(x)
#define DBG(x)
#endif
#endif
#if DBG_LVL >= 2
#if DBG_LVL >= 2
#define DBGL2(x) printf x
#define DBGL2(x) printf x
#else
#else
#define DBGL2(x)
#define DBGL2(x)
#endif
#endif
static int sbit, ebit;
static int sbit, ebit;
static struct itbl_entry *insn=0;
static struct itbl_entry *insn=0;
static int yyerror (const char *);
static int yyerror (const char *);
%}
%}
%union
%union
  {
  {
    char *str;
    char *str;
    int num;
    int num;
    int processor;
    int processor;
    unsigned long val;
    unsigned long val;
  }
  }
%token      DREG CREG GREG IMMED ADDR INSN NUM ID NL PNUM
%token      DREG CREG GREG IMMED ADDR INSN NUM ID NL PNUM
%type        value flags flagexpr
%type        value flags flagexpr
%type        number NUM ftype regtype pnum PNUM
%type        number NUM ftype regtype pnum PNUM
%type        ID name
%type        ID name
%start insntbl
%start insntbl
%%
%%
insntbl:
insntbl:
        entrys
        entrys
        ;
        ;
entrys:
entrys:
        entry entrys
        entry entrys
        |
        |
        ;
        ;
entry:
entry:
        pnum regtype name value NL
        pnum regtype name value NL
          {
          {
            DBG (("line %d: entry pnum=%d type=%d name=%s value=x%x\n",
            DBG (("line %d: entry pnum=%d type=%d name=%s value=x%x\n",
                    insntbl_line, $1, $2, $3, $4));
                    insntbl_line, $1, $2, $3, $4));
            itbl_add_reg ($1, $2, $3, $4);
            itbl_add_reg ($1, $2, $3, $4);
          }
          }
        | pnum INSN name value range flags
        | pnum INSN name value range flags
          {
          {
            DBG (("line %d: entry pnum=%d type=INSN name=%s value=x%x",
            DBG (("line %d: entry pnum=%d type=INSN name=%s value=x%x",
                    insntbl_line, $1, $3, $4));
                    insntbl_line, $1, $3, $4));
            DBG ((" sbit=%d ebit=%d flags=0x%x\n", sbit, ebit, $6));
            DBG ((" sbit=%d ebit=%d flags=0x%x\n", sbit, ebit, $6));
            insn=itbl_add_insn ($1, $3, $4, sbit, ebit, $6);
            insn=itbl_add_insn ($1, $3, $4, sbit, ebit, $6);
          }
          }
        fieldspecs NL
        fieldspecs NL
          {}
          {}
        | NL
        | NL
        | error NL
        | error NL
        ;
        ;
fieldspecs:
fieldspecs:
        ',' fieldspec fieldspecs
        ',' fieldspec fieldspecs
        | fieldspec fieldspecs
        | fieldspec fieldspecs
        |
        |
        ;
        ;
ftype:
ftype:
        regtype
        regtype
          {
          {
            DBGL2 (("ftype\n"));
            DBGL2 (("ftype\n"));
            $$ = $1;
            $$ = $1;
          }
          }
        | ADDR
        | ADDR
          {
          {
            DBGL2 (("addr\n"));
            DBGL2 (("addr\n"));
            $$ = ADDR;
            $$ = ADDR;
          }
          }
        | IMMED
        | IMMED
          {
          {
            DBGL2 (("immed\n"));
            DBGL2 (("immed\n"));
            $$ = IMMED;
            $$ = IMMED;
          }
          }
        ;
        ;
fieldspec:
fieldspec:
        ftype range flags
        ftype range flags
          {
          {
            DBG (("line %d: field type=%d sbit=%d ebit=%d, flags=0x%x\n",
            DBG (("line %d: field type=%d sbit=%d ebit=%d, flags=0x%x\n",
                    insntbl_line, $1, sbit, ebit, $3));
                    insntbl_line, $1, sbit, ebit, $3));
            itbl_add_operand (insn, $1, sbit, ebit, $3);
            itbl_add_operand (insn, $1, sbit, ebit, $3);
          }
          }
        ;
        ;
flagexpr:
flagexpr:
        NUM '|' flagexpr
        NUM '|' flagexpr
          {
          {
            $$ = $1 | $3;
            $$ = $1 | $3;
          }
          }
        | '[' flagexpr ']'
        | '[' flagexpr ']'
          {
          {
            $$ = $2;
            $$ = $2;
          }
          }
        | NUM
        | NUM
          {
          {
            $$ = $1;
            $$ = $1;
          }
          }
        ;
        ;
flags:
flags:
        '*' flagexpr
        '*' flagexpr
          {
          {
            DBGL2 (("flags=%d\n", $2));
            DBGL2 (("flags=%d\n", $2));
            $$ = $2;
            $$ = $2;
          }
          }
        |
        |
          {
          {
            $$ = 0;
            $$ = 0;
          }
          }
        ;
        ;
range:
range:
        ':' NUM '-' NUM
        ':' NUM '-' NUM
          {
          {
            DBGL2 (("range %d %d\n", $2, $4));
            DBGL2 (("range %d %d\n", $2, $4));
            sbit = $2;
            sbit = $2;
            ebit = $4;
            ebit = $4;
          }
          }
        |
        |
          {
          {
            sbit = 31;
            sbit = 31;
            ebit = 0;
            ebit = 0;
          }
          }
        ;
        ;
pnum:
pnum:
        PNUM
        PNUM
          {
          {
            DBGL2 (("pnum=%d\n",$1));
            DBGL2 (("pnum=%d\n",$1));
            $$ = $1;
            $$ = $1;
          }
          }
        ;
        ;
regtype:
regtype:
             DREG
             DREG
          {
          {
            DBGL2 (("dreg\n"));
            DBGL2 (("dreg\n"));
            $$ = DREG;
            $$ = DREG;
          }
          }
        | CREG
        | CREG
          {
          {
            DBGL2 (("creg\n"));
            DBGL2 (("creg\n"));
            $$ = CREG;
            $$ = CREG;
          }
          }
        | GREG
        | GREG
          {
          {
            DBGL2 (("greg\n"));
            DBGL2 (("greg\n"));
            $$ = GREG;
            $$ = GREG;
          }
          }
        ;
        ;
name:
name:
        ID
        ID
          {
          {
            DBGL2 (("name=%s\n",$1));
            DBGL2 (("name=%s\n",$1));
            $$ = $1;
            $$ = $1;
          }
          }
        ;
        ;
number:
number:
        NUM
        NUM
          {
          {
            DBGL2 (("num=%d\n",$1));
            DBGL2 (("num=%d\n",$1));
            $$ = $1;
            $$ = $1;
          }
          }
        ;
        ;
value:
value:
        NUM
        NUM
          {
          {
            DBGL2 (("val=x%x\n",$1));
            DBGL2 (("val=x%x\n",$1));
            $$ = $1;
            $$ = $1;
          }
          }
        ;
        ;
%%
%%
static int
static int
yyerror (msg)
yyerror (msg)
     const char *msg;
     const char *msg;
{
{
  printf ("line %d: %s\n", insntbl_line, msg);
  printf ("line %d: %s\n", insntbl_line, msg);
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.