Commit Graph

60 Commits

Author SHA1 Message Date
Arthur Cohen
6fef4d6ffc gccrs: libgrust: Add format_parser library
Compile libformat_parser and link to it.

gcc/rust/ChangeLog:

	* Make-lang.in: Compile libformat_parser.
	* ast/rust-fmt.cc: New FFI definitions.
	* ast/rust-fmt.h: Likewise.
	* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler): Call
	into libformat_parser.
	* expand/rust-macro-builtins.h: Define format_args!() handler proper.

libgrust/ChangeLog:

	* libformat_parser/Cargo.lock: New file.
	* libformat_parser/Cargo.toml: New file.
	* libformat_parser/generic_format_parser/Cargo.toml: New file.
	* libformat_parser/generic_format_parser/src/lib.rs: New file.
	* libformat_parser/src/bin.rs: New file.
	* libformat_parser/src/lib.rs: New file.
2024-08-01 12:47:19 +02:00
Sahil Yeole
767698ff6c Update copyright years.
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
2024-02-21 13:51:26 +01:00
GCC Administrator
1a17797496 Daily bump. 2024-01-17 00:21:29 +00:00
Pierre-Emmanuel Patry
10699fb34a gccrs: Add an explicit value to proc macro enum kind
We'll need this value in the final binary, it should therefore be kept
explicit.

libgrust/ChangeLog:

	* libproc_macro_internal/proc_macro.h (enum ProcmacroTag): Add
	explicit value for proc macro tag enum.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:09:33 +01:00
Pierre-Emmanuel Patry
0a2219668d gccrs: Add license text to libproc_macro rust interface
The license text was missing in rust files producing the libproc_macro
interface to the libproc_macro_internal library.

libgrust/ChangeLog:

	* libproc_macro/bridge.rs: Add license text.
	* libproc_macro/bridge/ffistring.rs: Likewise.
	* libproc_macro/bridge/group.rs: Likewise.
	* libproc_macro/bridge/ident.rs: Likewise.
	* libproc_macro/bridge/literal.rs: Likewise.
	* libproc_macro/bridge/punct.rs: Likewise.
	* libproc_macro/bridge/span.rs: Likewise.
	* libproc_macro/bridge/token_stream.rs: Likewise.
	* libproc_macro/group.rs: Likewise.
	* libproc_macro/ident.rs: Likewise.
	* libproc_macro/lib.rs: Likewise.
	* libproc_macro/literal.rs: Likewise.
	* libproc_macro/punct.rs: Likewise.
	* libproc_macro/span.rs: Likewise.
	* libproc_macro/token_stream.rs: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:04:36 +01:00
Pierre-Emmanuel Patry
b1c722d141 gccrs: libproc_macro: Split c++ and rust
Move the rust interface to the libproc_macro directory.

libgrust/ChangeLog:

	* libproc_macro_internal/rust/bridge.rs: Moved to...
	* libproc_macro/bridge.rs: ...here.
	* libproc_macro_internal/rust/bridge/ffistring.rs: Moved to...
	* libproc_macro/bridge/ffistring.rs: ...here.
	* libproc_macro_internal/rust/bridge/group.rs: Moved to...
	* libproc_macro/bridge/group.rs: ...here.
	* libproc_macro_internal/rust/bridge/ident.rs: Moved to...
	* libproc_macro/bridge/ident.rs: ...here.
	* libproc_macro_internal/rust/bridge/literal.rs: Moved to...
	* libproc_macro/bridge/literal.rs: ...here.
	* libproc_macro_internal/rust/bridge/punct.rs: Moved to...
	* libproc_macro/bridge/punct.rs: ...here.
	* libproc_macro_internal/rust/bridge/span.rs: Moved to...
	* libproc_macro/bridge/span.rs: ...here.
	* libproc_macro_internal/rust/bridge/token_stream.rs: Moved to...
	* libproc_macro/bridge/token_stream.rs: ...here.
	* libproc_macro_internal/rust/group.rs: Moved to...
	* libproc_macro/group.rs: ...here.
	* libproc_macro_internal/rust/ident.rs: Moved to...
	* libproc_macro/ident.rs: ...here.
	* libproc_macro_internal/rust/lib.rs: Moved to...
	* libproc_macro/lib.rs: ...here.
	* libproc_macro_internal/rust/literal.rs: Moved to...
	* libproc_macro/literal.rs: ...here.
	* libproc_macro_internal/rust/punct.rs: Moved to...
	* libproc_macro/punct.rs: ...here.
	* libproc_macro_internal/rust/span.rs: Moved to...
	* libproc_macro/span.rs: ...here.
	* libproc_macro_internal/rust/token_stream.rs: Moved to...
	* libproc_macro/token_stream.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:04:32 +01:00
