[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] Make MIG recognize the basic C integral types.
From: |
Flavio Cruz |
Subject: |
[PATCH] Make MIG recognize the basic C integral types. |
Date: |
Tue, 19 Apr 2016 03:05:13 -0400 |
User-agent: |
Mutt/1.5.24 (2015-08-30) |
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.
---
cpu.sym | 3 +++
tests/base_types.defs | 1 -
tests/good/complex-types.defs | 4 ++--
tests/good/directions.defs | 3 ---
tests/good/types.defs | 3 +--
type.c | 56 ++++++++++++++++++++++++++++++-------------
6 files changed, 45 insertions(+), 25 deletions(-)
diff --git a/cpu.sym b/cpu.sym
index eca50f3..36e5317 100644
--- a/cpu.sym
+++ b/cpu.sym
@@ -25,6 +25,9 @@
expr sizeof(integer_t) word_size
expr sizeof(integer_t)*8 word_size_in_bits
+expr sizeof(int) sizeof_int
+expr sizeof(char) sizeof_char
+expr sizeof(short) sizeof_short
expr sizeof(void*) sizeof_pointer
expr sizeof(mach_msg_header_t) sizeof_mach_msg_header_t
expr sizeof(mach_msg_type_t) sizeof_mach_msg_type_t
diff --git a/tests/base_types.defs b/tests/base_types.defs
index a226056..5118ea2 100644
--- a/tests/base_types.defs
+++ b/tests/base_types.defs
@@ -1,4 +1,3 @@
-type int = MACH_MSG_TYPE_INTEGER_32;
type int64_t = MACH_MSG_TYPE_INTEGER_64;
type int32_t = MACH_MSG_TYPE_INTEGER_32;
type mach_port_t = MACH_MSG_TYPE_COPY_SEND;
diff --git a/tests/good/complex-types.defs b/tests/good/complex-types.defs
index a10fc21..0a5c952 100644
--- a/tests/good/complex-types.defs
+++ b/tests/good/complex-types.defs
@@ -22,8 +22,8 @@ subsystem types 0;
import <stdint.h>;
import "types.h";
-type char = MACH_MSG_TYPE_BYTE;
-type intptr_t = ^char;
+type byte = MACH_MSG_TYPE_BYTE;
+type intptr_t = ^byte;
type pointer_t = ^array[] of MACH_MSG_TYPE_BYTE
ctype: vm_offset_t;
diff --git a/tests/good/directions.defs b/tests/good/directions.defs
index 37c5767..daae678 100644
--- a/tests/good/directions.defs
+++ b/tests/good/directions.defs
@@ -19,9 +19,6 @@
/* Tests arguments with different directions. */
subsystem directions 100;
-type char = MACH_MSG_TYPE_BYTE;
-type int = MACH_MSG_TYPE_INTEGER_32;
-
type mach_port_t = MACH_MSG_TYPE_COPY_SEND;
type mach_port_array_t = array[] of mach_port_t;
diff --git a/tests/good/types.defs b/tests/good/types.defs
index a27c191..5ef041c 100644
--- a/tests/good/types.defs
+++ b/tests/good/types.defs
@@ -23,7 +23,6 @@ import <stdint.h>;
import "types.h";
#include "../base_types.defs"
-type char = MACH_MSG_TYPE_CHAR;
type int16_t = MACH_MSG_TYPE_INTEGER_16;
type boolean_t = MACH_MSG_TYPE_BOOLEAN;
type uint16_t = MACH_MSG_TYPE_INTEGER_16;
@@ -50,7 +49,7 @@ type trans_int = int
outtran: int int8_to_int(int8_t);
routine alltypes(port : mach_port_t;
- c : char; s : int16_t; i : int;
+ c : char; s1 : int16_t; s2 : short; i : int;
i32 : int32_t; i64 : int64_t; bool : boolean_t;
ui16 : uint16_t; ui32 : uint32_t; ui64 : uint64_t);
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));
}
/******************************************************
--
2.6.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH] Make MIG recognize the basic C integral types.,
Flavio Cruz <=