summaryrefslogtreecommitdiff
path: root/include/llvm/Analysis
diff options
context:
space:
mode:
Diffstat (limited to 'include/llvm/Analysis')
-rw-r--r--include/llvm/Analysis/ModuleAnalyzer.h113
-rw-r--r--include/llvm/Analysis/SlotCalculator.h96
-rw-r--r--include/llvm/Analysis/Verifier.h28
3 files changed, 237 insertions, 0 deletions
diff --git a/include/llvm/Analysis/ModuleAnalyzer.h b/include/llvm/Analysis/ModuleAnalyzer.h
new file mode 100644
index 0000000000..3abdd49afe
--- /dev/null
+++ b/include/llvm/Analysis/ModuleAnalyzer.h
@@ -0,0 +1,113 @@
+//===-- llvm/Analysis/ModuleAnalyzer.h - Module analysis driver --*- C++ -*-==//
+//
+// This class provides a nice interface to traverse a module in a predictable
+// way. This is used by the AssemblyWriter, BytecodeWriter, and SlotCalculator
+// to do analysis of a module.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_MODULEANALYZER_H
+#define LLVM_ANALYSIS_MODULEANALYZER_H
+
+#include "llvm/ConstantPool.h"
+#include <set>
+
+class Module;
+class Method;
+class BasicBlock;
+class Instruction;
+class ConstPoolVal;
+class MethodType;
+class MethodArgument;
+
+class ModuleAnalyzer {
+ ModuleAnalyzer(const ModuleAnalyzer &); // do not impl
+ const ModuleAnalyzer &operator=(const ModuleAnalyzer &); // do not impl
+public:
+ ModuleAnalyzer() {}
+ virtual ~ModuleAnalyzer() {}
+
+protected:
+ // processModule - Driver function to call all of my subclasses virtual
+ // methods. Commonly called by derived type's constructor.
+ //
+ bool processModule(const Module *M);
+
+ //===--------------------------------------------------------------------===//
+ // Stages of processing Module level information
+ //
+ virtual bool processConstPool(const ConstantPool &CP, bool isMethod);
+
+ // processType - This callback occurs when an derived type is discovered
+ // at the class level. This activity occurs when processing a constant pool.
+ //
+ virtual bool processType(const Type *Ty) { return false; }
+
+ // processMethods - The default implementation of this method loops through
+ // all of the methods in the module and processModule's them.
+ //
+ virtual bool processMethods(const Module *M);
+
+ //===--------------------------------------------------------------------===//
+ // Stages of processing a constant pool
+ //
+
+ // processConstPoolPlane - Called once for every populated plane in the
+ // constant pool. The default action is to do nothing. The processConstPool
+ // method does the iteration over constants.
+ //
+ virtual bool processConstPoolPlane(const ConstantPool &CP,
+ const ConstantPool::PlaneType &Pl,
+ bool isMethod) {
+ return false;
+ }
+
+ // processConstant is called once per each constant in the constant pool. It
+ // traverses the constant pool such that it visits each constant in the
+ // order of its type. Thus, all 'int' typed constants shall be visited
+ // sequentially, etc...
+ //
+ virtual bool processConstant(const ConstPoolVal *CPV) { return false; }
+
+ // visitMethod - This member is called after the constant pool has been
+ // processed. The default implementation of this is a noop.
+ //
+ virtual bool visitMethod(const Method *M) { return false; }
+
+ //===--------------------------------------------------------------------===//
+ // Stages of processing Method level information
+ //
+ // (processConstPool is also used above, with the isMethod flag set to true)
+ //
+
+ // processMethod - Process all aspects of a method.
+ //
+ virtual bool processMethod(const Method *M);
+
+ // processMethodArgument - This member is called for every argument that
+ // is passed into the method.
+ //
+ virtual bool processMethodArgument(const MethodArgument *MA) { return false; }
+
+ // processBasicBlock - This member is called for each basic block in a methd.
+ //
+ virtual bool processBasicBlock(const BasicBlock *BB);
+
+ //===--------------------------------------------------------------------===//
+ // Stages of processing BasicBlock level information
+ //
+
+ // preProcessInstruction - This member is called for each Instruction in a
+ // method before processInstruction.
+ //
+ virtual bool preProcessInstruction(const Instruction *I);
+
+ // processInstruction - This member is called for each Instruction in a method
+ //
+ virtual bool processInstruction(const Instruction *I) { return false; }
+
+private:
+ bool handleType(set<const Type *> &TypeSet, const Type *T);
+};
+
+#endif
diff --git a/include/llvm/Analysis/SlotCalculator.h b/include/llvm/Analysis/SlotCalculator.h
new file mode 100644
index 0000000000..99e40cbeb5
--- /dev/null
+++ b/include/llvm/Analysis/SlotCalculator.h
@@ -0,0 +1,96 @@
+//===-- llvm/Analysis/SlotCalculator.h - Calculate value slots ---*- C++ -*-==//
+//
+// This ModuleAnalyzer subclass calculates the slots that values will land in.
+// This is useful for when writing bytecode or assembly out, because you have
+// to know these things.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_SLOTCALCULATOR_H
+#define LLVM_ANALYSIS_SLOTCALCULATOR_H
+
+#include "llvm/Analysis/ModuleAnalyzer.h"
+#include "llvm/SymTabValue.h"
+#include <vector>
+#include <map>
+
+class SlotCalculator : public ModuleAnalyzer {
+ const Module *TheModule;
+ bool IgnoreNamedNodes; // Shall we not count named nodes?
+
+ typedef vector<const Value*> TypePlane;
+ vector <TypePlane> Table;
+ map<const Value *, unsigned> NodeMap;
+
+ // ModuleLevel - Used to keep track of which values belong to the module,
+ // and which values belong to the currently incorporated method.
+ //
+ vector <unsigned> ModuleLevel;
+
+public:
+ SlotCalculator(const Module *M, bool IgnoreNamed);
+ SlotCalculator(const Method *M, bool IgnoreNamed);// Start out in incorp state
+ inline ~SlotCalculator() {}
+
+ // getValSlot returns < 0 on error!
+ int getValSlot(const Value *D) const;
+
+ inline unsigned getNumPlanes() const { return Table.size(); }
+ inline unsigned getModuleLevel(unsigned Plane) const {
+ return Plane < ModuleLevel.size() ? ModuleLevel[Plane] : 0;
+ }
+
+ inline const TypePlane &getPlane(unsigned Plane) const {
+ return Table[Plane];
+ }
+
+ // If you'd like to deal with a method, use these two methods to get its data
+ // into the SlotCalculator!
+ //
+ void incorporateMethod(const Method *M);
+ void purgeMethod();
+
+protected:
+ // insertVal - Insert a value into the value table...
+ //
+ void insertVal(const Value *D);
+
+ // visitMethod - This member is called after the constant pool has been
+ // processed. The default implementation of this is a noop.
+ //
+ virtual bool visitMethod(const Method *M);
+
+ // processConstant is called once per each constant in the constant pool. It
+ // traverses the constant pool such that it visits each constant in the
+ // order of its type. Thus, all 'int' typed constants shall be visited
+ // sequentially, etc...
+ //
+ virtual bool processConstant(const ConstPoolVal *CPV);
+
+ // processType - This callback occurs when an derived type is discovered
+ // at the class level. This activity occurs when processing a constant pool.
+ //
+ virtual bool processType(const Type *Ty);
+
+ // processMethods - The default implementation of this method loops through
+ // all of the methods in the module and processModule's them. We don't want
+ // this (we want to explicitly visit them with incorporateMethod), so we
+ // disable it.
+ //
+ virtual bool processMethods(const Module *M) { return false; }
+
+ // processMethodArgument - This member is called for every argument that
+ // is passed into the method.
+ //
+ virtual bool processMethodArgument(const MethodArgument *MA);
+
+ // processBasicBlock - This member is called for each basic block in a methd.
+ //
+ virtual bool processBasicBlock(const BasicBlock *BB);
+
+ // processInstruction - This member is called for each Instruction in a methd.
+ //
+ virtual bool processInstruction(const Instruction *I);
+};
+
+#endif
diff --git a/include/llvm/Analysis/Verifier.h b/include/llvm/Analysis/Verifier.h
new file mode 100644
index 0000000000..2feadca779
--- /dev/null
+++ b/include/llvm/Analysis/Verifier.h
@@ -0,0 +1,28 @@
+//===-- llvm/Analysis/Verifier.h - Module Verifier ---------------*- C++ -*-==//
+//
+// This file defines the method verifier interface, that can be used for some
+// sanity checking of input to the system.
+//
+// Note that this does not provide full 'java style' security and verifications,
+// instead it just tries to ensure that code is well formed.
+//
+// To see what specifically is checked, look at the top of Verifier.cpp
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_ANALYSIS_VERIFIER_H
+#define LLVM_ANALYSIS_VERIFIER_H
+
+#include <vector>
+#include <string>
+class Module;
+class Method;
+
+// verify - Check a module or method for validity. If errors are detected,
+// error messages corresponding to the problem are added to the errorMsgs
+// vectors, and a value of true is returned.
+//
+bool verify(const Module *M, vector<string> &ErrorMsgs);
+bool verify(const Method *M, vector<string> &ErrorMsgs);
+
+#endif