Commit Graph

32 Commits

Author SHA1 Message Date
Pierre-Emmanuel Patry
10c9b9f0cc gccrs: libproc_macro: Change cpp literal representation
Change the literal representation on cpp side to match the new one in
rust. This means FFIString had to be implemented on cpp side. A few
helper functions has also been introduced.

libgrust/ChangeLog:

	* libproc_macro/Makefile.am: Add ffistring unit to
	compiled objects list.
	* libproc_macro/Makefile.in: Regenerate.
	* libproc_macro/literal.cc (Literal::drop): Change with
	a call to ffistring drop function.
	(Literal::make_literal): Add new helper constructor
	(Literal__drop): Remove this function.
	(Literal__string): Likewise.
	(Literal__byte_string): Likewise.
	(Literal__from_string): Moved this function.
	(Literal::make_unsigned): Changed the constructor to match the
	new layout.
	(Literal::make_signed): Likewise.
	(Literal::clone): Reimplement th eclone function.
	(Literal::make_u8): Changed the constructor, make suffixed by
	default.
	(Literal::make_u16): Likewise.
	(Literal::make_u32): Likewise.
	(Literal::make_u64): Likewise.
	(Literal::make_i8): Likewise.
	(Literal::make_i16): Likewise.
	(Literal::make_i32): Likewise.
	(Literal::make_i64): Likewise.
	(Literal::make_string): Likewise.
	(Literal::make_byte_string): Likewise.
	(Literal::make_f32): Likewise.
	(Literal::make_f64): Likewise.
	(Literal::make_char): Likewise.
	(Literal::make_usize): Likewise.
	(Literal::make_isize): Likewise.
	(LitKind::make_byte): Add new helper constructor to avoid having
	to set the payload value.
	(LitKind::make_char): Likewise.
	(LitKind::make_integer): Likewise.
	(LitKind::make_float): Likewise.
	(LitKind::make_str): Likewise.
	(LitKind::make_str_raw): Add a new helper constructor which
	takes the payload value as an argument.
	(LitKind::make_byte_str): Add new helper constructor to avoid
	mistakes with payload value.
	(LitKind::make_byte_str_raw): Add a new helper constructor which
	takes the payload value as an argument.
	* libproc_macro/literal.h: Add new functions prototype.
	(enum UnsignedTag): Removed because it is now unused.
	(struct Payload128): Likewise.
	(union UnsignedPayload): Likewise.
	(struct Unsigned): Likewise.
	(enum SignedTag): Likewise.
	(union SignedPayload): Likewise.
	(struct Signed): Likewise.
	(enum LiteralTag): Likewise.
	(enum LitKindTag): Likewise.
	(struct StringPayload): Likewise.
	(struct ByteStringPayload): Likewise.
	(union LitKindPayload): Likewise.
	(struct UnsignedSuffixPayload): Likewise.
	(struct LitKind): Add new literal kind struct representation to
	match the enum on rust side.
	(struct SignedSuffixPayload): Removed because now unused.
	(struct UsizePayload): Likewise.
	(struct IsizePayload): Likewise.
	(struct Float32Payload): Likewise.
	(struct Float64Payload): Likewise.
	(union LiteralPayload): Likewise.
	(struct Literal): Changed the internals of the structure.
	(Literal__drop): Removed the drop function fom the c interface.
	(Literal__string): Removed unused function.
	(Literal__byte_string): Removed unused function.
	* libproc_macro/ffistring.cc: New file.
	* libproc_macro/ffistring.h: New file.

gcc/rust/ChangeLog:

	* lex/rust-token.h: Implement hash for token id enumeration.
	* util/rust-token-converter.cc (dispatch_float_literals): Update
	to new internals.
	(dispatch_integer_literals): Likewise.
	(convert): Likewise.
	(string_literal): Remove function.
	(byte_string_literal): Likewise.
	(unsigned_literal): Likewise.
	(signed_literal): Likewise.
	(from_literal): Update with new internals.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:37:19 +01:00
Pierre-Emmanuel Patry
5605333c90 gccrs: libproc_macro: Change rust literal internals
Rust interface literal internals were taking a type and storing that
type. This lead to multiple problems such as various conversion from
string to int/float/other type as well as dead end on undetermined types
(type checker runs at a later stage).

libgrust/ChangeLog:

	* libproc_macro/rust/bridge.rs: Add ffistring module.
	* libproc_macro/rust/bridge/literal.rs: Rework type
	internals.
	* libproc_macro/rust/bridge/ffistring.rs: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:37:19 +01:00
