From 3902cb2fcae6e2028252b5d2016bf0e99ed74980 Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Fri, 4 Nov 2022 01:29:37 -0400 Subject: Add support to define structures in mig. Basic syntax is presented below and allows users to define nested structured types by using simpler or structure types as members. Mig will use the C padding and alignment rules to produce the same size as the corresponding C structures. type timespec_t = struct { uint32_t tv_sec; uint32_t tv_nsec; }; This allows us to build stubs that are more easily adaptable to other architectures. Message-Id: --- tests/good/complex-types.defs | 12 ++++++++++++ tests/includes/types.h | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+) (limited to 'tests') diff --git a/tests/good/complex-types.defs b/tests/good/complex-types.defs index 0a5c952..58d417e 100644 --- a/tests/good/complex-types.defs +++ b/tests/good/complex-types.defs @@ -32,9 +32,21 @@ type mach_port_array_t = array[] of mach_port_t; type char_struct_t = struct[4] of char; type string_t = array[256] of char; +type simple_struct_t = struct { byte a; }; + +type complex_struct_x_t = struct { simple_struct_t a; simple_struct_t b; int c; }; + +type complex_struct_y_t = struct { complex_struct_x_t a; byte b; }; + +type complex_struct_z_t = struct { complex_struct_y_t a; int d; }; + routine callcomplex(port : mach_port_t; p : pointer_t; q : intptr_t; str : char_struct_t; strt : string_t; + simple : simple_struct_t; + x : complex_struct_x_t; + y : complex_struct_y_t; + z : complex_struct_z_t; out vec : mach_port_array_t); diff --git a/tests/includes/types.h b/tests/includes/types.h index fe70e69..2a70443 100644 --- a/tests/includes/types.h +++ b/tests/includes/types.h @@ -31,6 +31,26 @@ typedef struct char_struct { typedef char string_t[256]; typedef const char* const_string_t; +typedef struct simple_struct { + char a; +} simple_struct_t; + +typedef struct complex_struct_x { + simple_struct_t a; + simple_struct_t b; + int c; +} complex_struct_x_t; + +typedef struct complex_struct_y { + complex_struct_x_t a; + char b; +} complex_struct_y_t; + +typedef struct complex_struct_z { + complex_struct_y_t a; + int d; +} complex_struct_z_t; + static inline int8_t int_to_int8(int n) { return (int8_t) n; } -- cgit v1.2.3