Code Monkey home page Code Monkey logo

arm2riscv's People

Contributors

matanivgi avatar schorrm avatar tomkolan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

arm2riscv's Issues

Some types of syntaxes are not recognized

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

Barrel shifted operands sometimes crash the transpiler

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.