From ecf59842e472d28a54a16acffe4aaa2f882108c6 Mon Sep 17 00:00:00 2001 From: Flavio Cruz Date: Tue, 19 Apr 2016 03:05:13 -0400 Subject: Make MIG recognize the basic C integral types. Also removed itMakeIntType which was not used anymore. Users can use char, int, and short types without having to define them. These types are defined using the builtin MACH_MSG_TYPE_* types and are architecture independent since they have the same size as the C char, short and int. If these basic types are redefined, MIG will still produce stub code but will produce a warning. * cpu.sym: Define sizeof_int, char, short. * tests/base_types.defs: Remove int. * tests/good/complex-types.defs: Use byte instead of char. * tests/good/directions: Remove char and int. * tests/good/types.defs: Remove char and also use short as a parameter in 'alltypes'. * type.c: Define itCIntTypeDecl. Remove itMakeIntType. Call itInsert for char, short and int. Message-Id: <20160419070513.GA12642@debian> --- type.c | 56 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 17 deletions(-) (limited to 'type.c') diff --git a/type.c b/type.c index 6e2319e..0facd9e 100644 --- a/type.c +++ b/type.c @@ -713,6 +713,40 @@ itCStringDecl(u_int count, boolean_t varying) return it; } +/* Creates a new MIG type based on a basic integral C type. */ +static ipc_type_t * +itCIntTypeDecl(const_string_t ctype, const size_t size) +{ + ipc_type_t *it; + switch (size) { + case 1: + it = itShortDecl(MACH_MSG_TYPE_CHAR, "MACH_MSG_TYPE_CHAR", + MACH_MSG_TYPE_CHAR, "MACH_MSG_TYPE_CHAR", size * 8); + break; + case 2: + it = itShortDecl(MACH_MSG_TYPE_INTEGER_16, + "MACH_MSG_TYPE_INTEGER_16", MACH_MSG_TYPE_INTEGER_16, + "MACH_MSG_TYPE_INTEGER_16", size * 8); + break; + case 4: + it = itShortDecl(MACH_MSG_TYPE_INTEGER_32, + "MACH_MSG_TYPE_INTEGER_32", MACH_MSG_TYPE_INTEGER_32, + "MACH_MSG_TYPE_INTEGER_32", size * 8); + break; + case 8: + it = itShortDecl(MACH_MSG_TYPE_INTEGER_64, + "MACH_MSG_TYPE_INTEGER_64", MACH_MSG_TYPE_INTEGER_64, + "MACH_MSG_TYPE_INTEGER_64", size * 8); + break; + default: + fprintf(stderr, "Unrecognized size %zu for type %s\n", size, ctype); + exit(EXIT_FAILURE); + } + it->itName = ctype; + itCalculateNameInfo(it); + return it; +} + ipc_type_t * itMakeCountType(void) { @@ -747,23 +781,6 @@ itMakeNaturalType(const char *name) return it; } -extern ipc_type_t * -itMakeIntType() -{ - ipc_type_t *it = itAlloc(); - - it->itName = "int"; - it->itInName = MACH_MSG_TYPE_INTEGER_32; - it->itInNameStr = "MACH_MSG_TYPE_INTEGER_32"; - it->itOutName = MACH_MSG_TYPE_INTEGER_32; - it->itOutNameStr = "MACH_MSG_TYPE_INTEGER_32"; - it->itSize = 32; - - itCalculateSizeInfo(it); - itCalculateNameInfo(it); - return it; -} - ipc_type_t * itMakePolyType(void) { @@ -856,6 +873,11 @@ init_type(void) itWaitTimeType = itMakeNaturalType("mach_msg_timeout_t"); itMsgOptionType = itMakeNaturalType("mach_msg_option_t"); + + /* Define basic C integral types. */ + itInsert("char", itCIntTypeDecl("char", sizeof_char)); + itInsert("short", itCIntTypeDecl("short", sizeof_short)); + itInsert("int", itCIntTypeDecl("int", sizeof_int)); } /****************************************************** -- cgit v1.2.3