1 /* Marshalling and unmarshalling.
2 Copyright (C) 2014-2021 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #ifndef CC1_PLUGIN_MARSHALL_HH
21 #define CC1_PLUGIN_MARSHALL_HH
23 #include <type_traits>
26 #include "gcc-interface.h"
32 // Only a single kind of integer is ever sent over the wire, and
34 typedef unsigned long long protocol_int
;
36 // Read an integer from the connection and verify that it has the
38 status
unmarshall_check (connection
*, protocol_int v
);
40 // Write an integer, prefixed with the integer type marker, to the
42 status
marshall_intlike (connection
*, protocol_int
);
44 // Read a type marker from the connection and verify that it is an
45 // integer type marker. If not, return FAIL. If so, read an
46 // integer store it in the out argument.
47 status
unmarshall_intlike (connection
*, protocol_int
*);
49 status
marshall_array_start (connection
*, char, size_t);
50 status
marshall_array_elmts (connection
*, size_t, void *);
52 status
unmarshall_array_start (connection
*, char, size_t *);
53 status
unmarshall_array_elmts (connection
*, size_t, void *);
55 // An "empty" marshall call -- used to handle the base case for some
56 // variadic templates.
58 status
marshall (connection
*)
63 // A template function that can handle marshalling various integer
64 // objects to the connection.
66 status
marshall (connection
*conn
, T scalar
)
68 return marshall_intlike (conn
, scalar
);
71 // A template function that can handle unmarshalling various integer
72 // objects from the connection. Note that there's no way at the
73 // protocol level to distinguish different int types.
75 status
unmarshall (connection
*conn
, T
*scalar
,
76 typename
std::enable_if
<std::is_integral
<T
>::value
, T
>::type
* = 0)
80 if (!unmarshall_intlike (conn
, &result
))
86 // A template function that can handle unmarshalling various enum
87 // objects from the connection.
89 status
unmarshall (connection
*conn
, T
*e_val
,
90 typename
std::enable_if
<std::is_enum
<T
>::value
, T
>::type
* = 0)
94 if (!unmarshall_intlike (conn
, &result
))
100 // Send a string type marker followed by a string.
101 status
marshall (connection
*, const char *);
103 // Read a string type marker followed by a string. The caller is
104 // responsible for freeing the resulting string using 'delete[]'.
105 status
unmarshall (connection
*, char **);
107 // Send a gcc_type_array marker followed by the array.
108 status
marshall (connection
*, const gcc_type_array
*);
110 // Read a gcc_type_array marker, followed by a gcc_type_array. The
111 // resulting array must be freed by the caller, using 'delete[]' on
112 // the elements, and 'delete' on the array object itself.
113 status
unmarshall (connection
*, struct gcc_type_array
**);
115 template<typename T1
, typename T2
, typename
... Arg
>
116 status
marshall (connection
*c
, T1 arg1
, T2 arg2
, Arg
... rest
)
118 if (!marshall (c
, arg1
))
120 return marshall (c
, arg2
, rest
...);
124 #endif // CC1_PLUGIN_MARSHALL_HH