Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 1 | #!/bin/sh -efu |
| 2 | |
| 3 | mpers_name="$1"; shift |
Dmitry V. Levin | c4afd6d | 2015-12-15 12:58:42 +0000 | [diff] [blame] | 4 | size="$(printf %s "$mpers_name" |tr -cd '[0-9]')" |
| 5 | [ "$size" -gt 0 ] |
| 6 | |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 7 | srcdir=${0%/*} |
| 8 | mpers_sh="${srcdir}/mpers.sh" |
| 9 | |
| 10 | mpers_dir="mpers-$mpers_name" |
| 11 | mkdir -p "$mpers_dir" |
| 12 | |
| 13 | sample="$mpers_dir/sample.c" |
| 14 | cat > "$sample" <<EOF |
| 15 | #include "mpers_type.h" |
Dmitry V. Levin | 5999218 | 2015-12-15 00:26:46 +0000 | [diff] [blame] | 16 | #include DEF_MPERS_TYPE(sample_struct) |
Dmitry V. Levin | c4afd6d | 2015-12-15 12:58:42 +0000 | [diff] [blame] | 17 | typedef struct { |
| 18 | struct { |
| 19 | void *p; |
| 20 | char sc; |
| 21 | /* unsigned char mpers_filler_1[1]; */ |
| 22 | short ss; |
| 23 | unsigned char uc; |
| 24 | /* unsigned char mpers_filler_2[3]; */ |
| 25 | int si; |
| 26 | unsigned ui; |
| 27 | long sl; |
| 28 | unsigned short us; |
| 29 | /* unsigned char mpers_filler_3[6]; */ |
| 30 | long long sll __attribute__((__aligned__(8))); |
| 31 | unsigned long long ull; |
| 32 | unsigned long ul; |
| 33 | long asl[3]; |
| 34 | char f; |
| 35 | /* unsigned char mpers_end_filler_4[7]; */ |
| 36 | } s; |
| 37 | union { |
| 38 | long long sll; |
| 39 | unsigned long long ull; |
| 40 | void *p; |
| 41 | long sl; |
| 42 | unsigned long ul; |
| 43 | int si; |
| 44 | unsigned ui; |
| 45 | short ss; |
| 46 | unsigned short us; |
| 47 | char sc; |
| 48 | unsigned char uc; |
| 49 | } u[3]; |
| 50 | short f[0]; |
| 51 | } sample_struct; |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 52 | #include MPERS_DEFS |
| 53 | EOF |
| 54 | |
| 55 | expected="$mpers_dir/sample.expected" |
| 56 | cat > "$expected" <<EOF |
| 57 | #include <inttypes.h> |
Dmitry V. Levin | c4afd6d | 2015-12-15 12:58:42 +0000 | [diff] [blame] | 58 | typedef uint${size}_t mpers_ptr_t; |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 59 | typedef |
Dmitry V. Levin | 5999218 | 2015-12-15 00:26:46 +0000 | [diff] [blame] | 60 | struct { |
Dmitry V. Levin | c4afd6d | 2015-12-15 12:58:42 +0000 | [diff] [blame] | 61 | struct { |
| 62 | mpers_ptr_t p; |
| 63 | char sc; |
| 64 | unsigned char mpers_filler_1[1]; |
| 65 | int16_t ss; |
| 66 | unsigned char uc; |
| 67 | unsigned char mpers_filler_2[3]; |
| 68 | int32_t si; |
| 69 | uint32_t ui; |
| 70 | int${size}_t sl; |
| 71 | uint16_t us; |
| 72 | unsigned char mpers_filler_3[6]; |
| 73 | int64_t sll; |
| 74 | uint64_t ull; |
| 75 | uint${size}_t ul; |
| 76 | int${size}_t asl[3]; |
| 77 | char f; |
| 78 | unsigned char mpers_end_filler_4[7]; |
| 79 | } ATTRIBUTE_PACKED s; |
| 80 | union { |
| 81 | int64_t sll; |
| 82 | uint64_t ull; |
| 83 | mpers_ptr_t p; |
| 84 | int${size}_t sl; |
| 85 | uint${size}_t ul; |
| 86 | int32_t si; |
| 87 | uint32_t ui; |
| 88 | int16_t ss; |
| 89 | uint16_t us; |
| 90 | char sc; |
| 91 | unsigned char uc; |
| 92 | } u[3]; |
| 93 | int16_t f[0]; |
Dmitry V. Levin | 5999218 | 2015-12-15 00:26:46 +0000 | [diff] [blame] | 94 | } ATTRIBUTE_PACKED ${mpers_name}_sample_struct; |
| 95 | #define MPERS_${mpers_name}_sample_struct ${mpers_name}_sample_struct |
Elvira Khabirova | 0929422 | 2015-08-04 01:47:02 +0300 | [diff] [blame] | 96 | EOF |
| 97 | |
| 98 | CFLAGS="$CPPFLAGS -I${srcdir}" \ |
| 99 | CPPFLAGS="$CPPFLAGS -I${srcdir} -DIN_MPERS -DMPERS_IS_${mpers_name}" \ |
| 100 | "$mpers_sh" "-$mpers_name" "$sample" |
Dmitry V. Levin | 5999218 | 2015-12-15 00:26:46 +0000 | [diff] [blame] | 101 | cmp "$expected" "$mpers_dir"/sample_struct.h > /dev/null |