Skip to content

Commit

Permalink
make mnemonics case-insensitive
Browse files Browse the repository at this point in the history
  • Loading branch information
hlorenzi committed Mar 28, 2018
1 parent 82b36d3 commit b205898
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 35 deletions.
5 changes: 3 additions & 2 deletions src/asm/cpudef/rule_pattern_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl RulePatternMatcher
{
RulePatternPart::Exact(kind, ref excerpt) =>
{
let step_kind = MatchStepExact(kind, excerpt.clone());
let step_kind = MatchStepExact(kind, excerpt.as_ref().map(|s| s.to_ascii_lowercase()));

if let Some(next_step) = step.children_exact.get_mut(&step_kind)
{
Expand Down Expand Up @@ -126,7 +126,8 @@ impl RulePatternMatcher
let parser_state = parser.save();

let tk = parser.advance();
let step_exact = MatchStepExact(tk.kind, tk.excerpt);

let step_exact = MatchStepExact(tk.kind, tk.excerpt.map(|s| s.to_ascii_lowercase()));

if let Some(next_step) = step.children_exact.get(&step_exact)
{
Expand Down
43 changes: 10 additions & 33 deletions src/test/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ fn test_simple()
test("halt -> 8'0", "halt \n unknown", Fail(("asm", 2, "no match")));

test("halt -> 8'0", "#unknown \n halt", Fail(("asm", 1, "unknown")));

test("halt -> 8'0", "HALT", Pass((4, "00")));
test("HALT -> 8'0", "halt", Pass((4, "00")));
test("Halt -> 8'0", "hALT", Pass((4, "00")));
test("hALT -> 8'0", "Halt", Pass((4, "00")));
}


Expand Down Expand Up @@ -147,39 +152,6 @@ fn test_addr_directive()
}


/*#[test]
fn test_outp_directive()
{
test("halt -> 8'0x12", " halt", Pass((4, "12")));
test("halt -> 8'0x12", "#outp 0x00 \n halt", Pass((4, "12")));
test("halt -> 8'0x12", "#outp 0x01 \n halt", Pass((4, "0012")));
test("halt -> 8'0x12", "#outp 0x02 \n halt", Pass((4, "000012")));
test("halt -> 8'0x12", "#outp 0x10 \n halt", Pass((4, "0000000000000000000000000000000012")));
test("halt -> 8'0x12 @ pc[7:0]", " halt", Pass((4, "1200")));
test("halt -> 8'0x12 @ pc[7:0]", "#outp 0x00 \n halt", Pass((4, "1200")));
test("halt -> 8'0x12 @ pc[7:0]", "#outp 0x01 \n halt", Pass((4, "001200")));
test("halt -> 8'0x12 @ pc[7:0]", "#outp 0x02 \n halt", Pass((4, "00001200")));
test("halt -> 8'0x12 @ pc[7:0]", "#outp 0x10 \n halt", Pass((4, "000000000000000000000000000000001200")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0x45 \n #outp 0x00 \n halt", Pass((4, "1245")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0x77 \n #outp 0x01 \n halt", Pass((4, "001277")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0x93 \n #outp 0x02 \n halt", Pass((4, "00001293")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0xbf \n #outp 0x10 \n halt", Pass((4, "0000000000000000000000000000000012bf")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0x45 \n #outp 0x00 \n halt \n halt \n halt", Pass((4, "124512471249")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0x77 \n #outp 0x01 \n halt \n halt \n halt", Pass((4, "0012771279127b")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0x93 \n #outp 0x02 \n halt \n halt \n halt", Pass((4, "0000129312951297")));
test("halt -> 8'0x12 @ pc[7:0]", "#addr 0xbf \n #outp 0x10 \n halt \n halt \n halt", Pass((4, "0000000000000000000000000000000012bf12c112c3")));
test("halt -> 8'0x12 @ pc[7:0]", "#outp 0x00 \n halt \n halt \n #outp 0x10 \n halt \n halt", Pass((4, "1200120200000000000000000000000012041206")));
test("halt -> 8'0x12", "#outp 0xffff_ffff_ffff_ffff / 8", Pass((4, "")));
test("halt -> 8'0x12", "#outp 0x1_0000_0000_0000_0000 / 8", Fail(("asm", 1, "valid range")));
test("halt -> 8'0x12", "#outp 0x1_0000_0000_0000_0000 \n halt", Fail(("asm", 1, "large")));
}*/


#[test]
fn test_res_directive()
{
Expand Down Expand Up @@ -355,6 +327,11 @@ fn test_labels()

test(INSTRSET, " label: halt \n label: halt", Fail(("asm", 2, "duplicate")));
test(INSTRSET, ".label: halt \n .label: halt", Fail(("asm", 2, "duplicate")));

test(INSTRSET, "label: halt \n jump LABEL", Fail(("asm", 2, "unknown")));
test(INSTRSET, "LABEL: halt \n jump label", Fail(("asm", 2, "unknown")));
test(INSTRSET, "myVar: halt \n jump myvar", Fail(("asm", 2, "unknown")));
test(INSTRSET, "myvar: halt \n jump myVar", Fail(("asm", 2, "unknown")));
}


Expand Down

0 comments on commit b205898

Please sign in to comment.