Simulation.java 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package Export;
  7. import API.ExportInterface;
  8. import API.Utils;
  9. import common.Block;
  10. import common.Code;
  11. import common.Instruction;
  12. import java.util.Map;
  13. import tools.mips.Memory;
  14. import tools.mips.MipsSettings;
  15. /**
  16. *
  17. * @author EUGENIO CARVALHO
  18. */
  19. public class Simulation implements ExportInterface {
  20. protected MipsSettings settings;
  21. public Simulation(tools.mips.MipsSettings settings) {
  22. this.settings = settings;
  23. }
  24. @Override
  25. public void Exec(Code IR, Code Target) throws Exception {
  26. // Integer index;
  27. // System.out.println(Target.GlobalContext());
  28. String bin;
  29. Memory memory = new Memory(
  30. settings.Get("memory.instruction"),
  31. settings.GetInt("memory.instruction.size")
  32. );
  33. memory.SetIO(new MemoryInitializationFile());
  34. for (Map.Entry<String, Block> x : Target.stmts.entrySet()) {
  35. for (Instruction instr : x.getValue().Instructions()) {
  36. bin = instr.Get("inst.bin");
  37. if (bin.equals("")) {
  38. continue;
  39. }
  40. // Divide os bytes da instrução binaria e escreve na memoria
  41. for (String sbyte : Utils.SplitEach(bin, 8)) {
  42. memory.WB(sbyte);
  43. }
  44. }
  45. }
  46. // Grava resutlado no arquivo de memoria do simulador
  47. memory.Save();
  48. // Instancia um simulador, executa e salva a memoria
  49. new tools.mips.MipsProcessor(settings)
  50. .Run()
  51. .Persist();
  52. }
  53. }
  54. /**
  55. <laplaciano>:
  56. 16c: 0666763244 addiu sp,sp,-20 -- prolog| push stack frame
  57. 170: 0001962017 addu fp,zero,sp -- prolog|copy fp ← sp
  58. 174: 0605028355 addiu s0,zero,3 .0 -- copy _V20 ← 3
  59. 178: 2949644288 sw s0,fp,0 .1 -- store content of s0 in _V20
  60. 17c: 0605093891 addiu s1,zero,3 .2 -- copy _V22 ← 3
  61. 180: 2949709828 sw s1,fp,4 .3 -- store content of s1 in _V22
  62. 184: 0605159425 addiu s2,zero,1 .4 -- copy _V23 ← 1
  63. 188: 2949775368 sw s2,fp,8 .5 -- store content of s2 in _V23
  64. 18c: 0134217947 j 36c <laplaciano+0x200> .6 -- jump to laplaciano+_i20
  65. 190: 0000000000 sll zero,zero,0 .6 -- Nop
  66. 194: 0605224961 addiu s3,zero,1 .7 -- copy _V24 ← 1
  67. 198: 2949840908 sw s3,fp,12 .8 -- store content of s3 in _V24
  68. 19c: 0134217937 j 344 <laplaciano+0x1d8> .9 -- jump to laplaciano+_i24
  69. 1a0: 0000000000 sll zero,zero,0 .9 -- Nop
  70. 1a4: 2413035528 lw s4,fp,8 .10 -- load content from _V23 in s4
  71. 1a8: 0000000000 sll zero,zero,0 .10 -- Nop
  72. 1ac: 0646840319 addiu t5,s4,-1 .11 -- _T26 = _V23 - 1
  73. 1b0: 0000880768 sll t6,t5,2 .12 -- _T27 = _T26 << 2
  74. 1b4: 2413101068 lw s5,fp,12 .13 -- load content from _V24 in s5
  75. 1b8: 0000000000 sll zero,zero,0 .13 -- Nop
  76. 1bc: 0001407009 addu t7,zero,s5 .14 -- copy _T29 ← _V24
  77. 1c0: 0030371873 addu t6,t6,t7 .15 -- _T27 = _T27 + _T29
  78. 1c4: 0000966784 sll t8,t6,2 .16 -- _T33 = _T27 << 2
  79. 1c8: 0060342305 addu t8,gp,t8 .17
  80. 1cc: 2400583680 lw s6,t8,0 .17
  81. 1d0: 0000000000 sll zero,zero,0 .17 -- Nop
  82. 1d4: 0001488929 addu s7,zero,s6 .17 -- copy s7 ← s6
  83. 1d8: 2950103056 sw s7,fp,16 .18 -- store content of s7 in _V36
  84. 1dc: 2413035528 lw s4,fp,8 .19 -- load content from _V23 in s4
  85. 1e0: 0000000000 sll zero,zero,0 .19 -- Nop
  86. 1e4: 0001327137 addu t0,zero,s4 .20 -- copy _T37 ← _V23
  87. 1e8: 0000542848 sll t1,t0,2 .21 -- _T38 = _T37 << 2
  88. 1ec: 2413101068 lw s5,fp,12 .22 -- load content from _V24 in s5
  89. 1f0: 0000000000 sll zero,zero,0 .22 -- Nop
  90. 1f4: 0648806399 addiu t3,s5,-1 .23 -- _T41 = _V24 - 1
  91. 1f8: 0019613729 addu t1,t1,t3 .24 -- _T38 = _T38 + _T41
  92. 1fc: 0000614528 sll t4,t1,2 .25 -- _T45 = _T38 << 2
  93. 200: 0059531297 addu t4,gp,t4 .26
  94. 204: 2374828032 lw t5,t4,0 .26
  95. 208: 2413232144 lw s7,fp,16 .27 -- load content from _V36 in s7
  96. 20c: 0000000000 sll zero,zero,0 .27 -- Nop
  97. 210: 0049133601 addu s7,s7,t5 .28 -- _V36 = _V36 + _T47
  98. 214: 2950103056 sw s7,fp,16 .29 -- store content of s7 in _V36
  99. 218: 2413035528 lw s4,fp,8 .30 -- load content from _V23 in s4
  100. 21c: 0000000000 sll zero,zero,0 .30 -- Nop
  101. 220: 0001341473 addu t7,zero,s4 .31 -- copy _T48 ← _V23
  102. 224: 0001011840 sll t6,t7,2 .32 -- _T49 = _T48 << 2
  103. 228: 2413101068 lw s5,fp,12 .33 -- load content from _V24 in s5
  104. 22c: 0000000000 sll zero,zero,0 .33 -- Nop
  105. 230: 0648544257 addiu t0,s5,1 .34 -- _T52 = _V24 + 1
  106. 234: 0029913121 addu t6,t6,t0 .35 -- _T49 = _T49 + _T52
  107. 238: 0000938112 sll t2,t6,2 .36 -- _T56 = _T49 << 2
  108. 23c: 0059396129 addu t2,gp,t2 .37
  109. 240: 2370502656 lw t3,t2,0 .37
  110. 244: 2413232144 lw s7,fp,16 .38 -- load content from _V36 in s7
  111. 248: 0000000000 sll zero,zero,0 .38 -- Nop
  112. 24c: 0049002529 addu s7,s7,t3 .39 -- _V36 = _V36 + _T58
  113. 250: 2950103056 sw s7,fp,16 .40 -- store content of s7 in _V36
  114. 254: 2413035528 lw s4,fp,8 .41 -- load content from _V23 in s4
  115. 258: 0000000000 sll zero,zero,0 .41 -- Nop
  116. 25c: 0646709249 addiu t4,s4,1 .42 -- _T60 = _V23 + 1
  117. 260: 0000813184 sll t5,t4,2 .43 -- _T61 = _T60 << 2
  118. 264: 2413101068 lw s5,fp,12 .44 -- load content from _V24 in s5
  119. 268: 0000000000 sll zero,zero,0 .44 -- Nop
  120. 26c: 0001407009 addu t7,zero,s5 .45 -- copy _T63 ← _V24
  121. 270: 0028272673 addu t5,t5,t7 .46 -- _T61 = _T61 + _T63
  122. 274: 0000901248 sll t8,t5,2 .47 -- _T67 = _T61 << 2
  123. 278: 0060342305 addu t8,gp,t8 .48
  124. 27c: 2399666176 lw t0,t8,0 .48
  125. 280: 2413232144 lw s7,fp,16 .49 -- load content from _V36 in s7
  126. 284: 0000000000 sll zero,zero,0 .49 -- Nop
  127. 288: 0048805921 addu s7,s7,t0 .50 -- _V36 = _V36 + _T69
  128. 28c: 2950103056 sw s7,fp,16 .51 -- store content of s7 in _V36
  129. 290: 2413035528 lw s4,fp,8 .52 -- load content from _V23 in s4
  130. 294: 0000000000 sll zero,zero,0 .52 -- Nop
  131. 298: 0001339425 addu t6,zero,s4 .53 -- copy _T70 ← _V23
  132. 29c: 0000938112 sll t2,t6,2 .54 -- _T71 = _T70 << 2
  133. 2a0: 2413101068 lw s5,fp,12 .55 -- load content from _V24 in s5
  134. 2a4: 0000000000 sll zero,zero,0 .55 -- Nop
  135. 2a8: 0001398817 addu t3,zero,s5 .56 -- copy _T73 ← _V24
  136. 2ac: 0021712929 addu t2,t2,t3 .57 -- _T71 = _T71 + _T73
  137. 2b0: 0000673920 sll t1,t2,2 .58 -- _T77 = _T71 << 2
  138. 2b4: 0059328545 addu t1,gp,t1 .59
  139. 2b8: 2368929792 lw s3,t1,0 .59
  140. 2bc: 0000000000 sll zero,zero,0 .59 -- Nop
  141. 2c0: 0001269793 addu t4,zero,s3 .59 -- copy t4 ← s3
  142. 2c4: 0604962820 addiu t7,zero,4 .60
  143. 2c8: 0026175512 mult t4,t7 .60 -- _T80 = _T79 * 4
  144. 2cc: 0000026642 mflo t5 .60
  145. 2d0: 2413232144 lw s7,fp,16 .61 -- load content from _V36 in s7
  146. 2d4: 0000000000 sll zero,zero,0 .61 -- Nop
  147. 2d8: 0049133603 subu s7,s7,t5 .62 -- _V36 = _V36 - _T80
  148. 2dc: 2950103056 sw s7,fp,16 .63 -- store content of s7 in _V36
  149. 2e0: 2413232144 lw s7,fp,16 .64 -- load content from _V36 in s7
  150. 2e4: 0000000000 sll zero,zero,0 .64 -- Nop
  151. 2e8: 0605552895 addiu t8,zero,255 .65
  152. 2ec: 0049811491 subu v0,s7,t8 .65
  153. 2f0: 0406847491 blez v0,300 <laplaciano+0x194> .65 -- branch if register <= 0
  154. 2f4: 0000000000 sll zero,zero,0 .65 -- Nop
  155. 2f8: 0605421823 addiu s6,zero,255 .66 -- copy _V36 ← 255
  156. 2fc: 2950037520 sw s6,fp,16 .67 -- store content of s6 in _V36
  157. 300: 2412773384 lw s0,fp,8 .68 -- load content from _V23 in s0
  158. 304: 0000000000 sll zero,zero,0 .68 -- Nop
  159. 308: 0001077281 addu t6,zero,s0 .69 -- copy _T81 ← _V23
  160. 30c: 0000940160 sll t3,t6,2 .70 -- _T82 = _T81 << 2
  161. 310: 2412838924 lw s1,fp,12 .71 -- load content from _V24 in s1
  162. 314: 0000000000 sll zero,zero,0 .71 -- Nop
  163. 318: 0001134625 addu t2,zero,s1 .72 -- copy _T84 ← _V24
  164. 31c: 0023746593 addu t3,t3,t2 .73 -- _T82 = _T82 + _T84
  165. 320: 0000739456 sll t1,t3,2 .74 -- _T88 = _T82 << 2
  166. 324: 2412904464 lw s2,fp,16 .75 -- load content from _V36 in s2
  167. 328: 0000000000 sll zero,zero,0 .75 -- Nop
  168. 32c: 0059328545 addu t1,gp,t1 .76
  169. 330: 2905735232 sw s2,t1,64 .76 -- store content of t1 in _G90[_T88]
  170. 334: 2413101068 lw s5,fp,12 .77 -- load content from _V24 in s5
  171. 338: 0000000000 sll zero,zero,0 .77 -- Nop
  172. 33c: 0649396225 addiu s5,s5,1 .78 -- _V24 = _V24 + 1
  173. 340: 2949971980 sw s5,fp,12 .79 -- store content of s5 in _V24
  174. 344: 2412969996 lw s3,fp,12 .80 -- load content from _V24 in s3
  175. 348: 2413232132 lw s7,fp,4 .81 -- load content from _V22 in s7
  176. 34c: 0000000000 sll zero,zero,0 .81 -- Nop
  177. 350: 0041357347 subu v0,s3,s7 .82
  178. 354: 0071368595 bltz v0,1a4 <laplaciano+0x38> .82 -- branch if register < 0
  179. 358: 0000000000 sll zero,zero,0 .82 -- Nop
  180. 35c: 2413166600 lw s6,fp,8 .83 -- load content from _V23 in s6
  181. 360: 0000000000 sll zero,zero,0 .83 -- Nop
  182. 364: 0651558913 addiu s6,s6,1 .84 -- _V23 = _V23 + 1
  183. 368: 2950037512 sw s6,fp,8 .85 -- store content of s6 in _V23
  184. 36c: 2412773384 lw s0,fp,8 .86 -- load content from _V23 in s0
  185. 370: 2412838912 lw s1,fp,0 .87 -- load content from _V20 in s1
  186. 374: 0000000000 sll zero,zero,0 .87 -- Nop
  187. 378: 0034672675 subu v0,s0,s1 .88
  188. 37c: 0071368581 bltz v0,194 <laplaciano+0x28> .88 -- branch if register < 0
  189. 380: 0000000000 sll zero,zero,0 .88 -- Nop
  190. 384: 0666697748 addiu sp,sp,20 -- epilog| pop stack frame
  191. 388: 0001962017 addu fp,zero,sp -- epilog| pop stack frame
  192. 38c: 0065011720 jr ra -- epilog| return
  193. */