diff options
author | badumbatish <tanghocle456@gmail.com> | 2024-07-26 20:26:01 -0700 |
---|---|---|
committer | CohenArthur <arthur.cohen@embecosm.com> | 2024-09-02 09:44:55 +0000 |
commit | 596bf6946d85bf9b41d1b5479e661111750927a3 (patch) | |
tree | fd9911da51bd8a2bfc61492435f715edb79b3045 /gcc/rust/expand/rust-macro-builtins-asm.cc | |
parent | 8d157b63670d1efe4a664b7da14b6908bbd11689 (diff) | |
download | gcc-596bf6946d85bf9b41d1b5479e661111750927a3.zip gcc-596bf6946d85bf9b41d1b5479e661111750927a3.tar.gz gcc-596bf6946d85bf9b41d1b5479e661111750927a3.tar.bz2 |
Move strip double quotes, add scaffold expand
gcc/rust/ChangeLog:
* backend/rust-compile-asm.cc (strip_double_quotes):
Move strip double quotes to parse phase
(CompileAsm::asm_construct_string_tree): Likewise
* backend/rust-compile-asm.h (strip_double_quotes): Likewise
* expand/rust-macro-builtins-asm.cc (strip_double_quotes):
Likewise
(expand_inline_asm): Renamed to expand_inline_asm_strings
(expand_inline_asm_strings): Renamed from expand_inline_asm
(parse_asm): Move strip double quotes to parse phase
(parse_format_strings): Likewise
* expand/rust-macro-builtins-asm.h (strip_double_quotes):
Likewise
(expand_inline_asm_strings): Inline asm expansion fn
(expand_inline_asm_string): Inline asm expansion fn
Diffstat (limited to 'gcc/rust/expand/rust-macro-builtins-asm.cc')
-rw-r--r-- | gcc/rust/expand/rust-macro-builtins-asm.cc | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/gcc/rust/expand/rust-macro-builtins-asm.cc b/gcc/rust/expand/rust-macro-builtins-asm.cc index d3cfbd8..dcc2a3d 100644 --- a/gcc/rust/expand/rust-macro-builtins-asm.cc +++ b/gcc/rust/expand/rust-macro-builtins-asm.cc @@ -742,26 +742,42 @@ parse_asm_arg (InlineAsmContext inline_asm_ctx) return tl::expected<InlineAsmContext, InlineAsmParseError> (inline_asm_ctx); } +std::string +strip_double_quotes (const std::string &str) +{ + // Helper function strips the beginning and ending double quotes from a + // string. + std::string result = str; + + rust_assert (result.size () >= 3); + result.erase (0, 1); + result.erase (result.size () - 1, 1); + return result; +} + tl::expected<InlineAsmContext, InlineAsmParseError> -expand_inline_asm (InlineAsmContext &inline_asm_ctx) +expand_inline_asm_strings (InlineAsmContext &inline_asm_ctx) { auto &inline_asm = inline_asm_ctx.inline_asm; auto str_vec = inline_asm.get_template_strs (); for (auto &template_str : str_vec) { - std::cout << template_str.symbol << std::endl; + /*std::cout << template_str.symbol << std::endl;*/ auto pieces = Fmt::Pieces::collect (template_str.symbol, false, - Fmt::ffi::ParseMode::Format) - .get_pieces (); + Fmt::ffi::ParseMode::InlineAsm); + auto pieces_vec = pieces.get_pieces (); - for (size_t i = 0; i < pieces.size (); i++) + for (size_t i = 0; i < pieces_vec.size (); i++) { - auto piece = pieces[i]; + auto piece = pieces_vec[i]; if (piece.tag == Fmt::ffi::Piece::Tag::String) - std::cout << " " << i << ": " << piece.string._0.to_string () - << std::endl; + { + } + /*std::cout << " " << i << ": " << piece.string._0.to_string + * ()*/ + /* << std::endl;*/ } } @@ -798,7 +814,7 @@ parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc, auto is_valid = (bool) resulting_context; if (is_valid) { - expand_inline_asm (resulting_context.value ()); + expand_inline_asm_strings (*resulting_context); } if (is_valid) { @@ -846,7 +862,8 @@ parse_format_strings (InlineAsmContext inline_asm_ctx) else { auto template_str - = AST::TupleTemplateStr (token->get_locus (), fm_string.value ()); + = AST::TupleTemplateStr (token->get_locus (), + strip_double_quotes (fm_string.value ())); inline_asm.template_strs.push_back (template_str); } @@ -872,7 +889,8 @@ parse_format_strings (InlineAsmContext inline_asm_ctx) else { auto template_str - = AST::TupleTemplateStr (token->get_locus (), fm_string.value ()); + = AST::TupleTemplateStr (token->get_locus (), + strip_double_quotes (fm_string.value ())); inline_asm.template_strs.push_back (template_str); } } |