gcc/libcc1/marshall.cc

167 lines
3.6 KiB
C++
Raw Normal View History

Let GDB reuse GCC's parser. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * aclocal.m4: New file. * callbacks.cc: New file. * callbacks.hh: New file. * cc1plugin-config.h.in: New file. * configure: New file. * configure.ac: New file. * connection.cc: New file. * connection.hh: New file. * findcomp.cc: New file. * findcomp.hh: New file. * libcc1.cc: New file. * libcc1plugin.sym: New file. * libcc1.sym: New file. * Makefile.am: New file. * Makefile.in: New file. * marshall.cc: New file. * marshall.hh: New file. * names.cc: New file. * names.hh: New file. * plugin.cc: New file. * rpc.hh: New file. * status.hh: New file. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * gcc-c-fe.def: New file. * gcc-c-interface.h: New file. * gcc-interface.h: New file. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Tom Tromey <tromey@redhat.com> * c-tree.h (enum c_oracle_request): New. (c_binding_oracle_function): New typedef. (c_binding_oracle, c_pushtag, c_bind): Declare. * c-decl.c (c_binding_oracle): New global. (I_SYMBOL_CHECKED): New macro. (i_symbol_binding): New function. (I_SYMBOL_BINDING, I_SYMBOL_DECL): Redefine. (I_TAG_CHECKED): New macro. (i_tag_binding): New function. (I_TAG_BINDING, I_TAG_DECL): Redefine. (I_LABEL_CHECKED): New macro. (i_label_binding): New function. (I_LABEL_BINDING, I_LABEL_DECL): Redefine. (c_print_identifier): Save and restore c_binding_oracle. (c_pushtag, c_bind): New functions. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Tom Tromey <tromey@redhat.com> * aclocal.m4, configure: Rebuild. * Makefile.in (aclocal_deps): Add gcc-plugin.m4. * configure.ac: Use GCC_ENABLE_PLUGINS. * stor-layout.c (finish_bitfield_layout): Now public. Change argument type to 'tree'. (finish_record_layout): Update. * stor-layout.h (finish_bitfield_layout): Declare. 2014-10-27 Tom Tromey <tromey@redhat.com> * gcc-plugin.m4: New file. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Tom Tromey <tromey@redhat.com> * Makefile.def: Add libcc1 to host_modules. * configure.ac (host_tools): Add libcc1. * Makefile.in, configure: Rebuild. From-SVN: r216748
2014-10-27 18:21:42 +01:00
/* Marshalling and unmarshalling.
Copyright (C) 2014-2016 Free Software Foundation, Inc.
Let GDB reuse GCC's parser. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * aclocal.m4: New file. * callbacks.cc: New file. * callbacks.hh: New file. * cc1plugin-config.h.in: New file. * configure: New file. * configure.ac: New file. * connection.cc: New file. * connection.hh: New file. * findcomp.cc: New file. * findcomp.hh: New file. * libcc1.cc: New file. * libcc1plugin.sym: New file. * libcc1.sym: New file. * Makefile.am: New file. * Makefile.in: New file. * marshall.cc: New file. * marshall.hh: New file. * names.cc: New file. * names.hh: New file. * plugin.cc: New file. * rpc.hh: New file. * status.hh: New file. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Jan Kratochvil <jan.kratochvil@redhat.com> Tom Tromey <tromey@redhat.com> * gcc-c-fe.def: New file. * gcc-c-interface.h: New file. * gcc-interface.h: New file. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Tom Tromey <tromey@redhat.com> * c-tree.h (enum c_oracle_request): New. (c_binding_oracle_function): New typedef. (c_binding_oracle, c_pushtag, c_bind): Declare. * c-decl.c (c_binding_oracle): New global. (I_SYMBOL_CHECKED): New macro. (i_symbol_binding): New function. (I_SYMBOL_BINDING, I_SYMBOL_DECL): Redefine. (I_TAG_CHECKED): New macro. (i_tag_binding): New function. (I_TAG_BINDING, I_TAG_DECL): Redefine. (I_LABEL_CHECKED): New macro. (i_label_binding): New function. (I_LABEL_BINDING, I_LABEL_DECL): Redefine. (c_print_identifier): Save and restore c_binding_oracle. (c_pushtag, c_bind): New functions. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Tom Tromey <tromey@redhat.com> * aclocal.m4, configure: Rebuild. * Makefile.in (aclocal_deps): Add gcc-plugin.m4. * configure.ac: Use GCC_ENABLE_PLUGINS. * stor-layout.c (finish_bitfield_layout): Now public. Change argument type to 'tree'. (finish_record_layout): Update. * stor-layout.h (finish_bitfield_layout): Declare. 2014-10-27 Tom Tromey <tromey@redhat.com> * gcc-plugin.m4: New file. 2014-10-27 Phil Muldoon <pmuldoon@redhat.com> Tom Tromey <tromey@redhat.com> * Makefile.def: Add libcc1 to host_modules. * configure.ac (host_tools): Add libcc1. * Makefile.in, configure: Rebuild. From-SVN: r216748
2014-10-27 18:21:42 +01:00
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
#include <cc1plugin-config.h>
#include <new>
#include <string.h>
#include "marshall.hh"
#include "connection.hh"
cc1_plugin::status
cc1_plugin::unmarshall_check (connection *conn, unsigned long long check)
{
unsigned long long r;
if (!unmarshall (conn, &r))
return FAIL;
return check == r ? OK : FAIL;
}
cc1_plugin::status
cc1_plugin::marshall_intlike (connection *conn, unsigned long long val)
{
if (!conn->send ('i'))
return FAIL;
return conn->send (&val, sizeof (val));
}
cc1_plugin::status
cc1_plugin::unmarshall_intlike (connection *conn, unsigned long long *result)
{
if (!conn->require ('i'))
return FAIL;
return conn->get (result, sizeof (*result));
}
cc1_plugin::status
cc1_plugin::unmarshall (connection *conn, enum gcc_c_symbol_kind *result)
{
protocol_int p;
if (!unmarshall_intlike (conn, &p))
return FAIL;
*result = (enum gcc_c_symbol_kind) p;
return OK;
}
cc1_plugin::status
cc1_plugin::unmarshall (connection *conn, enum gcc_c_oracle_request *result)
{
protocol_int p;
if (!unmarshall_intlike (conn, &p))
return FAIL;
*result = (enum gcc_c_oracle_request) p;
return OK;
}
cc1_plugin::status
cc1_plugin::unmarshall (connection *conn, enum gcc_qualifiers *result)
{
protocol_int p;
if (!unmarshall_intlike (conn, &p))
return FAIL;
*result = (enum gcc_qualifiers) p;
return OK;
}
cc1_plugin::status
cc1_plugin::marshall (connection *conn, const char *str)
{
if (!conn->send ('s'))
return FAIL;
unsigned long long len = str == NULL ? -1ULL : strlen (str);
if (!conn->send (&len, sizeof (len)))
return FAIL;
if (str == NULL)
return OK;
return conn->send (str, len);
}
cc1_plugin::status
cc1_plugin::unmarshall (connection *conn, char **result)
{
unsigned long long len;
if (!conn->require ('s'))
return FAIL;
if (!conn->get (&len, sizeof (len)))
return FAIL;
if (len == -1ULL)
{
*result = NULL;
return OK;
}
char *str = new (std::nothrow) char[len + 1];
if (str == NULL)
return FAIL;
if (!conn->get (str, len))
{
delete[] str;
return FAIL;
}
str[len] = '\0';
*result = str;
return OK;
}
cc1_plugin::status
cc1_plugin::marshall (connection *conn, const gcc_type_array *a)
{
if (!conn->send ('a'))
return FAIL;
unsigned long long r = a->n_elements;
if (!conn->send (&r, sizeof (r)))
return FAIL;
return conn->send (a->elements, r * sizeof (a->elements[0]));
}
cc1_plugin::status
cc1_plugin::unmarshall (connection *conn, gcc_type_array **result)
{
unsigned long long len;
if (!conn->require ('a'))
return FAIL;
if (!conn->get (&len, sizeof (len)))
return FAIL;
*result = new gcc_type_array;
(*result)->n_elements = len;
(*result)->elements = new gcc_type[len];
if (!conn->get ((*result)->elements, len * sizeof ((*result)->elements[0])))
{
delete[] (*result)->elements;
delete *result;
return FAIL;
}
return OK;
}