diff options
author | Chris Lattner <sabre@nondot.org> | 2001-09-10 07:58:01 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-09-10 07:58:01 +0000 |
commit | 70cc3397f84c2e1fd69c059a0ef89e398e847b00 (patch) | |
tree | ca2156daf75e4abf788d92925bdce4063da36e58 /include/llvm | |
parent | 7720c8e1a7a252e983e3f3e7f841d7901dfea80c (diff) |
Implement global variable support
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@530 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm')
-rw-r--r-- | include/llvm/Function.h | 2 | ||||
-rw-r--r-- | include/llvm/GlobalVariable.h | 34 | ||||
-rw-r--r-- | include/llvm/Module.h | 37 | ||||
-rw-r--r-- | include/llvm/Value.h | 4 |
4 files changed, 73 insertions, 4 deletions
diff --git a/include/llvm/Function.h b/include/llvm/Function.h index b1d38dda4f..2be84d4e4c 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -40,7 +40,7 @@ private: Module *Parent; // The module that contains this method - friend class ValueHolder<Method,Module, Module>; + friend class ValueHolder<Method, Module, Module>; void setParent(Module *parent); public: diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h new file mode 100644 index 0000000000..fd97989618 --- /dev/null +++ b/include/llvm/GlobalVariable.h @@ -0,0 +1,34 @@ +//===-- llvm/Global.h - Class to represent a global variable -----*- C++ -*--=// +// +// This file contains the declaration of the GlobalVariable class, which +// represents a single global variable in the VM. +// +// Global variables are constant pointers that refer to hunks of space that are +// allocated by either the VM, or by the linker in a static compiler. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_GLOBAL_VARIABLE_H +#define LLVM_GLOBAL_VARIABLE_H + +#include "llvm/Value.h" +class Module; + +class GlobalVariable : public Value { + Module *Parent; // The module that contains this method + + friend class ValueHolder<GlobalVariable, Module, Module>; + void setParent(Module *parent) { Parent = parent; } + +public: + GlobalVariable(const Type *Ty, const string &Name = ""); + ~GlobalVariable() {} + + // Specialize setName to handle symbol table majik... + virtual void setName(const string &name, SymbolTable *ST = 0); + + inline Module *getParent() { return Parent; } + inline const Module *getParent() const { return Parent; } +}; + +#endif diff --git a/include/llvm/Module.h b/include/llvm/Module.h index 866f5e0e9e..bf710d1223 100644 --- a/include/llvm/Module.h +++ b/include/llvm/Module.h @@ -12,17 +12,27 @@ #include "llvm/SymTabValue.h" #include "llvm/ValueHolder.h" class Method; +class GlobalVariable; class Module : public Value, public SymTabValue { public: + typedef ValueHolder<GlobalVariable, Module, Module> GlobalListType; typedef ValueHolder<Method, Module, Module> MethodListType; + // Global Variable iterators... + typedef GlobalListType::iterator giterator; + typedef GlobalListType::const_iterator const_giterator; + typedef reverse_iterator<giterator> reverse_giterator; + typedef reverse_iterator<const_giterator> const_reverse_giterator; + // Method iterators... - typedef MethodListType::iterator iterator; - typedef MethodListType::const_iterator const_iterator; + typedef MethodListType::iterator iterator; + typedef MethodListType::const_iterator const_iterator; typedef reverse_iterator<const_iterator> const_reverse_iterator; typedef reverse_iterator<iterator> reverse_iterator; + private: + GlobalListType GlobalList; // The Global Variables MethodListType MethodList; // The Methods public: @@ -32,17 +42,40 @@ public: // reduceApply - Apply the specified function to all of the methods in this // module. The result values are or'd together and the result is returned. // + bool reduceApply(bool (*Func)(GlobalVariable*)); + bool reduceApply(bool (*Func)(const GlobalVariable*)) const; bool reduceApply(bool (*Func)(Method*)); bool reduceApply(bool (*Func)(const Method*)) const; // Get the underlying elements of the Module... + inline const GlobalListType &getGlobalList() const { return GlobalList; } + inline GlobalListType &getGlobalList() { return GlobalList; } inline const MethodListType &getMethodList() const { return MethodList; } inline MethodListType &getMethodList() { return MethodList; } //===--------------------------------------------------------------------===// // Module iterator forwarding functions // + inline giterator gbegin() { return GlobalList.begin(); } + inline const_giterator gbegin() const { return GlobalList.begin(); } + inline giterator gend () { return GlobalList.end(); } + inline const_giterator gend () const { return GlobalList.end(); } + + inline reverse_giterator grbegin() { return GlobalList.rbegin(); } + inline const_reverse_giterator grbegin() const { return GlobalList.rbegin(); } + inline reverse_giterator grend () { return GlobalList.rend(); } + inline const_reverse_giterator grend () const { return GlobalList.rend(); } + + inline unsigned gsize() const { return GlobalList.size(); } + inline bool gempty() const { return GlobalList.empty(); } + inline const GlobalVariable *gfront() const { return GlobalList.front(); } + inline GlobalVariable *gfront() { return GlobalList.front(); } + inline const GlobalVariable *gback() const { return GlobalList.back(); } + inline GlobalVariable *gback() { return GlobalList.back(); } + + + inline iterator begin() { return MethodList.begin(); } inline const_iterator begin() const { return MethodList.begin(); } inline iterator end () { return MethodList.end(); } diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 889551d0cd..dd97d3577d 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -19,6 +19,7 @@ class MethodArgument; class Instruction; class BasicBlock; class Method; +class GlobalVariable; class Module; class SymbolTable; template<class ValueSubclass, class ItemParentType, class SymTabType> @@ -36,9 +37,9 @@ public: ConstantVal, // This is an instance of ConstPoolVal MethodArgumentVal, // This is an instance of MethodArgument InstructionVal, // This is an instance of Instruction - BasicBlockVal, // This is an instance of BasicBlock MethodVal, // This is an instance of Method + GlobalVal, // This is an instance of GlobalVariable ModuleVal, // This is an instance of Module }; @@ -102,6 +103,7 @@ public: CAST_FN(Instruction , Instruction ) CAST_FN(BasicBlock , BasicBlock ) CAST_FN(Method , Method ) + CAST_FN(Global , GlobalVariable) CAST_FN(Module , Module ) #undef CAST_FN |