Changes to build successfully with GCC 3.02
[oota-llvm.git] / include / llvm / SlotCalculator.h
1 //===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==//
2 //
3 // This ModuleAnalyzer subclass calculates the slots that values will land in.
4 // This is useful for when writing bytecode or assembly out, because you have 
5 // to know these things.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H
10 #define LLVM_ANALYSIS_SLOTCALCULATOR_H
11
12 #include "llvm/SymTabValue.h"
13 #include <vector>
14 #include <map>
15 class Value;
16 class Module;
17 class Method;
18 class MethodArgument;
19 class BasicBlock;
20 class Instruction;
21
22 class SlotCalculator {
23   const Module *TheModule;
24   bool IgnoreNamedNodes;     // Shall we not count named nodes?
25
26   typedef std::vector<const Value*> TypePlane;
27   std::vector<TypePlane> Table;
28   std::map<const Value *, unsigned> NodeMap;
29
30   // ModuleLevel - Used to keep track of which values belong to the module,
31   // and which values belong to the currently incorporated method.
32   //
33   std::vector<unsigned> ModuleLevel;
34
35 public:
36   SlotCalculator(const Module *M, bool IgnoreNamed);
37   SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
38   inline ~SlotCalculator() {}
39   
40   // getValSlot returns < 0 on error!
41   int getValSlot(const Value *D) const;
42
43   inline unsigned getNumPlanes() const { return Table.size(); }
44   inline unsigned getModuleLevel(unsigned Plane) const { 
45     return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0; 
46   }
47
48   inline const TypePlane &getPlane(unsigned Plane) const { 
49     return Table[Plane]; 
50   }
51
52   // If you'd like to deal with a method, use these two methods to get its data
53   // into the SlotCalculator!
54   //
55   void incorporateMethod(const Method *M);
56   void purgeMethod();
57
58 protected:
59   // insertVal - Insert a value into the value table... Return the slot that it
60   // occupies, or -1 if the declaration is to be ignored because of the
61   // IgnoreNamedNodes flag.
62   //
63   int insertVal(const Value *D, bool dontIgnore = false);
64
65   // insertValue - Values can be crammed into here at will... if they haven't
66   // been inserted already, they get inserted, otherwise they are ignored.
67   //
68   int insertValue(const Value *D);
69
70   // doInsertVal - Small helper function to be called only be insertVal.
71   int doInsertVal(const Value *D);
72
73   // processModule - Process all of the module level method declarations and
74   // types that are available.
75   //
76   void processModule();
77
78   // processSymbolTable - Insert all of the values in the specified symbol table
79   // into the values table...
80   //
81   void processSymbolTable(const SymbolTable *ST);
82   void processSymbolTableConstants(const SymbolTable *ST);
83 };
84
85 #endif