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 // A template function that can handle marshalling various integer
56 // objects to the connection.
58 status marshall (connection *conn, T scalar)
60 return marshall_intlike (conn, scalar);
63 // A template function that can handle unmarshalling various integer
64 // objects from the connection. Note that there's no way at the
65 // protocol level to distinguish different int types.
67 status unmarshall (connection *conn, T *scalar,
68 typename std::enable_if<std::is_integral<T>::value, T>::type * = 0)
72 if (!unmarshall_intlike (conn, &result))
78 // A template function that can handle unmarshalling various enum
79 // objects from the connection.
81 status unmarshall (connection *conn, T *e_val,
82 typename std::enable_if<std::is_enum<T>::value, T>::type * = 0)
86 if (!unmarshall_intlike (conn, &result))
92 // Send a string type marker followed by a string.
93 status marshall (connection *, const char *);
95 // Read a string type marker followed by a string. The caller is
96 // responsible for freeing the resulting string using 'delete[]'.
97 status unmarshall (connection *, char **);
99 // Send a gcc_type_array marker followed by the array.
100 status marshall (connection *, const gcc_type_array *);
102 // Read a gcc_type_array marker, followed by a gcc_type_array. The
103 // resulting array must be freed by the caller, using 'delete[]' on
104 // the elements, and 'delete' on the array object itself.
105 status unmarshall (connection *, struct gcc_type_array **);
108 #endif // CC1_PLUGIN_MARSHALL_HH