Skip to content

Commit

Permalink
Hexmode fixed, SB instructions fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kcelebi committed Apr 10, 2023
1 parent 3024e69 commit 1e20a0f
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 8 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[![kcelebi](https://circleci.com/gh/kcelebi/riscv-assembler.svg?style=svg)](https://circleci.com/gh/kcelebi/riscv-assembler)
[![Gitter](https://badges.gitter.im/riscv-assembler/community.svg)](https://gitter.im/riscv-assembler/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

![example](references/mdimg.png)
Expand Down
3 changes: 1 addition & 2 deletions src/riscv_assembler/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,5 +161,4 @@ def apply_nibble(output : list) -> list:

@staticmethod
def apply_hex(output : list) -> list:
raise NotImplementedError()
return ...
return ['0x' + '{:08X}'.format(int(elem, 2)).lower() for elem in output]
12 changes: 11 additions & 1 deletion src/riscv_assembler/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ def handle_inline_comments(x : str) -> str:
if "#" in x:
pos = x.index("#")
if pos != 0 and pos != len(x)-1:
return x[0:pos]
return x[0:pos].replace(',', ' ')
return x.replace(',', ' ')

@staticmethod
def handle_specific_instr(x : list) -> list:
# for sw, lw, lb, lh, sb, sh
if len(x[0]) == 2 and (x[0] in S_instr or x[0] in I_instr):
y = x[-1].split('('); y[1] = y[1].replace(')','')
return x[0:-1] + y

return x

'''
Expand All @@ -73,6 +82,7 @@ def tokenize(line : str) -> list:
line = line.strip()
if len(line) > 0 and _Parser.valid_line(line, True):
tokens = _Parser.handle_inline_comments(line).split()
tokens = _Parser.handle_specific_instr(tokens)
return tokens
return []

Expand Down
Binary file modified tests/__pycache__/__init__.cpython-38.pyc
Binary file not shown.
Binary file modified tests/__pycache__/test_class.cpython-38-pytest-7.2.2.pyc
Binary file not shown.
29 changes: 25 additions & 4 deletions tests/test_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,20 @@ def func11():

return tokens

def func12():
cnv = AC(hex_mode = True, output_mode='a')

path = str(Path(__file__).parent / "assembly/test2.s")

return cnv(path)

def func13():
cnv = AC(hex_mode = True, output_mode='a')

path = str(Path(__file__).parent / "assembly/test3.s")

return cnv(path)

#-----------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------
Expand All @@ -118,11 +132,11 @@ def test_5():
def test_6():
assert func6() == ['p', True, True], "Test 6 Failed"

'''def test_7():
assert func7() == 4
#def test_7():
# assert func7() == 4

def test_8():
assert func8() == ['0x000000b3', '0x02040293'], "Test 8 Failed"'''''
assert func8() == ['0x000000b3', '0x02040293'], "Test 8 Failed"

def test_9():
assert func9() == ['add', 'x0', 'x0', 'x1'], "Test 9 Failed"
Expand All @@ -131,4 +145,11 @@ def test_10():
assert func10() == 'R Parser', "Test 10 Failed"

def test_11():
assert func11() == []
assert func11() == []

# Test file test2.s, need to implement JUMP
#def test_12():
# assert func12() == ['0x00a00413', '0x00a00493', '0x00848263', '0xfe040493']

def test_13():
assert func13() == ['0x00812023']

0 comments on commit 1e20a0f

Please sign in to comment.