Skip to content

Commit

Permalink
Working towards parse_reg and parse_reg_operand
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* expand/rust-macro-builtins-asm.cc (parse_reg):
	Working towards parse_reg and parse_reg_operand
	(parse_reg_operand):
	Working towards parse_reg and parse_reg_operand
	(parse_asm_arg):
	Add todo about errors
	* expand/rust-macro-builtins-asm.h (parse_global_asm):
	remove dead code.
	(parse_nonglobal_asm):
	remove dead code.
  • Loading branch information
badumbatish committed May 29, 2024
1 parent 4dbf9af commit 347d10d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
29 changes: 20 additions & 9 deletions gcc/rust/expand/rust-macro-builtins-asm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,10 @@ parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
// InlineAsmRegOrRegClass of reg or reg class
auto token = parser.peek_current_token ();
auto tok_id = token->get_id ();

if (tok_id == IDENTIFIER)
AST::InlineAsmRegOrRegClass regClass;
if (parser.skip_token (IDENTIFIER))
{
// construct a InlineAsmRegOrRegClass
AST::InlineAsmRegOrRegClass regClass;
regClass.type = RegType::RegClass;
regClass.regClass.Symbol = token->as_string ();
}
Expand All @@ -156,18 +155,27 @@ parse_reg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,

// construct a InlineAsmRegOrRegClass
// parse_format_string
regClass.type = RegType::Reg;
inlineAsmCtx.is_explicit = true;
regClass.regClass.Symbol = token->as_string ();
}
else
{
// TODO
// TODO: This should emit error
// return
// Err(p.dcx().create_err(errors::ExpectedRegisterClassOrExplicitRegister
// {
// span: p.token.span,
// }));
}
if (!parser.skip_token (RIGHT_PAREN))
{
// we expect a left parenthesis here, please return the correct error.
// TODO: we expect a left parenthesis here, please return the correct
// error.
return tl::nullopt;
}

return tl::nullopt;
return regClass;
}

int
Expand All @@ -193,7 +201,7 @@ parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
// };

using RegisterType = AST::InlineAsmOperand::RegisterType;

AST::InlineAsmOperand reg_operand;
auto token = parser.peek_current_token ();
auto iden_token = parser.peek_current_token ();
auto &inlineAsm = inlineAsmCtx.inlineAsm;
Expand Down Expand Up @@ -221,8 +229,9 @@ parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
{}
else if (!is_global_asm && check_identifier (parser, "inlateout"))
{}
else if (false && check_identifier (parser, "const"))
else if (parser.peek_current_token ()->get_id () == CONST)
{
rust_unreachable ();
// todo: Please handle const
}
else if (false && check_identifier (parser, "sym"))
Expand All @@ -237,7 +246,7 @@ parse_reg_operand (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
{
return tl::nullopt;
}
return tl::nullopt;
return reg_operand;
}
void
check_and_set (Parser<MacroInvocLexer> &parser, InlineAsmContext &inlineAsmCtx,
Expand Down Expand Up @@ -410,6 +419,8 @@ parse_asm_arg (Parser<MacroInvocLexer> &parser, TokenId last_token_id,
}
else
{
// TODO: we consumed comma, and there happens to also be a comma
// error should be: expected expression, found `,`
break;
}

Expand Down
4 changes: 0 additions & 4 deletions gcc/rust/expand/rust-macro-builtins-asm.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ int
parse_asm_arg (Parser<MacroInvocLexer> &p, TokenId last_token_id,
InlineAsmContext &inlineAsmCtx);

tl::optional<AST::Fragment>
parse_global_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
tl::optional<AST::Fragment>
parse_nonglobal_asm (location_t invoc_locus, AST::MacroInvocData &invoc);
tl::optional<AST::Fragment>
parse_asm (location_t invoc_locus, AST::MacroInvocData &invoc,
bool is_global_asm);
Expand Down

0 comments on commit 347d10d

Please sign in to comment.