source: liacs/coco/assignment4/RegisterManager.h@ 20

Last change on this file since 20 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 2.4 KB
Line 
1#ifndef REGISTERMANAGER_H
2#define REGISTERMANAGER_H
3
4#include "Symbol.h"
5#include "globals.h"
6#include "StackFrameManager.h"
7#include "AssemblerCode.h"
8
9/* Keeps track of what registers are associated with symbols.
10 Loads the appropriate registers and generates spill code if needed.
11*/
12class RegisterManager {
13public:
14 // constructor
15 RegisterManager(StackFrameManager& sfm, AssemblerCode& ac);
16
17 // Get the register associated with symbol.
18 // Register is of same type as the return type of the symbol.
19 // Generates loading code if needed.
20 MRegisterType GetRegister(Symbol *symbol);
21
22 // Gets an integer register associated with symbol.
23 // Generates loading code if needed.
24 MRegisterType GetIntRegister(Symbol *symbol);
25
26 // Gets a float register associated with symbol.
27 // Generates loading code if needed.
28 MRegisterType GetFloatRegister(Symbol *symbol);
29
30 // Get temponary register, which rotates
31 MRegisterType GetTempRegister();
32
33 // Write back all registers and unassociate all symbols.
34 void SpillAll();
35private:
36 StackFrameManager& sfm;
37 AssemblerCode& ac;
38
39 // Find the register associated with symbol and return its index
40 // Returns -1 if not found
41 int FindSymbol(Symbol *symbols[], int size, Symbol *symbol) const;
42
43 // Find an unused register and returns its index
44 // Returns -1 if not found
45 int FindUnused(Symbol *symbols[], int size) const;
46
47 int PickSpillRegister(MRegisterType registers[], int size) const;
48
49 // Clears the symbol associated with the register and generates spill code
50 void SpillIntRegister(int idx);
51 void SpillFloatRegister(int idx);
52
53 void GenerateIntSpillCode(MRegisterType reg, Symbol *symbol);
54 void GenerateFloatSpillCode(MRegisterType reg, Symbol *symbol);
55
56 void GenerateIntLoadCode(MRegisterType reg, Symbol *symbol);
57 void GenerateFloatLoadCode(MRegisterType reg, Symbol *symbol);
58
59 static const int int_reg_size = 18; // number of integer registers
60 static MRegisterType int_registers[int_reg_size]; // the integer registers that can be used
61 Symbol *int_symbols[int_reg_size]; // symbols associated with integer registers
62
63 static const int float_reg_size = 15; // number of float registers
64 static MRegisterType float_registers[float_reg_size]; // the float registers that can be used
65 Symbol *float_symbols[float_reg_size]; // symbols associated with integer registers
66
67 static const int tmp_reg_size = 4;
68 static MRegisterType tmp_registers[tmp_reg_size];
69};
70
71#endif /* REGISTERMANAGER_H */
Note: See TracBrowser for help on using the repository browser.