Skip to content

Commit

Permalink
Merge pull request riscv#144 from sequencer/master
Browse files Browse the repository at this point in the history
support import parse.py from other python script.
  • Loading branch information
aswaterman authored Oct 5, 2022
2 parents 86edbf4 + 95e8a3a commit 9f4d2be
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,13 @@ def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
'''
opcodes_dir = f'./'
opcodes_dir = os.path.dirname(os.path.realpath(__file__))
instr_dict = {}

# file_names contains all files to be parsed in the riscv-opcodes directory
file_names = []
for fil in file_filter:
file_names += glob.glob(f'{opcodes_dir}{fil}')
file_names += glob.glob(f'{opcodes_dir}/{fil}')
file_names.sort(reverse=True)
# first pass if for standard/regular instructions
logging.debug('Collecting standard instructions first')
Expand Down Expand Up @@ -274,21 +274,22 @@ def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
# extension, dependent instruction, the pseudo_op in question and
# its encoding
(ext, orig_inst, pseudo_inst, line) = pseudo_regex.findall(line)[0]
ext_file = f'{opcodes_dir}/{ext}'

# check if the file of the dependent extension exist. Throw error if
# it doesn't
if not os.path.exists(ext):
ext1 = f'unratified/{ext}'
if not os.path.exists(ext1):
if not os.path.exists(ext_file):
ext1_file = f'{opcodes_dir}/unratified/{ext}'
if not os.path.exists(ext1_file):
logging.error(f'Pseudo op {pseudo_inst} in {f} depends on {ext} which is not available')
raise SystemExit(1)
else:
ext = ext1
ext_file = ext1_file

# check if the dependent instruction exist in the dependent
# extension. Else throw error.
found = False
for oline in open(ext):
for oline in open(ext_file):
if not re.findall(f'^\s*{orig_inst}',oline):
continue
else:
Expand Down Expand Up @@ -338,30 +339,31 @@ def create_inst_dict(file_filter, include_pseudo=False, include_pseudo_ops=[]):
logging.debug(f' Processing line: {line}')

(import_ext, reg_instr) = imported_regex.findall(line)[0]
import_ext_file = f'{opcodes_dir}/{import_ext}'

# check if the file of the dependent extension exist. Throw error if
# it doesn't
if not os.path.exists(import_ext):
ext1 = f'unratified/{import_ext}'
if not os.path.exists(ext1):
if not os.path.exists(import_ext_file):
ext1_file = f'{opcodes_dir}/unratified/{import_ext}'
if not os.path.exists(ext1_file):
logging.error(f'Instruction {reg_instr} in {f} cannot be imported from {import_ext}')
raise SystemExit(1)
else:
ext = ext1
ext_file = ext1_file
else:
ext = import_ext
ext_file = import_ext_file

# check if the dependent instruction exist in the dependent
# extension. Else throw error.
found = False
for oline in open(ext):
for oline in open(ext_file):
if not re.findall(f'^\s*{reg_instr}',oline):
continue
else:
found = True
break
if not found:
logging.error(f'imported instruction {reg_instr} not found in {ext}. Required by {line} present in {f}')
logging.error(f'imported instruction {reg_instr} not found in {ext_file}. Required by {line} present in {f}')
logging.error(f'Note: you cannot import pseudo ops.')
raise SystemExit(1)

Expand Down

0 comments on commit 9f4d2be

Please sign in to comment.