-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a utils cli subcommand
- Loading branch information
Showing
26 changed files
with
178 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,55 @@ | ||
"""Directive handling.""" | ||
from typing import Union | ||
|
||
from .utils import parse_int, bytesify | ||
from .hardware import Memory | ||
from .utils import parse_int, bytesify, MipsException | ||
|
||
|
||
def directive_align(data: str, memory: Memory): | ||
"""Align directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
raise Exception("Unsupported directive.") | ||
"""Align directive.""" | ||
raise MipsException("Unsupported directive.") | ||
return None | ||
|
||
|
||
def directive_asciiz(data: str, memory: Memory) -> int: | ||
"""Asciiz directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
"""Asciiz directive.""" | ||
string = data[1:-1].encode("ascii", "ignore").decode("unicode_escape") | ||
address = memory.extend_data(bytesify(string, null_byte=True)) | ||
return address | ||
|
||
|
||
def directive_ascii(data: str, memory: Memory) -> int: | ||
"""Ascii directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
"""Ascii directive.""" | ||
string = data[1:-1].encode("ascii", "ignore").decode("unicode_escape") | ||
address = memory.extend_data(bytesify(string, null_byte=False)) | ||
return address | ||
|
||
|
||
def directive_byte(data: str, memory: Memory) -> int: | ||
"""Byte directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
"""Byte directive.""" | ||
value = bytesify(parse_int(data), size=1) | ||
address = memory.extend_data(value) | ||
return address | ||
|
||
|
||
def directive_half(data: str, memory: Memory) -> int: | ||
"""Half directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
"""Half directive.""" | ||
value = bytesify(parse_int(data), size=2) | ||
address = memory.extend_data(value) | ||
return address | ||
|
||
|
||
def directive_word(data: str, memory: Memory) -> int: | ||
"""Word directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
"""Word directive.""" | ||
value = bytesify(parse_int(data), size=4) | ||
address = memory.extend_data(value) | ||
return address | ||
|
||
|
||
def directive_space(data: str, memory: Memory) -> int: | ||
"""Space directive. | ||
:param name: str: | ||
:param data: str: | ||
:param memory: Memory: | ||
""" | ||
"""Space directive.""" | ||
value = parse_int(data) | ||
if value > 0x77359400: | ||
# 2 Gigabytes of space... | ||
raise Exception("Please use less memory...") | ||
raise MipsException("Please use less memory...") | ||
address = memory.extend_data(bytes([0] * value)) | ||
return address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.