Skip to content

Commit

Permalink
Minor tweaks to the line continuation symbol parsing.
Browse files Browse the repository at this point in the history
  • Loading branch information
sciguyryan committed Feb 1, 2024
1 parent 2ed7b1e commit 8208eb3
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions redox-core/src/parsing/asm_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const U32_REGISTERS: [RegisterId; 17] = [
/// A dummy label jump address used when handling a label.
const DUMMY_LABEL_JUMP_ADDRESS: u128 = u128::MAX;

/// The types of arguments supported by an assembly instruction.
#[derive(Debug, Clone)]
enum Argument {
/// A f64 argument.
Expand Down Expand Up @@ -137,9 +138,9 @@ impl<'a> AsmParser<'a> {

// Convert newlines into a single type and automatically
// allow lines ending with a \ to be treated as a singular line.
let sanitized = string.replace("\r\n", "\n").replace("\n\\", "");
let sanitized = string.replace("\r\n", "\n").replace("\\\n", "");

// Default to the text section, in case no sections are specied at all.
// Default to the text section, in case no sections are specified.
let mut section = FileSection::Text;

for line in sanitized.lines() {
Expand Down Expand Up @@ -376,7 +377,7 @@ impl<'a> AsmParser<'a> {
///
/// # Returns
///
/// A [`FileSection`] instance if a valid one was specified. The method will panic otherwise.
/// A [`FileSection`] instance if a valid one was specified. This method will panic otherwise.
#[inline]
fn parse_section_line(line: &str) -> FileSection {
assert!(line.len() >= 10);
Expand Down Expand Up @@ -1105,6 +1106,22 @@ mod tests_asm_parsing {
}
}

#[test]
fn code_misc_tests() {
let tests = [
ParserTest::new(
"mov EAX,\\\r\nEBX",
&[
Instruction::MovU32RegU32Reg(RegisterId::EAX, RegisterId::EBX),
],
false,
"failed to correctly parse instruction.",
),
];

ParserTests::new(&tests).run_all();
}

#[test]
fn code_parser_labels() {
let tests = [
Expand Down Expand Up @@ -1303,6 +1320,14 @@ mod tests_asm_parsing {
true,
"succeeded in parsing invalid section marker.",
),
// This is invalid because there should be a second function argument on the next line,
// which is made inline by the \ symbol.
ParserTest::new(
"mov EAX,\\\n",
&[],
true,
"succeeded in parsing invalid section marker.",
),
];

ParserTests::new(&tests).run_all();
Expand Down

0 comments on commit 8208eb3

Please sign in to comment.