Pierre-Emmanuel Patry
fb3eb13f0f gccrs: libproc_macro: Add helpers to construct Procmacro
Add some helper functions to create Procmacro tagged unions.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (Procmacro::make_derive):
	Add custom derive macro constructor.
	(Procmacro::make_attribute): Add attribute macro constructor.
	(Procmacro::make_bang): Add bang macro constructor.
	* libproc_macro/proc_macro.h (struct Procmacro):
	Add helper function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:16 +01:00
Pierre-Emmanuel Patry
1ff234bffd gccrs: libproc_macro: Add proc_macro interface structures
Add the structures that should be used by a compiler opening a
procedural macro to either identify or execute it.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.h (struct CustomDerivePayload):
	Add C compatible payload structure.
	(struct AttrPayload): Likewise.
	(struct BangPayload): Likewise.
	(enum ProcmacroTag): Add tag for tagged union.
	(union ProcmacroPayload): Proc macro payload union.
	(struct Procmacro): Tagged union.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:16 +01:00
Pierre-Emmanuel Patry
ba534efbc0 gccrs: libproc_macro: Change proc_macro.h to main header
Add different include directives to the proc_macro header in order to
create an handy header much alike rust-system.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.h: Add Literal, Punct,
	Group, TokenTree and Tokenstream headers.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:16 +01:00
Pierre-Emmanuel Patry
71180a9eed gccrs: libproc_macro: Build statically
We do not need dynamic linking, all use case of this library cover can
be done statically hence the change.

gcc/rust/ChangeLog:

	* Make-lang.in: Link against the static libproc_macro.

libgrust/ChangeLog:

	* Makefile.am: Remove libtool forwarding.
	* Makefile.in: Regenerate.
	* libproc_macro/Makefile.am: Creates an archive instead
	of using libtool.
	* libproc_macro/Makefile.in: Regenerate.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:16 +01:00
Pierre-Emmanuel Patry
b1a8cb2fbf gccrs: libproc_macro: Remove internal named namespaces
Either move the elements from their namespace up to the procmacro
namespace or make the namespace anonymous.

libgrust/ChangeLog:

	* libproc_macro/group.cc (Group::make_group): Remove
	internal namespace.
	(Group::drop): Likewise.
	* libproc_macro/group.h (enum Delimiter): Make members
	upercase.
	(struct Group):
	* libproc_macro/ident.cc (Ident::drop): Remove internal
	namespace.
	* libproc_macro/ident.h (Ident__clone): Likewise.
	* libproc_macro/literal.cc (Literal::make_isize):
	Likewise.
	* libproc_macro/literal.h (union LiteralPayload):
	Likewise.
	(Literal__from_string): Likewise.
	* libproc_macro/punct.cc (Punct::make_punct): Likewise.
	* libproc_macro/punct.h (enum Spacing): Make members
	uppercase.
	* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
	Remove internal namespace.
	(TokenStream::grow): Likewise.
	(TokenStream::push): Likewise.
	(TokenSream__push): Likewise.
	(TokenStream__clone): Likewise.
	(TokenStream__drop): Likewise.
	* libproc_macro/tokenstream.h (struct TokenStream):
	Likewise.
	(TokenSream__push): Likewise.
	(TokenStream__drop): Likewise.
	* libproc_macro/tokentree.cc (TokenTree::make_tokentree):
	Likewise.
	(TokenTree::drop): Likewise.
	* libproc_macro/tokentree.h (union TokenTreePayload):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:16 +01:00
Pierre-Emmanuel Patry
e112189800 gccrs: libproc_macro: Put all structures in a namespace
Put all functions and structures in a Procmacro namespace to avoid
spilling names in any other namespace.

libgrust/ChangeLog:

	* libproc_macro/group.cc (Group::drop): Add Procmacro
	namespace.
	* libproc_macro/group.h: Likewise.
	* libproc_macro/ident.cc (Ident::drop): Likewise.
	* libproc_macro/ident.h (Ident__clone): Likewise.
	* libproc_macro/literal.cc (Literal::make_isize):
	Likewise.
	* libproc_macro/literal.h (Literal__from_string):
	Likewise.
	* libproc_macro/punct.cc (Punct::make_punct): Likewise.
	* libproc_macro/punct.h: Likewise.
	* libproc_macro/tokenstream.cc (TokenStream__drop):
	Likewise.
	* libproc_macro/tokenstream.h (TokenStream__drop):
	Likewise.
	* libproc_macro/tokentree.cc (TokenTree::drop):
	Likewise.
	* libproc_macro/tokentree.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:15 +01:00
