blob: 5b535a95d95be45a38e751d319de6aee2e00f832 [file] [log] [blame]
Elvira Khabirova09294222015-08-04 01:47:02 +03001#!/bin/sh -efu
2
3mpers_name="$1"; shift
Dmitry V. Levinc4afd6d2015-12-15 12:58:42 +00004size="$(printf %s "$mpers_name" |tr -cd '[0-9]')"
5[ "$size" -gt 0 ]
6
Elvira Khabirova09294222015-08-04 01:47:02 +03007srcdir=${0%/*}
8mpers_sh="${srcdir}/mpers.sh"
9
10mpers_dir="mpers-$mpers_name"
11mkdir -p "$mpers_dir"
12
13sample="$mpers_dir/sample.c"
14cat > "$sample" <<EOF
15#include "mpers_type.h"
Dmitry V. Levin59992182015-12-15 00:26:46 +000016#include DEF_MPERS_TYPE(sample_struct)
Dmitry V. Levinc4afd6d2015-12-15 12:58:42 +000017typedef 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 Khabirova09294222015-08-04 01:47:02 +030052#include MPERS_DEFS
53EOF
54
55expected="$mpers_dir/sample.expected"
56cat > "$expected" <<EOF
57#include <inttypes.h>
Dmitry V. Levinc4afd6d2015-12-15 12:58:42 +000058typedef uint${size}_t mpers_ptr_t;
Elvira Khabirova09294222015-08-04 01:47:02 +030059typedef
Dmitry V. Levin59992182015-12-15 00:26:46 +000060struct {
Dmitry V. Levinc4afd6d2015-12-15 12:58:42 +000061struct {
62mpers_ptr_t p;
63char sc;
64unsigned char mpers_filler_1[1];
65int16_t ss;
66unsigned char uc;
67unsigned char mpers_filler_2[3];
68int32_t si;
69uint32_t ui;
70int${size}_t sl;
71uint16_t us;
72unsigned char mpers_filler_3[6];
73int64_t sll;
74uint64_t ull;
75uint${size}_t ul;
76int${size}_t asl[3];
77char f;
78unsigned char mpers_end_filler_4[7];
79} ATTRIBUTE_PACKED s;
80union {
81int64_t sll;
82uint64_t ull;
83mpers_ptr_t p;
84int${size}_t sl;
85uint${size}_t ul;
86int32_t si;
87uint32_t ui;
88int16_t ss;
89uint16_t us;
90char sc;
91unsigned char uc;
92} u[3];
93int16_t f[0];
Dmitry V. Levin59992182015-12-15 00:26:46 +000094} ATTRIBUTE_PACKED ${mpers_name}_sample_struct;
95#define MPERS_${mpers_name}_sample_struct ${mpers_name}_sample_struct
Elvira Khabirova09294222015-08-04 01:47:02 +030096EOF
97
98CFLAGS="$CPPFLAGS -I${srcdir}" \
99CPPFLAGS="$CPPFLAGS -I${srcdir} -DIN_MPERS -DMPERS_IS_${mpers_name}" \
100"$mpers_sh" "-$mpers_name" "$sample"
Dmitry V. Levin59992182015-12-15 00:26:46 +0000101cmp "$expected" "$mpers_dir"/sample_struct.h > /dev/null