1 /* Marshalling and unmarshalling.
2 Copyright (C) 2014-2016 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 #include <cc1plugin-config.h>
23 #include "marshall.hh"
24 #include "connection.hh"
27 cc1_plugin::unmarshall_check (connection
*conn
, unsigned long long check
)
31 if (!unmarshall (conn
, &r
))
33 return check
== r
? OK
: FAIL
;
37 cc1_plugin::marshall_intlike (connection
*conn
, unsigned long long val
)
39 if (!conn
->send ('i'))
41 return conn
->send (&val
, sizeof (val
));
45 cc1_plugin::unmarshall_intlike (connection
*conn
, unsigned long long *result
)
47 if (!conn
->require ('i'))
49 return conn
->get (result
, sizeof (*result
));
53 cc1_plugin::unmarshall (connection
*conn
, enum gcc_c_symbol_kind
*result
)
56 if (!unmarshall_intlike (conn
, &p
))
58 *result
= (enum gcc_c_symbol_kind
) p
;
63 cc1_plugin::unmarshall (connection
*conn
, enum gcc_c_oracle_request
*result
)
66 if (!unmarshall_intlike (conn
, &p
))
68 *result
= (enum gcc_c_oracle_request
) p
;
73 cc1_plugin::unmarshall (connection
*conn
, enum gcc_qualifiers
*result
)
76 if (!unmarshall_intlike (conn
, &p
))
78 *result
= (enum gcc_qualifiers
) p
;
83 cc1_plugin::marshall (connection
*conn
, const char *str
)
85 if (!conn
->send ('s'))
88 unsigned long long len
= str
== NULL
? -1ULL : strlen (str
);
89 if (!conn
->send (&len
, sizeof (len
)))
95 return conn
->send (str
, len
);
99 cc1_plugin::unmarshall (connection
*conn
, char **result
)
101 unsigned long long len
;
103 if (!conn
->require ('s'))
105 if (!conn
->get (&len
, sizeof (len
)))
114 char *str
= new (std::nothrow
) char[len
+ 1];
118 if (!conn
->get (str
, len
))
131 cc1_plugin::marshall (connection
*conn
, const gcc_type_array
*a
)
133 if (!conn
->send ('a'))
136 unsigned long long r
= a
->n_elements
;
137 if (!conn
->send (&r
, sizeof (r
)))
140 return conn
->send (a
->elements
, r
* sizeof (a
->elements
[0]));
144 cc1_plugin::unmarshall (connection
*conn
, gcc_type_array
**result
)
146 unsigned long long len
;
148 if (!conn
->require ('a'))
150 if (!conn
->get (&len
, sizeof (len
)))
153 *result
= new gcc_type_array
;
155 (*result
)->n_elements
= len
;
156 (*result
)->elements
= new gcc_type
[len
];
158 if (!conn
->get ((*result
)->elements
, len
* sizeof ((*result
)->elements
[0])))
160 delete[] (*result
)->elements
;