Skip to content

Commit

Permalink
Merge pull request #264 from IIITM-Jay/code-optimization
Browse files Browse the repository at this point in the history
Refactor and Optimization:: constants.py
  • Loading branch information
aswaterman authored Oct 2, 2024
2 parents 85da0d6 + 65743a0 commit 0033120
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,25 @@

imported_regex = re.compile('^\s*\$import\s*(?P<extension>.*)\s*::\s*(?P<instruction>.*)', re.M)

causes = []
with open("causes.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
for row in csv_reader:
causes.append((int(row[0], 0), row[1]))
csrs = []
with open("csrs.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
for row in csv_reader:
csrs.append((int(row[0], 0), row[1]))
csrs32 = []
with open("csrs32.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
for row in csv_reader:
csrs32.append((int(row[0], 0), row[1]))
def read_csv(filename):
"""
Reads a CSV file and returns a list of tuples.
Each tuple contains an integer value (from the first column) and a string (from the second column).
Args:
filename (str): The name of the CSV file to read.
Returns:
list of tuple: A list of (int, str) tuples extracted from the CSV file.
"""
with open(filename) as f:
csv_reader = csv.reader(f, skipinitialspace=True)
return [(int(row[0], 0), row[1]) for row in csv_reader]

causes = read_csv("causes.csv")
csrs = read_csv("csrs.csv")
csrs32 = read_csv("csrs32.csv")

arg_lut = {}
with open("arg_lut.csv") as f:
csv_reader = csv.reader(f, skipinitialspace=True)
Expand Down

0 comments on commit 0033120

Please sign in to comment.