Pierre-Emmanuel Patry
fd73cf8c31 gccrs: Rename libproc_macro to libproc_macro_internal
The name was a bit misleading since libproc_macro is a rust library that
should we should be able to link against some rust code. This cpp
library was the layer below the libproc_macro library, the "real" gcc
libproc_macro act as a translation layer for the internal library.

gcc/rust/ChangeLog:

	* expand/rust-macro-expand.h: Change include directive with the
	new name.
	* expand/rust-proc-macro.h (RUST_PROC_MACRO_H): Likewise.
	* util/rust-hir-map.h: Likewise.
	* util/rust-token-converter.h: Likewise.
	* util/rust-token-converter.cc: Remove useless include
	directive.
	* Make-lang.in: Rename library.

libgrust/ChangeLog:

	* Makefile.am: Change library name.
	* Makefile.in: Likewise.
	* configure.ac: Likewise.
	* configure: Regenerate.
	* libproc_macro/Makefile.am: Moved to...
	* libproc_macro_internal/Makefile.am: ...here.
	* libproc_macro/Makefile.in: Moved to...
	* libproc_macro_internal/Makefile.in: ...here.
	* libproc_macro/bridge.h: Moved to...
	* libproc_macro_internal/bridge.h: ...here.
	* libproc_macro/ffistring.cc: Moved to...
	* libproc_macro_internal/ffistring.cc: ...here.
	* libproc_macro/ffistring.h: Moved to...
	* libproc_macro_internal/ffistring.h: ...here.
	* libproc_macro/group.cc: Moved to...
	* libproc_macro_internal/group.cc: ...here.
	* libproc_macro/group.h: Moved to...
	* libproc_macro_internal/group.h: ...here.
	* libproc_macro/ident.cc: Moved to...
	* libproc_macro_internal/ident.cc: ...here.
	* libproc_macro/ident.h: Moved to...
	* libproc_macro_internal/ident.h: ...here.
	* libproc_macro/literal.cc: Moved to...
	* libproc_macro_internal/literal.cc: ...here.
	* libproc_macro/literal.h: Moved to...
	* libproc_macro_internal/literal.h: ...here.
	* libproc_macro/proc_macro.cc: Moved to...
	* libproc_macro_internal/proc_macro.cc: ...here.
	* libproc_macro/proc_macro.h: Moved to...
	* libproc_macro_internal/proc_macro.h: ...here.
	* libproc_macro/punct.cc: Moved to...
	* libproc_macro_internal/punct.cc: ...here.
	* libproc_macro/punct.h: Moved to...
	* libproc_macro_internal/punct.h: ...here.
	* libproc_macro/registration.h: Moved to...
	* libproc_macro_internal/registration.h: ...here.
	* libproc_macro/rust/bridge.rs: Moved to...
	* libproc_macro_internal/rust/bridge.rs: ...here.
	* libproc_macro/rust/bridge/ffistring.rs: Moved to...
	* libproc_macro_internal/rust/bridge/ffistring.rs: ...here.
	* libproc_macro/rust/bridge/group.rs: Moved to...
	* libproc_macro_internal/rust/bridge/group.rs: ...here.
	* libproc_macro/rust/bridge/ident.rs: Moved to...
	* libproc_macro_internal/rust/bridge/ident.rs: ...here.
	* libproc_macro/rust/bridge/literal.rs: Moved to...
	* libproc_macro_internal/rust/bridge/literal.rs: ...here.
	* libproc_macro/rust/bridge/punct.rs: Moved to...
	* libproc_macro_internal/rust/bridge/punct.rs: ...here.
	* libproc_macro/rust/bridge/span.rs: Moved to...
	* libproc_macro_internal/rust/bridge/span.rs: ...here.
	* libproc_macro/rust/bridge/token_stream.rs: Moved to...
	* libproc_macro_internal/rust/bridge/token_stream.rs: ...here.
	* libproc_macro/rust/group.rs: Moved to...
	* libproc_macro_internal/rust/group.rs: ...here.
	* libproc_macro/rust/ident.rs: Moved to...
	* libproc_macro_internal/rust/ident.rs: ...here.
	* libproc_macro/rust/lib.rs: Moved to...
	* libproc_macro_internal/rust/lib.rs: ...here.
	* libproc_macro/rust/literal.rs: Moved to...
	* libproc_macro_internal/rust/literal.rs: ...here.
	* libproc_macro/rust/punct.rs: Moved to...
	* libproc_macro_internal/rust/punct.rs: ...here.
	* libproc_macro/rust/span.rs: Moved to...
	* libproc_macro_internal/rust/span.rs: ...here.
	* libproc_macro/rust/token_stream.rs: Moved to...
	* libproc_macro_internal/rust/token_stream.rs: ...here.
	* libproc_macro/span.cc: Moved to...
	* libproc_macro_internal/span.cc: ...here.
	* libproc_macro/span.h: Moved to...
	* libproc_macro_internal/span.h: ...here.
	* libproc_macro/tokenstream.cc: Moved to...
	* libproc_macro_internal/tokenstream.cc: ...here.
	* libproc_macro/tokenstream.h: Moved to...
	* libproc_macro_internal/tokenstream.h: ...here.
	* libproc_macro/tokentree.cc: Moved to...
	* libproc_macro_internal/tokentree.cc: ...here.
	* libproc_macro/tokentree.h: Moved to...
	* libproc_macro_internal/tokentree.h: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 19:04:31 +01:00
