summaryrefslogtreecommitdiff
path: root/type.c
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2016-04-19 03:05:13 -0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2020-01-28 00:38:25 +0100
commitecf59842e472d28a54a16acffe4aaa2f882108c6 (patch)
tree6b5b18641ec85d2b41ac4e6cb7f11ec044bf3c64 /type.c
parent89298f4a0f61799b0a12e0ca297fe26a97c7e64e (diff)
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>
Diffstat (limited to 'type.c')
-rw-r--r--type.c56
1 files changed, 39 insertions, 17 deletions
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));
}
/******************************************************