diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2023-04-06 14:29:53 +0200 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2023-04-19 08:48:33 +0000 |
commit | da0553bcbfab23c4cf908092ea5cc29c454e157b (patch) | |
tree | 426a71ab175714d20f18dc9ee88bc53437d478cd | |
parent | 50583d42838b99cf89d2ac9b7ec5733cef41dcd1 (diff) | |
download | gcc-da0553bcbfab23c4cf908092ea5cc29c454e157b.zip gcc-da0553bcbfab23c4cf908092ea5cc29c454e157b.tar.gz gcc-da0553bcbfab23c4cf908092ea5cc29c454e157b.tar.bz2 |
libproc_macro: Add literal ffi implementations
Add literal type related ffi functions implementation.
ChangeLog:
* libgrust/libproc_macro/Makefile.am: Add literal.cc.
* libgrust/libproc_macro/Makefile.in: Regenerate.
* libgrust/libproc_macro/literal.h (Literal__drop): Implement
drop.
(Literal__string): Constructor from a string function prototype.
(Literal__byte_string): Constructor from a byte string function
prototype.
(Literal__from_string): Add function body, no implementation
yet.
* libgrust/libproc_macro/literal.cc: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
-rw-r--r-- | libgrust/libproc_macro/Makefile.am | 3 | ||||
-rw-r--r-- | libgrust/libproc_macro/Makefile.in | 6 | ||||
-rw-r--r-- | libgrust/libproc_macro/literal.cc | 80 | ||||
-rw-r--r-- | libgrust/libproc_macro/literal.h | 15 |
4 files changed, 101 insertions, 3 deletions
diff --git a/libgrust/libproc_macro/Makefile.am b/libgrust/libproc_macro/Makefile.am index 1e61d12..4bc7943 100644 --- a/libgrust/libproc_macro/Makefile.am +++ b/libgrust/libproc_macro/Makefile.am @@ -51,7 +51,8 @@ AM_MAKEFLAGS = \ toolexeclib_LTLIBRARIES = libproc_macro.la libproc_macro_la_SOURCES = \ - proc_macro.cc + proc_macro.cc \ + literal.cc include_HEADERS = \ proc_macro.h diff --git a/libgrust/libproc_macro/Makefile.in b/libgrust/libproc_macro/Makefile.in index d3a3973..57ace6a 100644 --- a/libgrust/libproc_macro/Makefile.in +++ b/libgrust/libproc_macro/Makefile.in @@ -138,7 +138,7 @@ am__installdirs = "$(DESTDIR)$(toolexeclibdir)" \ "$(DESTDIR)$(includedir)" LTLIBRARIES = $(toolexeclib_LTLIBRARIES) libproc_macro_la_LIBADD = -am_libproc_macro_la_OBJECTS = proc_macro.lo +am_libproc_macro_la_OBJECTS = proc_macro.lo literal.lo libproc_macro_la_OBJECTS = $(am_libproc_macro_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -385,7 +385,8 @@ AM_MAKEFLAGS = \ toolexeclib_LTLIBRARIES = libproc_macro.la libproc_macro_la_SOURCES = \ - proc_macro.cc + proc_macro.cc \ + literal.cc include_HEADERS = \ proc_macro.h @@ -468,6 +469,7 @@ mostlyclean-compile: distclean-compile: -rm -f *.tab.c +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/literal.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/proc_macro.Plo@am__quote@ .cc.o: diff --git a/libgrust/libproc_macro/literal.cc b/libgrust/libproc_macro/literal.cc new file mode 100644 index 0000000..a667fcb --- /dev/null +++ b/libgrust/libproc_macro/literal.cc @@ -0,0 +1,80 @@ +// Copyright (C) 2023 Free Software Foundation, Inc. +// +// This file is part of the GNU Proc Macro Library. This library 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. + +// This library 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. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// <http://www.gnu.org/licenses/>. + +#include "literal.h" +#include <cstring> + +extern "C" { + +void +Literal__drop (Literal *lit) +{ + switch (lit->tag) + { + case STRING: + delete lit->payload.string_payload.data; + lit->payload.string_payload.len = 0; + break; + case BYTE_STRING: + delete lit->payload.byte_string_payload.data; + lit->payload.byte_string_payload.size = 0; + break; + case CHAR: + case UNSIGNED: + case SIGNED: + case USIZE: + case ISIZE: + case FLOAT32: + case FLOAT64: + break; + } +} + +Literal +Literal__string (const unsigned char *str, std::uint64_t len) +{ + unsigned char *data = new unsigned char[len]; + StringPayload str_payload = {data, len}; + std::memcpy (data, str, len); + LiteralPayload payload; + payload.string_payload = str_payload; + return {STRING, payload}; +} + +Literal +Literal__byte_string (const std::uint8_t *bytes, std::uint64_t len) +{ + std::uint8_t *data = new std::uint8_t[len]; + ByteStringPayload bstr_payload = {data, len}; + std::memcpy (data, bytes, len); + LiteralPayload payload; + payload.byte_string_payload = bstr_payload; + return {BYTE_STRING, payload}; +} + +bool +Literal__from_string (const unsigned char *str, std::uint64_t len, Literal *lit) +{ + // FIXME: implement this function with parser + return false; +} +} diff --git a/libgrust/libproc_macro/literal.h b/libgrust/libproc_macro/literal.h index 7b3e3c5..62a1452 100644 --- a/libgrust/libproc_macro/literal.h +++ b/libgrust/libproc_macro/literal.h @@ -158,4 +158,19 @@ struct Literal LiteralPayload payload; }; +extern "C" { +void +Literal__drop (Literal *lit); + +Literal +Literal__string (const unsigned char *str, std::uint64_t len); + +Literal +Literal__byte_string (const std::uint8_t *bytes, std::uint64_t len); + +bool +Literal__from_string (const unsigned char *str, std::uint64_t len, + Literal *lit); +} + #endif /* ! LITERAL_H */ |