os/ossrv/genericopenlibs/liboil/src/build_trampolines.c
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2  * LIBOIL - Library of Optimized Inner Loops
     3  * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
     4  * All rights reserved.
     5  *
     6  * Redistribution and use in source and binary forms, with or without
     7  * modification, are permitted provided that the following conditions
     8  * are met:
     9  * 1. Redistributions of source code must retain the above copyright
    10  *    notice, this list of conditions and the following disclaimer.
    11  * 2. Redistributions in binary form must reproduce the above copyright
    12  *    notice, this list of conditions and the following disclaimer in the
    13  *    documentation and/or other materials provided with the distribution.
    14  * 
    15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
    16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
    17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
    19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
    21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
    23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
    24  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    25  * POSSIBILITY OF SUCH DAMAGE.
    26  */
    27 
    28 
    29 #include <stdio.h>
    30 #include <liboil/liboil.h>
    31 #include <ctype.h>
    32 #include <stdlib.h>
    33 #include <string.h>
    34 
    35 #include <liboil/liboilprototype.h>
    36 
    37 static char * xstrdup (const char *s);
    38 
    39 void print_header (void);
    40 void print_footer (void);
    41 
    42 int main (int argc, char *argv[])
    43 {
    44   OilFunctionClass *klass;
    45   OilPrototype *proto;
    46   int i;
    47   int n;
    48   char *string;
    49   char *arg_string;
    50 
    51   oil_init_no_optimize ();
    52 
    53   print_header ();
    54 
    55   n = oil_class_get_n_classes ();
    56   for (i=0;i<n; i++ ){
    57     klass = oil_class_get_by_index (i);
    58 
    59     if(klass->prototype) {
    60       proto = oil_prototype_from_string (klass->prototype);
    61       if (proto) {
    62         string = oil_prototype_to_string (proto);
    63         if (strlen (string) == 0) {
    64           free (string);
    65           string = xstrdup("void");
    66         }
    67         arg_string = oil_prototype_to_arg_string (proto);
    68 
    69         printf ("#undef oil_%s\n", klass->name);
    70         printf ("void\n");
    71         printf ("oil_%s (%s)\n", klass->name, string);
    72         printf ("{\n");
    73         printf ("  if (_oil_function_class_%s.func == NULL) {\n", klass->name);
    74         printf ("    oil_class_optimize (&_oil_function_class_%s);\n", klass->name);
    75         printf ("  }\n");
    76         printf ("  ((void (*)(%s))(_oil_function_class_%s.func))(%s);\n",
    77             string, klass->name, arg_string);
    78         printf ("}\n");
    79         printf ("\n");
    80 
    81         oil_prototype_free (proto);
    82         free (string);
    83         free (arg_string);
    84       } else {
    85         printf("/* ERROR: could not parse %s(%s) */\n", klass->name, klass->prototype);
    86       }
    87     }
    88   }
    89 
    90   print_footer ();
    91 
    92   return 0;
    93 }
    94 
    95 void print_header (void)
    96 {
    97   printf ("/*\n");
    98   printf (" * LIBOIL - Library of Optimized Inner Loops\n");
    99   printf (" * Copyright (c) 2004 David A. Schleef <ds@schleef.org>\n");
   100   printf (" * All rights reserved.\n");
   101   printf (" *\n");
   102   printf (" * Redistribution and use in source and binary forms, with or without\n");
   103   printf (" * modification, are permitted provided that the following conditions\n");
   104   printf (" * are met:\n");
   105   printf (" * 1. Redistributions of source code must retain the above copyright\n");
   106   printf (" *    notice, this list of conditions and the following disclaimer.\n");
   107   printf (" * 2. Redistributions in binary form must reproduce the above copyright\n");
   108   printf (" *    notice, this list of conditions and the following disclaimer in the\n");
   109   printf (" *    documentation and/or other materials provided with the distribution.\n");
   110   printf (" * \n");
   111   printf (" * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR\n");
   112   printf (" * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\n");
   113   printf (" * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n");
   114   printf (" * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,\n");
   115   printf (" * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\n");
   116   printf (" * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\n");
   117   printf (" * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\n");
   118   printf (" * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\n");
   119   printf (" * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\n");
   120   printf (" * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n");
   121   printf (" * POSSIBILITY OF SUCH DAMAGE.\n");
   122   printf (" */\n");
   123   printf ("\n");
   124   printf ("/* This file is automatically generated.  Do not edit. */\n");
   125   printf ("\n");
   126   printf ("#include <liboil/liboil.h>\n");
   127   printf ("#include <liboil/liboilclasses.h>\n");
   128   printf ("#include <liboil/liboilfunction.h>\n");
   129   printf ("\n");
   130 }
   131 
   132 void print_footer (void)
   133 {
   134   printf ("\n");
   135 }
   136 
   137 static char *
   138 xstrdup (const char *s)
   139 {
   140   int n = strlen(s);
   141   char *t;
   142 
   143   n = strlen(s);
   144   t = malloc(n + 1);
   145   memcpy (t, s, n);
   146   t[n] = 0;
   147 
   148   return t;
   149 }
   150