Cleanup lint warnings in CacheSim.py

This commit is contained in:
Jordan Carlin 2024-12-11 22:42:51 -08:00
parent bc2a0d2714
commit 71168e5a97
No known key found for this signature in database

View File

@ -44,6 +44,7 @@
import math
import argparse
import os
import sys
class CacheLine:
def __init__(self):
@ -72,7 +73,7 @@ class Cache:
self.ways = []
for i in range(numways):
self.ways.append([])
for j in range(numsets):
for _ in range(numsets):
self.ways[i].append(CacheLine())
self.pLRU = []
@ -92,7 +93,8 @@ class Cache:
line = self.ways[waynum][setnum]
if line.tag == tag and line.valid:
line.dirty = 0
if invalidate: line.valid = 0
if invalidate:
line.valid = 0
# invalidates the cache by setting all valid bits to False
def invalidate(self):
@ -103,7 +105,7 @@ class Cache:
# resets the pLRU to a fresh 2-D array of 0s
def clear_pLRU(self):
self.pLRU = []
for i in range(self.numsets):
for _ in range(self.numsets):
self.pLRU.append([0]*(self.numways-1))
# splits the given address into tag, set, and offset
@ -158,7 +160,7 @@ class Cache:
tree = self.pLRU[setnum]
bottomrow = (self.numways - 1)//2
index = (waynum // 2) + bottomrow
tree[index] = int(not (waynum % 2))
tree[index] = int(not waynum % 2)
while index > 0:
parent = (index-1) // 2
tree[parent] = index % 2
@ -201,7 +203,7 @@ class Cache:
return self.__str__()
def main():
def parseArgs():
parser = argparse.ArgumentParser(description="Simulates a L1 cache.")
parser.add_argument('numlines', type=int, help="The number of lines per way (a power of 2)", metavar="L")
parser.add_argument('numways', type=int, help="The number of ways (a power of 2)", metavar='W')
@ -211,8 +213,9 @@ def main():
parser.add_argument('-v', "--verbose", action='store_true', help="verbose/full-trace mode")
parser.add_argument('-p', "--perf", action='store_true', help="Report hit/miss ratio")
parser.add_argument('-d', "--dist", action='store_true', help="Report distribution of operations")
return parser.parse_args()
args = parser.parse_args()
def main(args):
cache = Cache(args.numlines, args.numways, args.addrlen, args.taglen)
extfile = os.path.expanduser(args.file)
mismatches = 0
@ -227,7 +230,7 @@ def main():
atoms = 0
totalops = 0
with open(extfile, "r") as f:
with open(extfile, "r", encoding="utf-8") as f:
for ln in f:
ln = ln.strip()
lninfo = ln.split()
@ -257,7 +260,7 @@ def main():
IsCBOClean = lninfo[1] != 'C'
cache.cbo(addr, IsCBOClean)
if args.verbose:
print(lninfo[1]);
print(lninfo[1])
else:
addr = int(lninfo[0], 16)
iswrite = lninfo[1] == 'W' or lninfo[1] == 'A' or lninfo[1] == 'Z'
@ -299,4 +302,5 @@ def main():
return mismatches
if __name__ == '__main__':
exit(main())
args = parseArgs()
sys.exit(main(args))