Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put main code in a function #291

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def process_enc_line(line, ext):
existing_arg, new_arg = parts
if existing_arg in arg_lut:
arg_lut[a] = arg_lut[existing_arg]

else:
logging.error(f' Found field {existing_arg} in variable {a} in instruction {name} whose mapping in arg_lut does not exist')
raise SystemExit(1)
Expand Down Expand Up @@ -1027,7 +1027,7 @@ def make_go(instr_dict):
instr_str += f''' case A{i.upper().replace("_","")}:
return &inst{{ {hex(opcode)}, {hex(funct3)}, {hex(rs1)}, {hex(rs2)}, {signed(csr,12)}, {hex(funct7)} }}
'''

with open('inst.go','w') as file:
file.write(prelude)
file.write(instr_str)
Expand All @@ -1046,7 +1046,7 @@ def signed(value, width):
return value - (1<<width)


if __name__ == "__main__":
def main():
Copy link
Member

@IIITM-Jay IIITM-Jay Oct 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aswaterman yes, we can do this change as I have already did that in Refactored parse.py file in my PR ( a longer one). So yeah, this could be accepted (but I have already done in my PR) .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's close this PR and handle this as part of merging your PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@IIITM-Jay which PR are you referring to? I can't find one that does this.

Copy link
Member

@IIITM-Jay IIITM-Jay Oct 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Timmmm I have revised the PR #283 with mentioning in comments, about only to consider that PR with pure intention to refactor and optimize the parser logic with modular approach to enhance maintainability and readability keeping the best practices and standards.

Will include this thing as I proceed further refactoring other scripts which are dedicated to generate the corresponding artifacts such as encoding.out.h, instr-table.tex etc.
I have in mind to include the changes w.r.t main method inclusion.

print(f'Running with args : {sys.argv}')

extensions = sys.argv[1:]
Expand All @@ -1066,7 +1066,7 @@ def signed(value, width):
instr_dict = collections.OrderedDict(sorted(instr_dict.items()))

if '-c' in sys.argv[1:]:
instr_dict_c = create_inst_dict(extensions, False,
instr_dict_c = create_inst_dict(extensions, False,
include_pseudo_ops=emitted_pseudo_ops)
instr_dict_c = collections.OrderedDict(sorted(instr_dict_c.items()))
make_c(instr_dict_c)
Expand Down Expand Up @@ -1097,3 +1097,7 @@ def signed(value, width):
logging.info('instr-table.tex generated successfully')
make_priv_latex_table()
logging.info('priv-instr-table.tex generated successfully')


if __name__ == "__main__":
main()