Back to index

cell-binutils  2.17cvs20070401
test-example.c
Go to the documentation of this file.
00001 /* Copyright (C) 2000, 2003 Free Software Foundation
00002    Contributed by Alexandre Oliva <aoliva@cygnus.com>
00003 
00004    This file is free software; you can redistribute it and/or modify it
00005    under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 2 of the License, or
00007    (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful, but
00010    WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    General Public License for more details.
00013   
00014    You should have received a copy of the GNU General Public License
00015    along with this program; if not, write to the Free Software
00016    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.  */
00017 
00018 /* Generator of tests for insns introduced in AM33 2.0.
00019   
00020    See the following file for usage and documentation.  */
00021 #include "../all/test-gen.c"
00022 
00023 /* Define any char*[]s you may need here.  */
00024 char *named_regs[] = { "a", "b", "c", "d" };
00025 
00026 /* Define helper macros to generate register accesses here.  */
00027 #define namedregs(shift) \
00028   reg_r (named_regs, shift, 0x3, mk_get_bits (2u))
00029 #define numberedregs(shift) \
00030   reg_p ("f", shift, mk_get_bits (2u))
00031 
00032 /* Define helper functions here.  */
00033 int
00034 jmp_cond (func_arg * arg, insn_data * data)
00035 #define jmp_cond(shift) { jmp_cond, { i1: shift } }
00036 {
00037   static const char conds[4][2] = { "z", "n", "g", "l" };
00038   unsigned val = get_bits (2u);
00039 
00040   data->as_in = data->dis_out = strdup (conds[val]);
00041   data->bits = val << arg->i1;
00042 
00043   /* Do not forget to return 0, otherwise the insn will be skipped.  */
00044   return 0;
00045 }
00046 
00047 /* Define convenience wrappers to define_insn.  */
00048 #define cond_jmp_insn(insname, word, funcs...) \
00049   define_insn (insname, \
00050               insn_size_bits (insname, 1, word), \
00051               jmp_cond (4), \
00052               tab, \
00053               ## funcs)
00054 
00055 /* Define insns.  */
00056 cond_jmp_insn (j, 0x40, numberedregs(2), comma, namedregs (0));
00057 
00058 /* Define an insn group.  */
00059 func *jmp_insns[] =
00060   {
00061     insn (j),
00062     0
00063   };
00064 
00065 /* Define the set of all groups.  */
00066 group_t
00067 groups[] =
00068   {
00069     { "jumps", jmp_insns },
00070     { 0 }
00071   };
00072 
00073 int
00074 main (int argc, char *argv[])
00075 {
00076   FILE *as_in = stdout, *dis_out = stderr;
00077 
00078   /* Check whether we're filtering insns.  */
00079   if (argc > 1)
00080     skip_list = argv + 1;
00081 
00082   /* Output assembler header.  */
00083   fputs ("\t.text\n"
00084         "\t.align\n",
00085         as_in);
00086   /* Output comments for the testsuite-driver and the initial
00087      disassembler output.  */
00088   fputs ("#objdump: -dr --prefix-address --show-raw-insn\n"
00089         "#name: Foo Digital Processor\n"
00090         "#as: -mfood\n"
00091         "\n"
00092         "# Test the instructions of FooD\n"
00093         "\n"
00094         ".*: +file format.*food.*\n"
00095         "\n"
00096         "Disassembly of section .text:\n",
00097         dis_out);
00098 
00099   /* Now emit all (selected) insns.  */
00100   output_groups (groups, as_in, dis_out);
00101 
00102   exit (0);
00103 }