Pierre-Emmanuel Patry
2698707419 gccrs: libproc_macro: Fix literal drop function
Fix drop function by changing the delete operator to delete[] in order
to avoid undefined behaviors.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal::drop): Change
	delete operator to delete[].

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
98b779a83c gccrs: libproc_macro: Implement Drop for TokenStream
TokenStream did not have any drop implementation, the memory could not
have been freed correctly.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/token_stream.rs: Implement
	drop.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
b44757f836 gccrs: libproc_macro: Add remaining drop functions
Remaining structures from the rust bridge that missed a drop function
now have one.

libgrust/ChangeLog:

	* libproc_macro/group.cc (Group::drop): Add drop
	implementation.
	* libproc_macro/group.h: Add drop prototype.
	* libproc_macro/tokenstream.cc (TokenStream::drop): Add
	drop implementation.
	(TokenStream__drop): Change to a call to TokenStream::drop.
	* libproc_macro/tokenstream.h: Add drop prototype.
	* libproc_macro/tokentree.cc (TokenTree::drop): Add
	drop implementation.
	* libproc_macro/tokentree.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:12 +01:00
Pierre-Emmanuel Patry
2fa0bbc3ee gccrs: libproc_macro: Add drop function to Literal struct
Add a drop function to clean internal fields of a Literal struct.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal__drop): Replace
	implementation by a call to Literal::drop.
	(Literal::drop): Add drop implementation.
	* libproc_macro/literal.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
c9534eb5d9 gccrs: libproc_macro: Add drop function on Ident struct
Add a drop function that cleans internal fields of a given Ident struct.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident__drop): Replace by call
	to Ident::drop.
	(Ident::drop): Add drop function.
	* libproc_macro/ident.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
d9473a5b55 gccrs: libproc_macro: Add remaining tokenstream structs.
Add remaining missing tokenstream structures. Most are interdependent.

libgrust/ChangeLog:

	* libproc_macro/group.cc: New file.
	* libproc_macro/group.h: New file.
	* libproc_macro/tokenstream.cc: New file.
	* libproc_macro/tokenstream.h: New file.
	* libproc_macro/tokentree.cc: New file.
	* libproc_macro/tokentree.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
27f298c1dd gccrs: libproc_macro: Add Punct struct
Add Punct struct for rust interface as well as a basic named
constructor.

libgrust/ChangeLog:

	* libproc_macro/punct.cc: New file.
	* libproc_macro/punct.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
6a569f5c6c gccrs: libproc_macro: Add namespace to Ident
Add a new Ident namespace to group Ident related enumeration and
structures.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident::make_ident): Add Ident
	namespace.
	* libproc_macro/ident.h (Ident__clone): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
f4b2b28f32 gccrs: libproc_macro: Add named constructor
Add named constructor directly in Ident struct.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident__new): Use named
	constructor.
	(Ident__new_raw): Use named constructor.
	(Ident__clone): Use clone member function.
	(Ident::clone): Make clone const.
	(Ident::make_ident): Add named construcot.
	* libproc_macro/ident.h (struct Ident): Add named
	constructor prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
d2c9c8cf39 gccrs: libproc_macro: Change drop rust interface
Change rust interface on drop function to take a mut pointer instead.
This will match the drop trait interface more closely.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/ident.rs: Change drop
	function interface.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
e8c656ff6e gccrs: libproc_macro: Add ident implementation
Add implementation and representation for ident cpp structure as well as
a high level wrapper interface.

libgrust/ChangeLog:

	* libproc_macro/ident.cc: New file.
	* libproc_macro/ident.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:11 +01:00
Pierre-Emmanuel Patry
aae0830fbf gccrs: libproc_macro: Add member functions to Literal
Add some member functions to the Literal structure as well as named
constructors.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal__string): Add call
	to named constructor.
	(Literal__byte_string): Likewise.
	(Literal::make_unsigned): Add function.
	(Literal::make_signed): Add function.
	(Literal::clone): Likewise.
	(Literal::make_u8): Likewise.
	(Literal::make_u16): Likewise.
	(Literal::make_u32): Likewise.
	(Literal::make_u64): Likewise.
	(Literal::make_i8): Likewise.
	(Literal::make_i16): Likewise.
	(Literal::make_i32): Likewise.
	(Literal::make_i64): Likewise.
	(Literal::make_string): Likewise.
	(Literal::make_byte_string): Likewise.
	(Literal::make_f32): Likewise.
	(Literal::make_f64): Likewise.
	(make_char): Likewise.
	(Literal::make_char): Likewise.
	(make_usize): Likewise.
	(Literal::make_usize): Likewise.
	(make_isize): Likewise.
	(Literal::make_isize): Likewise.
	* libproc_macro/literal.h: Add prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:10 +01:00