Pierre-Emmanuel Patry
0680907b3b gccrs: proc_macro: Add literal_from_string callback
The function to get a literal from a string missed an implementation.
It did require a conversion function to achieve it, now that callback
system has been merged this function can be easily implemented.

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (literal_from_string): Add callback
	function.
	(load_macros_array): Likewise.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal__from_string): Add
	implementation with call to constructor.
	(Literal::make_literal): Add new constructor which calls the
	callback.
	* libproc_macro/literal.h: Add new constructor's
	prototype.
	* libproc_macro/proc_macro.cc (bridge_is_available):
	Change symbol name to match convention.
	* libproc_macro/registration.h: Add lit_from_str
	symbol.
	* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
	Change symbol name to disambiguate with literal from string.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:02 +01:00
Pierre-Emmanuel Patry
6e5d6c3f0e gccrs: proc_macro: Remove useless typedef
Initially a typedef was used to easily get the callback function pointer
type. Since this type has changed to a simpler well defined type, this
using declaration has no more purpose.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc: Remove type alias.
	* libproc_macro/registration.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:01 +01:00
Pierre-Emmanuel Patry
ea0bd46eb8 gccrs: proc_macro: Delete unused prototype
This function prototype was forgotten when the function was deleted.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.h (proc_macro_register_from_str):
	Remove rogue function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:01 +01:00
Pierre-Emmanuel Patry
8db58652d8 gccrs: proc_macro: Remode function indirection
There was no need to register a function when the value could be
registered directly.

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (available): Remove function.
	(load_macros_array): There was no need for an indirection here.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (not_available): Remove
	function.
	* libproc_macro/proc_macro.h (not_available): Remove
	function prototype.
	* libproc_macro/registration.h: Change symbol type.
	* libproc_macro/bridge.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:01 +01:00
Pierre-Emmanuel Patry
ce09474789 gccrs: proc_macro: Add is_available function
Add is_available function to the C++ library.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (bridge_is_available):
	Add bridge function.
	* libproc_macro/proc_macro.h (bridge_is_available):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:01 +01:00
Pierre-Emmanuel Patry
c0763eac05 gccrs: proc_macro: Add is_available callback
Add a callback from gcc to determine wether the bridge is available or
not.

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (available): Add symbol
	registration.
	(load_macros_array): Likewise.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (not_available): Add a
	function to express bridge unavailability.
	* libproc_macro/proc_macro.h (not_available): Likewise.
	* libproc_macro/registration.h: Add symbol type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:01 +01:00
Pierre-Emmanuel Patry
b190aaeff7 gccrs: proc_macro: Rename from_string callback symbol
The symbol had a different convention from rust standard naming
convention (?) hence the change before adding new callback.

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (load_macros_array): Symbol rename.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (Procmacro::make_bang):
	Change symbol name.
	* libproc_macro/registration.h: Likewise.
	* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:56:01 +01:00
Pierre-Emmanuel Patry
973f4088ef gccrs: proc_macro: Mirror FFIString changes in C++library
Recent changes in the rust interface on some extern C function shall be
synced up in the C++ library.

