Skip to content

Commit 1e20a0f

Browse files
committed
Hexmode fixed, SB instructions fixed
1 parent 3024e69 commit 1e20a0f

File tree

6 files changed

+37
-8
lines changed

6 files changed

+37
-8
lines changed

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
[![kcelebi](https://circleci.com/gh/kcelebi/riscv-assembler.svg?style=svg)](https://circleci.com/gh/kcelebi/riscv-assembler)
2-
[![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)
32
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
43

54
![example](references/mdimg.png)

src/riscv_assembler/convert.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,5 +161,4 @@ def apply_nibble(output : list) -> list:
161161

162162
@staticmethod
163163
def apply_hex(output : list) -> list:
164-
raise NotImplementedError()
165-
return ...
164+
return ['0x' + '{:08X}'.format(int(elem, 2)).lower() for elem in output]

src/riscv_assembler/parse.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,16 @@ def handle_inline_comments(x : str) -> str:
4747
if "#" in x:
4848
pos = x.index("#")
4949
if pos != 0 and pos != len(x)-1:
50-
return x[0:pos]
50+
return x[0:pos].replace(',', ' ')
51+
return x.replace(',', ' ')
52+
53+
@staticmethod
54+
def handle_specific_instr(x : list) -> list:
55+
# for sw, lw, lb, lh, sb, sh
56+
if len(x[0]) == 2 and (x[0] in S_instr or x[0] in I_instr):
57+
y = x[-1].split('('); y[1] = y[1].replace(')','')
58+
return x[0:-1] + y
59+
5160
return x
5261

5362
'''
@@ -73,6 +82,7 @@ def tokenize(line : str) -> list:
7382
line = line.strip()
7483
if len(line) > 0 and _Parser.valid_line(line, True):
7584
tokens = _Parser.handle_inline_comments(line).split()
85+
tokens = _Parser.handle_specific_instr(tokens)
7686
return tokens
7787
return []
7888

0 Bytes
Binary file not shown.
Binary file not shown.

tests/test_class.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ def func11():
9595

9696
return tokens
9797

98+
def func12():
99+
cnv = AC(hex_mode = True, output_mode='a')
100+
101+
path = str(Path(__file__).parent / "assembly/test2.s")
102+
103+
return cnv(path)
104+
105+
def func13():
106+
cnv = AC(hex_mode = True, output_mode='a')
107+
108+
path = str(Path(__file__).parent / "assembly/test3.s")
109+
110+
return cnv(path)
111+
98112
#-----------------------------------------------------------------------------------------
99113
#-----------------------------------------------------------------------------------------
100114
#-----------------------------------------------------------------------------------------
@@ -118,11 +132,11 @@ def test_5():
118132
def test_6():
119133
assert func6() == ['p', True, True], "Test 6 Failed"
120134

121-
'''def test_7():
122-
assert func7() == 4
135+
#def test_7():
136+
# assert func7() == 4
123137

124138
def test_8():
125-
assert func8() == ['0x000000b3', '0x02040293'], "Test 8 Failed"'''''
139+
assert func8() == ['0x000000b3', '0x02040293'], "Test 8 Failed"
126140

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

133147
def test_11():
134-
assert func11() == []
148+
assert func11() == []
149+
150+
# Test file test2.s, need to implement JUMP
151+
#def test_12():
152+
# assert func12() == ['0x00a00413', '0x00a00493', '0x00848263', '0xfe040493']
153+
154+
def test_13():
155+
assert func13() == ['0x00812023']

0 commit comments

Comments
 (0)