Changeset 5af6cf3d in mainline for tools/autogen2.sh
- Timestamp:
- 2018-03-05T15:55:34Z (6 years ago)
- Children:
- db3c8834
- Parents:
- d5e5fd1
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/autogen2.sh
rd5e5fd1 r5af6cf3d 1 1 #!/bin/sh 2 2 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. 5 7 6 members=`cat $filename | sed -n -e "1,/typedef struct $struct_name {/d" -e "/} ${struct_name}_t;/,$$d" -e "s/.* \([^ ]\+\);/\1/p"` 8 echo $PWD 7 9 8 ustruct_name=`echo "$struct_name" | awk '{print toupper($0)}'` 9 dmembers=`echo "$members" | awk '{print "DEFINE_MEMBER(" $0 ", " toupper($0) ")" }'` 10 input="$1" 11 output="$2" 12 toolsdir="$(readlink -f $(dirname "$0"))" 13 awkscript="$toolsdir/autogen2.awk" 10 14 15 # Set default value for $CC. 11 16 if [ -z "${CC}" ]; then 12 17 CC=cc 13 18 fi 14 19 20 # If $CC is clang, we need to make sure integrated assembler is not used. 15 21 if ( ${CC} --version | grep clang > /dev/null ) ; then 16 22 CFLAGS="${CFLAGS} -no-integrated-as" 17 23 fi 18 24 19 echo "/* Autogenerated file, do not modify. */" 20 echo "#pragma once"25 # Tell the compiler to generate makefile dependencies. 26 CFLAGS="${CFLAGS} -MD -MP -MT $output -MF $output.d" 21 27 22 ( ${CC} ${CFLAGS} -w -S -x c - -o - | sed -n 's/^.* #define \([^ ]\+\) [^0-9]*\([0-9]\+\) .*/#define \1 \2/p' ) <<- EOF 28 # Generate defines 29 defs=`$awkscript -- $input || exit 1` 23 30 24 #include "$filename" 31 # Generate C file. 32 cat > $output.c <<- EOF 25 33 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))); 29 42 30 43 void autogen() 31 44 { 32 $d members45 $defs 33 46 } 34 47 35 48 EOF 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 55 echo "/* Autogenerated file, do not modify. */" > $output 56 echo "#pragma once" >> $output 57 sed -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.