aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorRichard Brooksby2012-08-31 10:33:46 +0100
committerRichard Brooksby2012-08-31 10:33:46 +0100
commit84eedf29b06a51ab402c0edf4fcd35ca55a5f453 (patch)
tree90d6d023e72ac87bf84860c57460d66633c40471 /mps/code
parent4e8ff21a10b5aaf2edf7eec5c1a338f60231d97c (diff)
downloademacs-84eedf29b06a51ab402c0edf4fcd35ca55a5f453.tar.gz
emacs-84eedf29b06a51ab402c0edf4fcd35ca55a5f453.zip
Adding consistency checks of the event definitions.
Tidying up comments and declaration order. Copied from Perforce Change: 179125 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/event.c35
-rw-r--r--mps/code/eventcom.h65
-rw-r--r--mps/code/eventdef.h15
3 files changed, 77 insertions, 38 deletions
diff --git a/mps/code/event.c b/mps/code/event.c
index c16ac133bbe..ca50a4ea32f 100644
--- a/mps/code/event.c
+++ b/mps/code/event.c
@@ -80,6 +80,41 @@ Res EventInit(void)
80{ 80{
81 Res res; 81 Res res;
82 82
83 /* Make local enums for all event params in order to check that the indexes
84 in the parameter definition macros are in order, and that parameter
85 idents are unique. */
86
87#define EVENT_CHECK_ENUM_PARAM(name, index, sort, ident) \
88 Event##name##Param##ident,
89
90#define EVENT_CHECK_ENUM(X, name, code, always, kind) \
91 enum Event##name##ParamEnum { \
92 EVENT_##name##_PARAMS(EVENT_CHECK_ENUM_PARAM, name) \
93 Event##name##ParamLIMIT \
94 };
95
96 EVENT_LIST(EVENT_CHECK_ENUM, X)
97
98 /* Check consistency of the event definitions. These are all compile-time
99 checks and should get optimised away. */
100
101#define EVENT_PARAM_CHECK(name, index, sort, ident) \
102 AVER(index == Event##name##Param##ident); \
103 AVER(sizeof(EventF##sort) >= 0); /* check existence of type */
104
105#define EVENT_CHECK(X, name, code, always, kind) \
106 AVER(size_tAlignUp(sizeof(Event##name##Struct), MPS_PF_ALIGN) \
107 <= EventSizeMAX); \
108 AVER(Event##name##Code == code); \
109 AVER(0 <= code && code <= EventCodeMAX); \
110 AVER(sizeof(#name) - 1 <= EventNameMAX); \
111 AVER(Event##name##Always == always); \
112 AVERT(Bool, always); \
113 AVER(0 <= Event##name##Kind && Event##name##Kind < EventKindLIMIT); \
114 EVENT_##name##_PARAMS(EVENT_PARAM_CHECK, name)
115
116 EVENT_LIST(EVENT_CHECK, X)
117
83 /* Ensure that no event can be larger than the maximum event size. */ 118 /* Ensure that no event can be larger than the maximum event size. */
84 AVER(EventBufferSIZE <= EventSizeMAX); 119 AVER(EventBufferSIZE <= EventSizeMAX);
85 120
diff --git a/mps/code/eventcom.h b/mps/code/eventcom.h
index c42dbeb4c61..d5e3959d72c 100644
--- a/mps/code/eventcom.h
+++ b/mps/code/eventcom.h
@@ -88,31 +88,10 @@ typedef Word EventClock;
88#endif 88#endif
89 89
90 90
91/* Types for event fields */
92
93typedef unsigned short EventCode;
94typedef unsigned EventKind;
95typedef unsigned short EventSize;
96#define EventSizeMAX USHRT_MAX
97
98typedef Byte EventStringLen;
99
100typedef struct {
101 EventStringLen len;
102 char str[EventStringLengthMAX];
103} EventStringStruct;
104
105typedef EventStringStruct *EventString;
106
107
108#define EventNameMAX ((size_t)19)
109#define EventCodeMAX ((EventCode)0x0069)
110
111
112/* Event Kinds --- see <design/telemetry/> 91/* Event Kinds --- see <design/telemetry/>
113 * 92 *
114 * All events are classified as being of one event type. 93 * All events are classified as being of one event type.
115 * They are small enough to be able to be used as shifts within a word. 94 * They are small enough to be able to be used as members of a bit set.
116 */ 95 */
117 96
118enum { 97enum {
@@ -129,7 +108,8 @@ enum {
129 108
130/* Event type definitions 109/* Event type definitions
131 * 110 *
132 * Define various constants for each event type to describe them. 111 * Various constants for each event type to describe them, so that they
112 * can easily be looked up from macros by name.
133 */ 113 */
134 114
135/* Note that enum values can be up to fifteen bits long portably. */ 115/* Note that enum values can be up to fifteen bits long portably. */
@@ -149,7 +129,29 @@ EVENT_LIST(EVENT_ENUM, X)
149 * buffers and on the binary telemetry output stream. 129 * buffers and on the binary telemetry output stream.
150 */ 130 */
151 131
152/* Event field types -- similar to WriteF* */ 132/* Types for common event fields */
133typedef unsigned short EventCode;
134typedef unsigned EventKind;
135typedef unsigned short EventSize;
136#define EventSizeMAX USHRT_MAX
137
138/* FIXME: Is the length byte really necessary? Why not use the overall event
139 size and NUL terminate? */
140typedef Byte EventStringLen;
141typedef struct EventStringStruct {
142 EventStringLen len;
143 char str[EventStringLengthMAX];
144} EventStringStruct, *EventString;
145
146/* Common prefix for all event structures. The size field allows an event
147 reader to skip over events whose codes it does not recognise. */
148typedef struct EventAnyStruct {
149 EventCode code; /* encoding of the event type */
150 EventSize size; /* allows reader to skip events of unknown code */
151 EventClock clock; /* when the event occurred */
152} EventAnyStruct;
153
154/* Event field types, for indexing by macro on the event parameter sort */
153typedef void *EventFP; /* pointer to C object */ 155typedef void *EventFP; /* pointer to C object */
154typedef Addr EventFA; /* address on the heap */ 156typedef Addr EventFA; /* address on the heap */
155typedef Word EventFW; /* word */ 157typedef Word EventFW; /* word */
@@ -158,6 +160,7 @@ typedef EventStringStruct EventFS; /* string */
158typedef double EventFD; /* double */ 160typedef double EventFD; /* double */
159typedef int EventFB; /* boolean */ 161typedef int EventFB; /* boolean */
160 162
163/* Event packing bitfield specifiers */
161#define EventFP_BITFIELD 164#define EventFP_BITFIELD
162#define EventFA_BITFIELD 165#define EventFA_BITFIELD
163#define EventFW_BITFIELD 166#define EventFW_BITFIELD
@@ -166,22 +169,14 @@ typedef int EventFB; /* boolean */
166#define EventFD_BITFIELD 169#define EventFD_BITFIELD
167#define EventFB_BITFIELD : 1 170#define EventFB_BITFIELD : 1
168 171
169/* Common prefix for all event structures. The size field allows an event
170 reader to skip over events whose codes it does not recognise. */
171typedef struct EventAnyStruct {
172 EventCode code;
173 EventSize size;
174 EventClock clock;
175} EventAnyStruct;
176
177#define EVENT_STRUCT_FIELD(X, index, sort, ident) \ 172#define EVENT_STRUCT_FIELD(X, index, sort, ident) \
178 EventF##sort f##index EventF##sort##_BITFIELD; 173 EventF##sort f##index EventF##sort##_BITFIELD;
179 174
180#define EVENT_STRUCT(X, name, _code, always, kind) \ 175#define EVENT_STRUCT(X, name, _code, always, kind) \
181 typedef struct Event##name##Struct { \ 176 typedef struct Event##name##Struct { \
182 EventCode code; \ 177 EventCode code; /* Must match EventAnyStruct */ \
183 EventSize size; \ 178 EventSize size; /* ditto */ \
184 EventClock clock; \ 179 EventClock clock; /* ditto */ \
185 EVENT_##name##_PARAMS(EVENT_STRUCT_FIELD, X) \ 180 EVENT_##name##_PARAMS(EVENT_STRUCT_FIELD, X) \
186 } Event##name##Struct; 181 } Event##name##Struct;
187 182
diff --git a/mps/code/eventdef.h b/mps/code/eventdef.h
index a0569bb4a16..77a1269369b 100644
--- a/mps/code/eventdef.h
+++ b/mps/code/eventdef.h
@@ -47,9 +47,14 @@
47 * - Kind: Category into which this event falls, without the 47 * - Kind: Category into which this event falls, without the
48 * leading "EventKind"; 48 * leading "EventKind";
49 * 49 *
50 * TODO: Add a doc string to each event type.
51 *
50 * See also EVENT_*_PARAMS for definition of event parameters. 52 * See also EVENT_*_PARAMS for definition of event parameters.
51 */ 53 */
52 54
55#define EventNameMAX ((size_t)19)
56#define EventCodeMAX ((EventCode)0x0069)
57
53/* FIXME: Work out why not-in-use events were not in use and restore or delete them. */ 58/* FIXME: Work out why not-in-use events were not in use and restore or delete them. */
54 59
55#define EVENT_LIST(EVENT, X) \ 60#define EVENT_LIST(EVENT, X) \
@@ -152,17 +157,21 @@
152 EVENT(X, SegMerge , 0x0068, TRUE, Seg) \ 157 EVENT(X, SegMerge , 0x0068, TRUE, Seg) \
153 EVENT(X, SegSplit , 0x0069, TRUE, Seg) 158 EVENT(X, SegSplit , 0x0069, TRUE, Seg)
154 159
155/* Remember to update EventNameMAX and EventCodeMAX in eventcom.h! */ 160/* Remember to update EventNameMAX and EventCodeMAX in eventcom.h!
161 (These are checked in EventInit.) */
156 162
157 163
158/* EVENT_*_PARAMS -- definition of event parameters 164/* EVENT_*_PARAMS -- definition of event parameters
159 * 165 *
160 * For each event type in EVENT_LIST, these macros list the parameters of 166 * For each event type in EVENT_LIST, these macros list the parameters of
161 * the event. THe columns are: 167 * the event. THe columns are:
162 * - the positional index of the parameter in the list 168 * - the positional index of the parameter in the list, used to define
169 * numeric field names using the C preprocessor
163 * - the parameter sort, similar to writef (Pointer, Addr, Word, Unsigned, 170 * - the parameter sort, similar to writef (Pointer, Addr, Word, Unsigned,
164 * String, Double) 171 * String, Double)
165 * - a parameter name for display 172 * - a parameter identifier for display or use in code
173 *
174 * TODO: Add a doc string to each parameter.
166 */ 175 */
167 176
168#define EVENT_AMCGenCreate_PARAMS(PARAM, X) \ 177#define EVENT_AMCGenCreate_PARAMS(PARAM, X) \