111
|
1 /* Marshalling and unmarshalling.
|
145
|
2 Copyright (C) 2014-2020 Free Software Foundation, Inc.
|
111
|
3
|
|
4 This file is part of GCC.
|
|
5
|
|
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.
|
|
10
|
|
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.
|
|
15
|
|
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/>. */
|
|
19
|
|
20 #ifndef CC1_PLUGIN_MARSHALL_HH
|
|
21 #define CC1_PLUGIN_MARSHALL_HH
|
|
22
|
|
23 #include "status.hh"
|
|
24 #include "gcc-interface.h"
|
|
25
|
|
26 namespace cc1_plugin
|
|
27 {
|
|
28 class connection;
|
|
29
|
|
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;
|
|
33
|
|
34 // Read an integer from the connection and verify that it has the
|
|
35 // value V.
|
|
36 status unmarshall_check (connection *, protocol_int v);
|
|
37
|
|
38 // Write an integer, prefixed with the integer type marker, to the
|
|
39 // connection.
|
|
40 status marshall_intlike (connection *, protocol_int);
|
|
41
|
|
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 *);
|
|
46
|
|
47 status marshall_array_start (connection *, char, size_t);
|
|
48 status marshall_array_elmts (connection *, size_t, void *);
|
|
49
|
|
50 status unmarshall_array_start (connection *, char, size_t *);
|
|
51 status unmarshall_array_elmts (connection *, size_t, void *);
|
|
52
|
|
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)
|
|
57 {
|
|
58 return marshall_intlike (conn, scalar);
|
|
59 }
|
|
60
|
|
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)
|
|
67 {
|
|
68 protocol_int result;
|
|
69
|
|
70 if (!unmarshall_intlike (conn, &result))
|
|
71 return FAIL;
|
|
72 *scalar = result;
|
|
73 return OK;
|
|
74 }
|
|
75
|
|
76 // Send a string type marker followed by a string.
|
|
77 status marshall (connection *, const char *);
|
|
78
|
|
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 **);
|
|
82
|
|
83 // Send a gcc_type_array marker followed by the array.
|
|
84 status marshall (connection *, const gcc_type_array *);
|
|
85
|
|
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 **);
|
|
90 };
|
|
91
|
|
92 #endif // CC1_PLUGIN_MARSHALL_HH
|