diff options
| author | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-04-23 13:38:58 +0200 |
|---|---|---|
| committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2024-08-01 12:47:19 +0200 |
| commit | 6fef4d6ffcab0fec8518adcb05458cba5dbeac25 (patch) | |
| tree | bb3bdab1b69382086cc1bab294d79f60f75295c7 /libgrust/libformat_parser/src | |
| parent | 473feb033d5ccb139f8af8e0e54193b176d1cd93 (diff) | |
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.
Diffstat (limited to 'libgrust/libformat_parser/src')
| -rw-r--r-- | libgrust/libformat_parser/src/bin.rs | 7 | ||||
| -rw-r--r-- | libgrust/libformat_parser/src/lib.rs | 41 |
2 files changed, 48 insertions, 0 deletions
diff --git a/libgrust/libformat_parser/src/bin.rs b/libgrust/libformat_parser/src/bin.rs new file mode 100644 index 00000000000..4b1f903ad5f --- /dev/null +++ b/libgrust/libformat_parser/src/bin.rs @@ -0,0 +1,7 @@ +use libformat_parser::rust; + +fn main() { + dbg!(rust::collect_pieces( + std::env::args().nth(1).unwrap().as_str() + )); +} diff --git a/libgrust/libformat_parser/src/lib.rs b/libgrust/libformat_parser/src/lib.rs new file mode 100644 index 00000000000..e6dc16eeb49 --- /dev/null +++ b/libgrust/libformat_parser/src/lib.rs @@ -0,0 +1,41 @@ +//! FFI interface for `rustc_format_parser` + +// what's the plan? Have a function return something that can be constructed into a vector? +// or an iterator? + +use std::ffi::CStr; + +// TODO: Use rustc's version here #3 +use generic_format_parser::Piece; + +// FIXME: Rename? +pub mod rust { + use generic_format_parser::{ParseMode, Parser, Piece}; + + pub fn collect_pieces(input: &str) -> Vec<Piece<'_>> { + // let parser = Parser::new(); + let parser = Parser::new(input, None, None, true, ParseMode::Format); + + parser.into_iter().collect() + } +} + +#[repr(C)] +pub struct PieceSlice { + base_ptr: *const Piece<'static /* FIXME: That's wrong */>, + len: usize, +} + +#[no_mangle] +pub extern "C" fn collect_pieces(input: *const libc::c_char) -> PieceSlice { + // FIXME: Add comment + let str = unsafe { CStr::from_ptr(input) }; + + // FIXME: No unwrap + let pieces = rust::collect_pieces(str.to_str().unwrap()); + + PieceSlice { + base_ptr: pieces.as_ptr(), + len: pieces.len(), + } +} |