Pierre-Emmanuel Patry
a79920c2d6 gccrs: libproc_macro: Put literal members in namespace
Add a Literal namespace to gather all every literal related code.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal__from_string):
	Add abort because unimplemented.
	* libproc_macro/literal.h (Literal__from_string): Add
	namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:10 +01:00
Pierre-Emmanuel Patry
a2605b5a49 gccrs: libproc_macro: Drop function shall take a mutable
The rust API requires a mut reference, hence having a mutable pointer
seems to match better. Furthermore the implementation is now modifying
the struct in order to set the size to 0 instead of simply freeing the
data, this will allow us to easily identify mistaken manual call to this
function.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/literal.rs: Make the
	pointer mutable.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:10 +01:00
Pierre-Emmanuel Patry
86c070baa8 gccrs: libproc_macro: Add literal ffi implementations
Add literal type related ffi functions implementation.

libgrust/ChangeLog:

	* 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.
	* libproc_macro/literal.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:10 +01:00
Pierre-Emmanuel Patry
49eb3f5fc6 gccrs: libproc_macro: Add Literal type
Add the Literal type matching rust ffi definitions.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.h (PROC_MACRO_H): Add
	literal header include directive.
	* libproc_macro/literal.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:10 +01:00
Pierre-Emmanuel Patry
4756e2ae8d gccrs: libproc_macro: Add license headers
Add license headers to existing files.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (test): Remove dummy
	function.
	* libproc_macro/proc_macro.h (test): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:34:09 +01:00
Pierre-Emmanuel Patry
f7379085ae gccrs: libproc_macro: Add rust interface
libgrust/ChangeLog:

	* libproc_macro/rust/bridge.rs: New file.
	* libproc_macro/rust/bridge/group.rs: New file.
	* libproc_macro/rust/bridge/ident.rs: New file.
	* libproc_macro/rust/bridge/literal.rs: New file.
	* libproc_macro/rust/bridge/punct.rs: New file.
	* libproc_macro/rust/bridge/span.rs: New file.
	* libproc_macro/rust/bridge/token_stream.rs: New file.
	* libproc_macro/rust/group.rs: New file.
	* libproc_macro/rust/ident.rs: New file.
	* libproc_macro/rust/lib.rs: New file.
	* libproc_macro/rust/literal.rs: New file.
	* libproc_macro/rust/punct.rs: New file.
	* libproc_macro/rust/span.rs: New file.
	* libproc_macro/rust/token_stream.rs: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:28:39 +01:00
GCC Administrator
6b1d6a2d3a Daily bump. 2024-01-09 00:17:50 +00:00
Thomas Schwinge
cde6f1085b libgrust: 'AM_ENABLE_MULTILIB' only for target builds [PR113056]
..., but not for host builds, which don't need it, and it may cause the build
to fail.

Use what appears to be the standard pattern for that (see
'libbacktrace/configure.ac', 'zlib/configure.ac').

	PR rust/113056
	libgrust/
	* configure.ac: 'AM_ENABLE_MULTILIB' only for target builds.
	* configure: Regenerate.
2024-01-08 12:01:05 +01:00
Jakub Jelinek
6a720d41ff Update Copyright year in ChangeLog files
2023 -> 2024
2024-01-03 11:35:18 +01:00
GCC Administrator
f998335ac0 Daily bump. 2023-12-15 00:17:17 +00:00
Pierre-Emmanuel Patry
f37c55c14b libgrust: Add libproc_macro and build system
Add some dummy files in libproc_macro along with its build system.

libgrust/ChangeLog:

	* Makefile.am: New file.
	* Makefile.in: Generate.
	* configure.ac: New file.
	* configure: Generate.
	* aclocal.m4: Generate.
	* libproc_macro/Makefile.am: New file.
	* libproc_macro/proc_macro.cc: New file.
	* libproc_macro/proc_macro.h: New file.
	* libproc_macro/Makefile.in: Generate.

contrib/ChangeLog:

	* gcc_update: Add libgrust file dependencies.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-12-14 13:58:57 +01:00
Pierre-Emmanuel Patry
a857ec6aad libgrust: Add ChangeLog file
libgrust/ChangeLog:

	* ChangeLog: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-12-14 13:34:20 +01:00