Advertisement
Lauda

Untitled

Jun 12th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.22 KB | None | 0 0
  1. // VJEZBA 12
  2. bool doResourceAllocation(stack<Variable*>* simplificationStack, InterferenceGraph* ig)
  3. {
  4.     vector<Variable*> promenjive;
  5.     for (Variables::const_iterator it=ig->variables->begin(); it!=ig->variables->end(); ++it)
  6.         promenjive.push_back(*it);
  7.  
  8.     sort(promenjive.begin(),promenjive.end()); // Sortiramo vektor: cba -> abc
  9.  
  10.     while (!simplificationStack->empty()) //uzimamo jedan po jedan cvor sa steka i "bojimo ga
  11.     {
  12.         bool foundReg = false;
  13.         vector<Regs> used;
  14.         Variable *a = simplificationStack->top(); // Pristupamo sledecem elementu
  15.         simplificationStack->pop(); // Skidamo sa vrha element
  16.  
  17.         for (int i=0; i < ig->size; i++)
  18.             if (ig->values[a->pos][i] == __INTERFERENCE__) // ako je element na preseku kolone(tekuci el.) i vrste(neki vec prethodno obojeni cvor)
  19.                                                                     // jednak __INTERFERENCE__ to znaci da su ta 2 cvora u smetnji(u toj celiji matrice je __INTERFERENCE__)
  20.                 if ((promenjive[i]->assigment)!=-1)
  21.                     used.push_back((Regs)promenjive[i]->assigment);
  22.  
  23.         for (int i=0; i<=__REG_NUMBER__; i++)
  24.         {
  25.             Regs tmp = (Regs)i;
  26.             if (find(used.begin(), used.end(), tmp) == used.end())
  27.             {
  28.                 a->assigment = (Regs)i;
  29.                 foundReg = true;
  30.                 break;
  31.             }
  32.         }
  33.  
  34.         if (!foundReg)
  35.             return false;
  36.     }
  37.     return true;
  38. }
  39.  
  40.  
  41. Instructions* removeMove(Instructions* instrs)
  42. {
  43.     // ovo je dodatni zadatak
  44.     Variable* v;
  45.     for (Instructions::const_iterator it = instrs->begin(); it!=instrs->end(); ++it)
  46.     {
  47.         if ((*it)->type == T_MOVE)
  48.             if (((*it)->src1->assigment == (*it)->dst->assigment) && ((*it)->src2 == NULL))
  49.             {
  50.                 instrs->remove((*it));
  51.                 return instrs;
  52.             }
  53.     }
  54.     return instrs;
  55. }
  56.  
  57. // VJEZBA 13
  58.  
  59.     // your code should go here
  60.  
  61.     list<RelTableEntry*>::iterator it = firstPass[0]->relTable->begin();
  62.  
  63.     for(; it != firstPass[0]->relTable->end(); ++it)
  64.     {
  65.         SymbolTableEntry ste = *findSymbol((*it)->symbolName);
  66.         relMips26((Elf32_Word*)(firstPass[0]->textSection.buffer + (*it)->offset), ste.pap + ste.value);
  67.     }
  68.    
  69.     int offset = 0;
  70.  
  71.     for(int i = 0; i < __NFILE__; i++)
  72.     {
  73.         memcpy(secondPass->textSection.buffer + offset, firstPass[i]->textSection.buffer, firstPass[i]>textSection.size);
  74.         offset += firstPass[i]->textSection.size;
  75.     }
  76.  
  77.     return secondPass;
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement