schorrm / arm2riscv Goto Github PK
View Code? Open in Web Editor NEWArm AArch64 to RISC-V Transpiler
License: MIT License
Arm AArch64 to RISC-V Transpiler
License: MIT License
Consider the following input:
.arch armv8-a
.file "bug.c"
.text
.align 2
.global main
.type main, %function
main:
add w0, w0, w0, lsl 1
ret
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0"
.section .note.GNU-stack,"",@progbits
On my machine (Ubuntu 18.04 LTS running in Docker on RHEL 7.5), the output of arm2riscv.py
for this input is distributed as follows:
55% of times - the output is okay, no errors:
.file "bug.c"
.section .tdata
REG_BANK:
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.text
.align 2
.global main
.type main, %function
main:
la s5, REG_BANK
slliw s10, a0, 1
addw a0, a0, s10
ret
.size main, .-main
.ident "GCC: (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0"
.section .note.GNU-stack,"",@progbits
23% of times - I get this error:
Traceback (most recent call last):
File "./arm2riscv.py", line 89, in <module>
buffer.append(instructions[op](op, [tmpreg, shifts['shift_reg'], shifts['shift_by']]))
File "/home/shayaviv/arm2riscv/aarch64_instructions.py", line 49, in __init__
self.specific_regs = safe_pullregs(operands)
File "/home/shayaviv/arm2riscv/instr_helpers.py", line 18, in safe_pullregs
if 'register' in o.keys():
AttributeError: 'NoneType' object has no attribute 'keys'
22% of times - I get a partial output:
.file "bug.c"
.section .tdata
REG_BANK:
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.dword 0
.text
.align 2
.global main
.type main, %function
main:
la s5, REG_BANK
followed by this error:
Traceback (most recent call last):
File "./arm2riscv.py", line 125, in <module>
line.emit_riscv()
File "/home/shayaviv/arm2riscv/aarch64_instructions.py", line 176, in emit_riscv
dest, s1, s2 = self.get_args()
ValueError: too many values to unpack (expected 3)
I suspect that the bug has something to do with the random ordering of keys in Python's dict
or set
types, but I'm only guessing.
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.