hlorenzi / customasm

💻 An assembler for custom, user-defined instruction sets! https://hlorenzi.github.io/customasm/web/
Apache License 2.0
720 stars 56 forks source link

`slice index starts at 2 but ends at 1` when implementing AT&T memory access syntax #88

Closed clubby789 closed 3 years ago

clubby789 commented 3 years ago
#subruledef reg {
    ax => 0x0;
    bx => 0x1;
    cx => 0x2;
}

#subruledef memaccess {
    {o: s8}(%{r: reg}) => 0x00 @ r @ o;
}

#subruledef arg {
    {m: memaccess} => 0x00 @ m;
    %{r: reg} => 0x01 @ r;
}

#ruledef {
    mov {a: arg}, {a2: arg} => 0x10 @ a @ a2;
}

mov (%ax), %bx

Backtrace:

customasm v0.11.9 (2021-05-09, x86_64-unknown-linux-gnu)
assembling `test.S`...
thread 'main' panicked at 'slice index starts at 2 but ends at 1', src/syntax/parser.rs:138:43
stack backtrace:
   0:     0x561361c366a0 - std::backtrace_rs::backtrace::libunwind::trace::h25e12e0d899beba0
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/../../backtrace/src/backtrace/libunwind.rs:90:5
   1:     0x561361c366a0 - std::backtrace_rs::backtrace::trace_unsynchronized::h70e61195d6ae3df6
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x561361c366a0 - std::sys_common::backtrace::_print_fmt::hba93ab80d779695a
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:67:5
   3:     0x561361c366a0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf092b5883b4b2e50
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:46:22
   4:     0x561361c4dc8c - core::fmt::write::hf68bc350a8f2f0dc
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/fmt/mod.rs:1078:17
   5:     0x561361c33c72 - std::io::Write::write_fmt::hf66811b1bc767436
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/io/mod.rs:1517:15
   6:     0x561361c38425 - std::sys_common::backtrace::_print::hd425a11bfe1f20f8
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:49:5
   7:     0x561361c38425 - std::sys_common::backtrace::print::h6d678795c1e61e13
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:36:9
   8:     0x561361c38425 - std::panicking::default_hook::{{closure}}::h78a02a4a0dee5e7e
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:208:50
   9:     0x561361c37f7a - std::panicking::default_hook::h56eb7eda02f355a7
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:225:9
  10:     0x561361c38bc1 - std::panicking::rust_panic_with_hook::hb27ea14285131c61
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:591:17
  11:     0x561361c38707 - std::panicking::begin_panic_handler::{{closure}}::hc552fcee62aad17f
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:497:13
  12:     0x561361c36b5c - std::sys_common::backtrace::__rust_end_short_backtrace::hb9f0aa9a78e885a0
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:141:18
  13:     0x561361c38669 - rust_begin_unwind
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:493:5
  14:     0x561361c4d061 - core::panicking::panic_fmt::h12ac4570ea43d06f
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/panicking.rs:92:14
  15:     0x561361c4f4c2 - core::slice::index::slice_index_order_fail::h63fbbda415970cce
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/slice/index.rs:48:5
  16:     0x561361b47345 - <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index::haeae9b67c2491b31
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/slice/index.rs:236:13
  17:     0x561361b2c708 - core::slice::index::<impl core::ops::index::Index<I> for [T]>::index::h8cd005d69286b2f8
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/slice/index.rs:15:9
  18:     0x561361ba47f9 - customasm::syntax::parser::Parser::clone_slice::h3ef2ab0dde3a54d2
                               at /opt/customasm/src/syntax/parser.rs:138:37
  19:     0x561361ba5132 - customasm::syntax::parser::Parser::slice_until_char_or_nesting::hc1291fb28af59f17
                               at /opt/customasm/src/syntax/parser.rs:297:9
  20:     0x561361b88fb8 - customasm::asm::parser::rule_invocation::match_rule::h7614b3ea14f752d4
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:326:65
  21:     0x561361b88096 - customasm::asm::parser::rule_invocation::match_ruleset::h6e2df5bdbe5f4209
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:186:36
  22:     0x561361b893df - customasm::asm::parser::rule_invocation::match_rule::h7614b3ea14f752d4
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:377:49
  23:     0x561361b88096 - customasm::asm::parser::rule_invocation::match_ruleset::h6e2df5bdbe5f4209
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:186:36
  24:     0x561361b893df - customasm::asm::parser::rule_invocation::match_rule::h7614b3ea14f752d4
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:377:49
  25:     0x561361b88096 - customasm::asm::parser::rule_invocation::match_ruleset::h6e2df5bdbe5f4209
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:186:36
  26:     0x561361b877cb - customasm::asm::parser::rule_invocation::match_active_rulesets::h393f797d8ab4010a
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:142:36
  27:     0x561361b86bad - customasm::asm::parser::rule_invocation::match_rule_invocation::h7316419bd1573467
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:50:26
  28:     0x561361b866c6 - customasm::asm::parser::rule_invocation::parse_rule_invocation::h54c116f091e20279
                               at /opt/customasm/src/asm/parser/rule_invocation.rs:15:29
  29:     0x561361b8fe63 - customasm::asm::parser::file::parse_line::he219040780a3430c
                               at /opt/customasm/src/asm/parser/file.rs:69:9
  30:     0x561361b7cef2 - customasm::asm::parser::file::parse_file::h12b9a3b880500628
                               at /opt/customasm/src/asm/parser/file.rs:34:9
  31:     0x561361b70279 - customasm::asm::state::Assembler::assemble::hf496ee445f3811f4
                               at /opt/customasm/src/asm/state.rs:115:18
  32:     0x561361b4e6e5 - customasm::driver::drive_inner::h765269abcdd0a7cd
                               at /opt/customasm/src/driver.rs:190:15
  33:     0x561361b4d244 - customasm::driver::drive::hcee602fa090a2613
                               at /opt/customasm/src/driver.rs:38:15
  34:     0x561361b25cd3 - customasm::main::h380b979316259b74
                               at /opt/customasm/src/main.rs:10:19
  35:     0x561361b24c7b - core::ops::function::FnOnce::call_once::hf43bcfa38dfb92c3
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/ops/function.rs:227:5
  36:     0x561361b241de - std::sys_common::backtrace::__rust_begin_short_backtrace::h9731a1e124ac7876
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/sys_common/backtrace.rs:125:18
  37:     0x561361b25c71 - std::rt::lang_start::{{closure}}::he880318b57b39099
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/rt.rs:66:18
  38:     0x561361c38fe7 - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h78040f802d89ccdc
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/core/src/ops/function.rs:259:13
  39:     0x561361c38fe7 - std::panicking::try::do_call::h6853cad536dd09a1
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:379:40
  40:     0x561361c38fe7 - std::panicking::try::h827495f03a9fbb9a
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panicking.rs:343:19
  41:     0x561361c38fe7 - std::panic::catch_unwind::h4bdf17571090eb17
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/panic.rs:396:14
  42:     0x561361c38fe7 - std::rt::lang_start_internal::h2f319c33bb013f29
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/rt.rs:51:25
  43:     0x561361b25c47 - std::rt::lang_start::hdd19fe7c7b925bbf
                               at /rustc/cb75ad5db02783e8b0222fee363c5f63f7e2cf5b/library/std/src/rt.rs:65:5
  44:     0x561361b25d6a - main
  45:     0x7fa543029d0a - __libc_start_main
  46:     0x561361b240ba - _start
  47:                0x0 - <unknown>

Using the latest commit (a1e41944a62b882400e471308018d1faf3283be6)

hlorenzi commented 3 years ago

I've fixed this in the latest commit! But you'll now get a no match found error on your example. I think the pattern {o: s8}(%{r: reg}) looks a bit weird; I don't know whether that's what you were really going for.