diff options
Diffstat (limited to 'assembler/hasm.py')
-rwxr-xr-x | assembler/hasm.py | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/assembler/hasm.py b/assembler/hasm.py new file mode 100755 index 0000000..2eb5fc7 --- /dev/null +++ b/assembler/hasm.py @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +import os +import sys +import glob + +datadir = os.path.abspath(os.path.dirname(__file__)+"/../cpu") + +paths = glob.glob(datadir+"/instructions/*/*") + +paths.sort() + +instructions = {} + +num_instructions = 0 +for file in paths: + if os.path.isfile(file) and not os.path.basename(file).endswith("notes.txt"): + name = os.path.splitext(os.path.basename(file))[0] + try: + _ = instructions[name] + raise Exception("Instruction name conflict") + except KeyError: + pass + instructions[name] = {"path": file, "id": num_instructions} + num_instructions += 1 + +for ins in instructions: + info = instructions[ins] + f = open(info["path"], "r") + line = f.readline() + f.close() + + header, num = line.rsplit(maxsplit=1) + if header != "Number of parameters:": + print("Unable to read file "+info["path"]+": does not look like an instruction. ignoring...") + + if type(int(num)) != int: + raise Exception("Invalid number: "+num) + + info["params"] = int(num) + +print(instructions) +print(num_instructions) |