Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. from sys import argv
  2. #============================================================================#
  3. # FONCTIONS #
  4. #============================================================================#
  5.  
  6. #cache_slots = 8
  7. tableau = 8
  8. class txtError(Exception):
  9. def __init__(self, value):
  10. self.value = value
  11. def __str__(self):
  12. return repr(self.value)
  13.  
  14.  
  15. #----------------------------------------------------------------------------#
  16. def ouverture_fichier(filename, M, L1Addr, L1Data, L1Dirt, LastUse, compteur = 1):
  17. """
  18. Description:
  19. """
  20. fichier = open(filename, "r")
  21. liste = fichier.readlines()
  22. for i in range(len(liste)):
  23. ligne = liste[i].strip()
  24. ligne = ligne.split()
  25. if ligne[0] == "R":
  26. compteur=lecture(int(ligne[1]), M, L1Addr, L1Data, L1Dirt, LastUse, compteur)
  27.  
  28. elif ligne[0] == "W":
  29. compteur= ecriture(int(ligne[1]),int(ligne[2]), M, L1Addr, L1Data, L1Dirt, LastUse, compteur)
  30.  
  31. print(ligne)
  32. print(M)
  33. print(L1Addr)
  34. print(L1Data)
  35.  
  36. fichier.close()
  37.  
  38. #----------------------------------------------------------------------------#
  39. def lecture(i , M, L1Addr, L1Data, L1Dirt, LastUse, compteur):
  40. """
  41. Description:
  42. """
  43. res = False
  44. for j in range(len(L1Addr)):
  45. if L1Addr[j] == i:
  46. res = L1Data[j]
  47. if not res:
  48. v = M[i]
  49. k = choix_victime(LastUse)
  50. LastUse[j] = compteur
  51. if L1Dirt[k]:
  52. M[L1Addr[k]] = L1Data[k]
  53. #print("WR"+ str(k)+ "to" + str(v) +"\t miss: vitime"+ + "(LU"+ compteur+")")
  54. L1Addr[k] = i
  55. L1Data[k] = v
  56. L1Dirt[k] = False
  57. compteur += 1
  58. return res, compteur
  59. #----------------------------------------------------------------------------#
  60. def ecriture(v , i, M, L1Addr, L1Data, L1Dirt, LastUse, compteur):
  61. """
  62. Description:
  63. """
  64. res = False
  65. for j in range(len(L1Addr)):
  66. if L1Addr[j] == i:
  67. L1Data[j] = v
  68. L1Dirt[j] = True
  69.  
  70. if not res:
  71. v = M[i]
  72. k = choix_victime(LastUse)
  73. LastUse[j] = compteur
  74. if L1Dirt:
  75. M[L1Addr[k]] = L1Data[k]
  76. L1Addr[k] = i
  77. L1Data[k] = v
  78. L1Dirt[k] = False
  79. compteur += 1
  80. return res, compteur
  81.  
  82. #----------------------------------------------------------------------------#
  83. def choix_victime(LastUse):
  84. victime = min(LastUse)
  85. return LastUse.index(victime)
  86.  
  87. #----------------------------------------------------------------------------#
  88. def affichage():
  89. pass
  90.  
  91. #============================================================================#
  92. # FONCTIONS PRINCIPALE #
  93. #============================================================================#
  94. def main():
  95. """
  96. Description: le but de cet fonction est de rentrer en ligne de commande
  97. tous les données nécessaire pour effectuer la simulation de la mémoire
  98. cache.
  99. """
  100. #if (sys.argv[1] == "R"):
  101. # print("")
  102. #elif (sys.argv[1] == "W"):
  103. # print("")
  104. M=[0 for i in range(32)]
  105. L1Addr=[0 for i in range(8)]
  106. L1Data=[0 for i in range(8)]
  107. L1Dirt=[False for i in range(8)]
  108. LastUse = [0 for k in range(8)]
  109. filename = ouverture_fichier("instruction_file.txt", M, L1Addr, L1Data, L1Dirt, LastUse, compteur = 1)
  110.  
  111. #============================================================================#
  112. # TEST #
  113. #============================================================================#
  114. if __name__ == "__main__":
  115. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement