[multiple changes]
[official-gcc.git] / libcc1 / marshall.hh
blobd238f3a75f223a98293709a8dda34521983f30d3
1 /* Marshalling and unmarshalling.
2 Copyright (C) 2014-2017 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
9 version.
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
14 for more details.
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 "status.hh"
24 #include "gcc-interface.h"
26 namespace cc1_plugin
28 class connection;
30 // Only a single kind of integer is ever sent over the wire, and
31 // this is it.
32 typedef unsigned long long protocol_int;
34 // Read an integer from the connection and verify that it has the
35 // value V.
36 status unmarshall_check (connection *, protocol_int v);
38 // Write an integer, prefixed with the integer type marker, to the
39 // connection.
40 status marshall_intlike (connection *, protocol_int);
42 // Read a type marker from the connection and verify that it is an
43 // integer type marker. If not, return FAIL. If so, read an
44 // integer store it in the out argument.
45 status unmarshall_intlike (connection *, protocol_int *);
47 status marshall_array_start (connection *, char, size_t);
48 status marshall_array_elmts (connection *, size_t, void *);
50 status unmarshall_array_start (connection *, char, size_t *);
51 status unmarshall_array_elmts (connection *, size_t, void *);
53 // A template function that can handle marshalling various integer
54 // objects to the connection.
55 template<typename T>
56 status marshall (connection *conn, T scalar)
58 return marshall_intlike (conn, scalar);
61 // A template function that can handle unmarshalling various integer
62 // objects from the connection. Note that this can't be
63 // instantiated for enum types. Note also that there's no way at
64 // the protocol level to distinguish different int types.
65 template<typename T>
66 status unmarshall (connection *conn, T *scalar)
68 protocol_int result;
70 if (!unmarshall_intlike (conn, &result))
71 return FAIL;
72 *scalar = result;
73 return OK;
76 // Send a string type marker followed by a string.
77 status marshall (connection *, const char *);
79 // Read a string type marker followed by a string. The caller is
80 // responsible for freeing the resulting string using 'delete[]'.
81 status unmarshall (connection *, char **);
83 // Send a gcc_type_array marker followed by the array.
84 status marshall (connection *, const gcc_type_array *);
86 // Read a gcc_type_array marker, followed by a gcc_type_array. The
87 // resulting array must be freed by the caller, using 'delete[]' on
88 // the elements, and 'delete' on the array object itself.
89 status unmarshall (connection *, struct gcc_type_array **);
92 #endif // CC1_PLUGIN_MARSHALL_HH