schorrm / arm2riscv

Arm AArch64 to RISC-V Transpiler
MIT License
32 stars 3 forks source link

Some types of syntaxes are not recognized #4

Open kasperk81 opened 3 years ago

kasperk81 commented 3 years ago

setup:

$ cat test2.S
str x29, [x0, #(0xb0 + 0x0f0)]

# test with gcc
$ aarch64-linux-gnu-gcc -S -o - test2.S
# 1 "test2.S"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/aarch64-linux-gnu/include/stdc-predef.h" 1 3
# 32 "<command-line>" 2
# 1 "test2.S"
str x29, [x0, #(0xb0 + 0x0f0)]

first error:

$ aarch64-linux-gnu-gcc -S -o - test2.S | python3 arm2riscv.py
Traceback (most recent call last):
  File "arm2riscv.py", line 59, in <module>
    tree = l.parse(line)
  File "/usr/local/lib/python3.6/dist-packages/lark/lark.py", line 561, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
  File "/usr/local/lib/python3.6/dist-packages/lark/parser_frontends.py", line 107, in parse
    return self.parser.parse(stream, start, **kw)
  File "/usr/local/lib/python3.6/dist-packages/lark/parsers/earley.py", line 298, in parse
    to_scan = self._parse(lexer, columns, to_scan, start_symbol)
  File "/usr/local/lib/python3.6/dist-packages/lark/parsers/xearley.py", line 144, in _parse
    to_scan = scan(i, to_scan)
  File "/usr/local/lib/python3.6/dist-packages/lark/parsers/xearley.py", line 120, in scan
    considered_rules=considered_rules
lark.exceptions.UnexpectedCharacters: No terminal matches '1' in the current parser context, at line 1 col 3

# 1 "test2.S"
  ^
Expected one of: 
        * CNAME

ok so i will omit the ^# lines...

$ aarch64-linux-gnu-gcc -S -o - test2.S | grep -v '^#' | python3 arm2riscv.py 
Traceback (most recent call last):
  File "arm2riscv.py", line 59, in <module>
    tree = l.parse(line)
  File "/usr/local/lib/python3.6/dist-packages/lark/lark.py", line 561, in parse
    return self.parser.parse(text, start=start, on_error=on_error)
  File "/usr/local/lib/python3.6/dist-packages/lark/parser_frontends.py", line 107, in parse
    return self.parser.parse(stream, start, **kw)
  File "/usr/local/lib/python3.6/dist-packages/lark/parsers/earley.py", line 298, in parse
    to_scan = self._parse(lexer, columns, to_scan, start_symbol)
  File "/usr/local/lib/python3.6/dist-packages/lark/parsers/xearley.py", line 144, in _parse
    to_scan = scan(i, to_scan)
  File "/usr/local/lib/python3.6/dist-packages/lark/parsers/xearley.py", line 120, in scan
    considered_rules=considered_rules
lark.exceptions.UnexpectedCharacters: No terminal matches '(' in the current parser context, at line 1 col 16

str x29, [x0, #(0xb0 + 0x0f0)]
               ^
Expected one of: 
        * NUMBER
        * SIGNED_NUMBER
        * __ANON_1
schorrm commented 3 years ago

I am pleasantly surprised someone actually uses this enough to report an issue

schorrm commented 3 years ago

Where did that syntax come from?

kasperk81 commented 3 years ago

I was trying to convert an aarch64 assembly file to riscv64: https://github.com/libunwind/libunwind/blob/ffd0c05e8fabef6e2f41569c8d5680eaf5168749/src/aarch64/getcontext.S#L42

asm2riscv is a unique tool, when we need some quick reference to what the transpired form would look like, this repo tops the google search result. understandably, the output is not necessarily for production use, but sometimes this sort of tool helps analyzing code. :slightly_smiling_face:

ps I was hoping to find its web-based version like https://godbolt.org/ and https://sharplab.io/ and in future more source/target options