libgrust/ChangeLog:

	* libproc_macro/literal.cc (Literal__from_string):
	Update to match rust interface.
	* libproc_macro/literal.h (Literal__from_string):
	Likewise.
	* libproc_macro/tokenstream.cc (TokenStream__from_string):
	Likewise.
	* libproc_macro/tokenstream.h (TokenStream__from_string):
	Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:55:59 +01:00
Pierre-Emmanuel Patry
f00f3837ef gccrs: proc_macro: Increase FFIString usage
Two remaining structures in the rust interface were still using raw
string pointer and length couples to communicate with the C++ library
throught extern C functions. Using FFIString instead allow us to reduce
the scope of potential errors using those raw pointers. As FFIString
encapsulate raw pointer operations there will be only one locaiton to
look after.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/literal.rs: Change extern C
	function argument from raw string pointer and length to
	FFIString.
	* libproc_macro/rust/bridge/token_stream.rs: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:55:59 +01:00
Pierre-Emmanuel Patry
43208b6cba gccrs: libproc_macro: Change rust Ident definition
Change rust interface Ident definition to match C++ struct definition.
This structure now uses an FFIString instead of raw pointers.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/ident.rs: Change raw
	pointer string with an FFIString.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:55:57 +01:00
Pierre-Emmanuel Patry
f7af0b90ef gccrs: libproc_macro: Change Ident structure
Use FFIString in Ident structure rather that a raw pointer and a
length, this will reduce the size of the code dealing with raw
pointers. Which should prevent some error.

gcc/rust/ChangeLog:

	* util/rust-token-converter.cc (from_ident): Adapt code to new
	constructor.

libgrust/ChangeLog:

	* libproc_macro/ident.cc (Ident__new): Constructor
	accepts an FFIString now.
	(Ident__new_raw): Likewise.
	(Ident::clone): Internal members change means clone also change.
	(Ident::make_ident): Change constructor call.
	(Ident::drop): Add call to FFIString::clone.
	* libproc_macro/ident.h (struct Ident): Remove raw
	pointer and length, add an FFIString inside instead.
	(Ident__new): Change constructor.
	(Ident__new_raw): Change constructor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:55:56 +01:00
Pierre-Emmanuel Patry
bee1255541 gccrs: proc_macro: Add from string implementation
Add a callback registration function into the proc macro library so the
compiler can register it's own lexing/parsing functions on load.

gcc/rust/ChangeLog:

	* expand/rust-proc-macro.cc (tokenstream_from_string): Add a
	function that creates a tokenstream from a given string.
	(load_macros_array): Add call to registration function.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.cc (proc_macro_register_from_str):
	Add registration function.
	* libproc_macro/proc_macro.h (proc_macro_register_from_str):
	Add registration function prototype.
	* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
	Add a new constructor from a string that uses the registered
	callback.
	(TokenStream__from_string): Add call to new constructor.
	* libproc_macro/tokenstream.h: Add registration
	declaration.
	* libproc_macro/registration.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:55:56 +01:00
Pierre-Emmanuel Patry
cf58150bea gccrs: libproc_macro: Fix Tokenstream growth
TokenStream did not copy back enough old data to the new location. This
commit also add more explicit memcpy usages in order to facilitate
change to utf-8 later.

libgrust/ChangeLog:

	* libproc_macro/ffistring.cc (FFIString::make_ffistring):
	Add explicit sizeof and utf-8 warning.
	(FFIString::clone): Add explicit sizeof and utf-8 warning.
	* libproc_macro/ident.cc (Ident::clone): Likewise.
	(Ident::make_ident): Likewise.
	* libproc_macro/tokenstream.cc (TokenStream::grow):
	Fix vector growth.
	(TokenStream__clone): Add explicit sizeof.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:46:26 +01:00
Pierre-Emmanuel Patry
22ba7ea9ee gccrs: libproc_macro: Fix capacity update in tokenstream
The capacity was not updated on tokenstream grow. This commit also add a
new mechanism to prevent a tokenstream to grow with a zero delta capacity.

libgrust/ChangeLog:

	* libproc_macro/tokenstream.cc (TokenStream::grow): Add
	minimum growing capacity.
	(TokenStream::push): Change condition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:46:26 +01:00
