Changeset 5af6cf3d in mainline for tools/autogen2.sh


Ignore:
Timestamp:
2018-03-05T15:55:34Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Children:
db3c8834
Parents:
d5e5fd1
Message:

todo

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/autogen2.sh

    rd5e5fd1 r5af6cf3d  
    11#!/bin/sh
    22
    3 filename="$1"
    4 struct_name="$2"
     3# There's a bunch of restriction. The script assumes that the structure definition begins with "typedef struct struct_name {",
     4# ends with "struct_name_t;", and that every word in between that ends with ";" is a struct member name with optional
     5# array subscript. Error handling is mostly omitted for simplicity, so any input that does not follow these rules will result
     6# in cryptic errors.
    57
    6 members=`cat $filename | sed -n -e "1,/typedef struct $struct_name {/d" -e "/} ${struct_name}_t;/,$$d" -e "s/.* \([^ ]\+\);/\1/p"`
     8echo $PWD
    79
    8 ustruct_name=`echo "$struct_name" | awk '{print toupper($0)}'`
    9 dmembers=`echo "$members" | awk '{print "DEFINE_MEMBER(" $0 ", " toupper($0) ")" }'`
     10input="$1"
     11output="$2"
     12toolsdir="$(readlink -f $(dirname "$0"))"
     13awkscript="$toolsdir/autogen2.awk"
    1014
     15# Set default value for $CC.
    1116if [ -z "${CC}" ]; then
    1217        CC=cc
    1318fi
    1419
     20# If $CC is clang, we need to make sure integrated assembler is not used.
    1521if ( ${CC} --version | grep clang > /dev/null ) ; then
    1622        CFLAGS="${CFLAGS} -no-integrated-as"
    1723fi
    1824
    19 echo "/* Autogenerated file, do not modify. */"
    20 echo "#pragma once"
     25# Tell the compiler to generate makefile dependencies.
     26CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d"
    2127
    22 ( ${CC} ${CFLAGS} -w -S -x c - -o - | sed -n 's/^.* #define \([^ ]\+\) [^0-9]*\([0-9]\+\) .*/#define \1 \2/p' ) <<- EOF
     28# Generate defines
     29defs=`$awkscript -- $input || exit 1`
    2330
    24 #include "$filename"
     31# Generate C file.
     32cat > $output.c <<- EOF
    2533
    26 #define DEFINE_MEMBER(lc, uc) \
    27         asm volatile ("/* #define ${ustruct_name}_OFFSET_"#uc" %0 */" :: "i" (__builtin_offsetof(struct $struct_name, lc))); \
    28         asm volatile ("/* #define ${ustruct_name}_SIZE_"#uc" %0 */" :: "i" (sizeof((struct $struct_name){}.lc)));
     34#include "`basename $input`"
     35
     36#define DEFINE_MEMBER(ls, us, lm, um) \
     37        asm volatile ("/* #define "#us"_OFFSET_"#um" %0 */" :: "i" (__builtin_offsetof(struct ls, lm))); \
     38        asm volatile ("/* #define "#us"_SIZE_"#um" %0 */" :: "i" (sizeof((struct ls){}.lm)));
     39
     40#define DEFINE_STRUCT(ls, us) \\
     41        asm volatile ("/* #define "#us"_SIZE %0 */" :: "i" (sizeof(struct ls)));
    2942
    3043void autogen()
    3144{
    32         $dmembers
     45        $defs
    3346}
    3447
    3548EOF
     49
     50# Turn the C file into assembly.
     51${CC} ${CFLAGS} -w -S -o $output.s $output.c || exit 1
     52
     53# Process the output.
     54
     55echo "/* Autogenerated file, do not modify. */" > $output
     56echo "#pragma once" >> $output
     57sed -n 's/^.* #define \([^ ]\+\) [^0-9]*\([0-9]\+\) .*/#define \1 \2/p' < $output.s > $output || exit 1
Note: See TracChangeset for help on using the changeset viewer.