Skip to content

Commit

Permalink
Hex editor (#16)
Browse files Browse the repository at this point in the history
* Added visual command

* Fixed Dashmips Version updating

* Formatting

Co-authored-by: Joshua Mitchener <[email protected]>
  • Loading branch information
joshuamitchener and joshuamitchener authored Aug 1, 2020
1 parent fa52c22 commit e5542c0
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion dashmips/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import sys
from threading import Thread
from typing import Any, List, NoReturn
from re import findall
from pkg_resources import get_distribution

from .extension import generate_snippets, instruction_name_regex
from .plugins.vt100 import VT100
Expand All @@ -18,6 +20,19 @@ def main_compile(args: argparse.Namespace) -> int:
json.dump(program.to_dict(), args.out)
else:
print(json.dumps(program.to_dict()))
if args.visual:
hex = "[0-9A-Fa-f]"
for section in ["stack", "heap", "data"]:
memory = "".join(
[
chr(int(num, 16))
for segments in findall(
f"({hex}{hex} {hex}{hex} {hex}{hex} {hex}{hex}) <....<\n", program.to_dict()["memory"][section].replace("|", "<")
)
for num in segments.split()
]
)
print(memory, file=args.visual, end="")
return 0


Expand Down Expand Up @@ -105,7 +120,7 @@ def main() -> NoReturn:
"""Entry function for Dashmips."""
parser = argparse.ArgumentParser("dashmips")

parser.add_argument("-v", "--version", action="version", version="0.1.0")
parser.add_argument("-v", "--version", action="version", version=get_distribution("dashmips").version)

sbp = parser.add_subparsers(title="commands", dest="command")
compileparse = sbp.add_parser("compile", aliases=["c"])
Expand All @@ -116,6 +131,7 @@ def main() -> NoReturn:

compileparse.add_argument("FILE", type=argparse.FileType("r", encoding="utf8"), help="Input file")
compileparse.add_argument("-o", "--out", type=argparse.FileType("w", encoding="utf8"), help="Output file name")
compileparse.add_argument("-v", "--visual", type=argparse.FileType("w", encoding="utf8"), help="Visualize memory to file name")
compileparse.set_defaults(func=main_compile)

runparse.add_argument("FILE", type=argparse.FileType("r", encoding="utf8"), help="Input file")
Expand Down

0 comments on commit e5542c0

Please sign in to comment.