Pierre-Emmanuel Patry
f888077249 gccrs: libproc_macro: Rename Procmacro subtypes
Rename procedural macro specializations without the "payload" suffix.
Those types will be reused in several places where the old suffix might
be counterintuitive.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.h (struct CustomDerivePayload):
	Rename from CustomDerivePayload to...
	(struct CustomDerive): ... CustomDerive
	(struct AttrPayload): Rename from AttrPayload to ...
	(struct Attribute): ... Attribute
	(struct BangPayload): Rename from BangPayload to ...
	(struct Bang): ... Bang
	(union ProcmacroPayload): Update union with new names.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:46:25 +01:00
Pierre-Emmanuel Patry
4ca2f20300 gccrs: libproc_macro: Add procmacro array definition
Standard types do not guarantee anything about their ABI and are
therefore unconvenient to use as a primarily exposed container.
With such asumption this commit introduces a container.

libgrust/ChangeLog:

	* libproc_macro/proc_macro.h (struct ProcmacroArray):
	Add ProcmacroArray definition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:46:25 +01:00
Pierre-Emmanuel Patry
4d950fa5df gccrs: libproc_macro: Add cpp Span representation
Add Span representation in libproc_macro cpp part of the library.
Integrate spans to existing types.

gcc/rust/ChangeLog:

	* util/rust-token-converter.cc (convert): Update call to
	constructors with location information.
	(handle_suffix): Convert token locus to a Span and use it in the
	literal.

libgrust/ChangeLog:

	* libproc_macro/Makefile.am: Add span.cc
	* libproc_macro/Makefile.in: Regenerate.
	* libproc_macro/span.cc: New file.
	* libproc_macro/span.h: New file.
	* libproc_macro/group.cc (Group::make_group): Add span
	argument.
	* libproc_macro/group.h (GROUP_H): Add include
	directive for spans.
	* libproc_macro/ident.cc (Ident__new): Add span
	argument.
	(Ident__new_raw): Likewise.
	(Ident::make_ident): Likewise.
	* libproc_macro/ident.h (Ident__new): Likewise.
	(Ident__new_raw): Likewise.
	* libproc_macro/literal.cc (Literal::clone): Clone the
	span.
	(Literal::make_literal): Add span argument.
	(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.
	(Literal::make_char): Likewise.
	(Literal::make_usize): Likewise.
	(Literal::make_isize): Likewise.
	* libproc_macro/literal.h (struct Literal): Add span to
	Literal structure.
	* libproc_macro/punct.cc (Punct::make_punct): Add span
	argument to punct constructor.
	* libproc_macro/punct.h (struct Punct): Add span to
	Punct structure.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:46:23 +01:00
Pierre-Emmanuel Patry
e4b769cb0a gccrs: libproc_macro: Add Span definition
Add Span type definition in the rust interface.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/group.rs: Add span member
	to the Group structure.
	* libproc_macro/rust/bridge/ident.rs: Likewise with the
	Ident structure.
	* libproc_macro/rust/bridge/literal.rs: Likewise with
	the Literal structure.
	* libproc_macro/rust/bridge/punct.rs: Likewise with the
	Punct structure.
	* libproc_macro/rust/bridge/span.rs: Add span
	internals.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:37:23 +01:00
Pierre-Emmanuel Patry
90effeedc4 gccrs: libproc_macro: Change constructor in ffistring
The "new" constructor wasn't fitting it's usage well.

libgrust/ChangeLog:

	* libproc_macro/rust/bridge/ffistring.rs: Implement
	From trait for FFIString.
	* libproc_macro/rust/bridge/literal.rs: Change
	constructor call.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:37:20 +01:00
Pierre-Emmanuel Patry
9fc94c1562 gccrs: libproc_macro: Copy ffistring data from source
Data from source pointer were not copied correctly in the ffistring
constructor.

libgrust/ChangeLog:

	* libproc_macro/ffistring.cc (FFIString::make_ffistring):
	Add copy from source pointer.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:37:20 +01:00
Pierre-Emmanuel Patry
4689998556 gccrs: libproc_macro: Remove has_suffix attribute
This variable was redundant with the empty string representation and
may have lead to desync between both.

libgrust/ChangeLog:

	* libproc_macro/literal.h: Remove has_suffix member
	attribute from Literal.
	* libproc_macro/literal.cc: Update constructors.
	* libproc_macro/rust/bridge/literal.rs: Remove
	has_suffix attribute from Literal.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16 18:37:20 +01:00
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