forked from OSchip/llvm-project
				
			Change Module to use TargetData-compatible strings internally.
This is part of the on-going work on PR 761. llvm-svn: 28379
This commit is contained in:
		
							parent
							
								
									305c49579c
								
							
						
					
					
						commit
						9eb1a268c1
					
				| 
						 | 
					@ -94,8 +94,7 @@ private:
 | 
				
			||||||
  SymbolTable *SymTab;           ///< Symbol Table for the module
 | 
					  SymbolTable *SymTab;           ///< Symbol Table for the module
 | 
				
			||||||
  std::string ModuleID;          ///< Human readable identifier for the module
 | 
					  std::string ModuleID;          ///< Human readable identifier for the module
 | 
				
			||||||
  std::string TargetTriple;      ///< Platform target triple Module compiled on
 | 
					  std::string TargetTriple;      ///< Platform target triple Module compiled on
 | 
				
			||||||
  Endianness  Endian;            ///< Endianness assumed in the module
 | 
					  std::string DataLayout;        ///< Target data description
 | 
				
			||||||
  PointerSize PtrSize;           ///< Pointer size assumed in the module
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  friend class Constant;
 | 
					  friend class Constant;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -123,11 +122,11 @@ public:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Get the target endian information.
 | 
					  /// Get the target endian information.
 | 
				
			||||||
  /// @returns Endianess - an enumeration for the endianess of the target
 | 
					  /// @returns Endianess - an enumeration for the endianess of the target
 | 
				
			||||||
  Endianness getEndianness() const { return Endian; }
 | 
					  Endianness getEndianness() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Get the target pointer size.
 | 
					  /// Get the target pointer size.
 | 
				
			||||||
  /// @returns PointerSize - an enumeration for the size of the target's pointer
 | 
					  /// @returns PointerSize - an enumeration for the size of the target's pointer
 | 
				
			||||||
  PointerSize getPointerSize() const { return PtrSize; }
 | 
					  PointerSize getPointerSize() const;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Get any module-scope inline assembly blocks.
 | 
					  /// Get any module-scope inline assembly blocks.
 | 
				
			||||||
  /// @returns a string containing the module-scope inline assembly blocks.
 | 
					  /// @returns a string containing the module-scope inline assembly blocks.
 | 
				
			||||||
| 
						 | 
					@ -144,10 +143,10 @@ public:
 | 
				
			||||||
  void setTargetTriple(const std::string &T) { TargetTriple = T; }
 | 
					  void setTargetTriple(const std::string &T) { TargetTriple = T; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Set the target endian information.
 | 
					  /// Set the target endian information.
 | 
				
			||||||
  void setEndianness(Endianness E) { Endian = E; }
 | 
					  void setEndianness(Endianness E);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Set the target pointer size.
 | 
					  /// Set the target pointer size.
 | 
				
			||||||
  void setPointerSize(PointerSize PS) { PtrSize = PS; }
 | 
					  void setPointerSize(PointerSize PS);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  /// Set the module-scope inline assembly blocks.
 | 
					  /// Set the module-scope inline assembly blocks.
 | 
				
			||||||
  void setModuleInlineAsm(const std::string &Asm) { GlobalScopeAsm = Asm; }
 | 
					  void setModuleInlineAsm(const std::string &Asm) { GlobalScopeAsm = Asm; }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -16,10 +16,12 @@
 | 
				
			||||||
#include "llvm/Constants.h"
 | 
					#include "llvm/Constants.h"
 | 
				
			||||||
#include "llvm/DerivedTypes.h"
 | 
					#include "llvm/DerivedTypes.h"
 | 
				
			||||||
#include "llvm/ADT/STLExtras.h"
 | 
					#include "llvm/ADT/STLExtras.h"
 | 
				
			||||||
 | 
					#include "llvm/ADT/StringExtras.h"
 | 
				
			||||||
#include "llvm/Support/LeakDetector.h"
 | 
					#include "llvm/Support/LeakDetector.h"
 | 
				
			||||||
#include "SymbolTableListTraitsImpl.h"
 | 
					#include "SymbolTableListTraitsImpl.h"
 | 
				
			||||||
#include <algorithm>
 | 
					#include <algorithm>
 | 
				
			||||||
#include <cstdarg>
 | 
					#include <cstdarg>
 | 
				
			||||||
 | 
					#include <cstdlib>
 | 
				
			||||||
#include <iostream>
 | 
					#include <iostream>
 | 
				
			||||||
#include <map>
 | 
					#include <map>
 | 
				
			||||||
using namespace llvm;
 | 
					using namespace llvm;
 | 
				
			||||||
| 
						 | 
					@ -61,7 +63,7 @@ template class SymbolTableListTraits<Function, Module, Module>;
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Module::Module(const std::string &MID)
 | 
					Module::Module(const std::string &MID)
 | 
				
			||||||
  : ModuleID(MID), Endian(AnyEndianness), PtrSize(AnyPointerSize) {
 | 
					  : ModuleID(MID), DataLayout("") {
 | 
				
			||||||
  FunctionList.setItemParent(this);
 | 
					  FunctionList.setItemParent(this);
 | 
				
			||||||
  FunctionList.setParent(this);
 | 
					  FunctionList.setParent(this);
 | 
				
			||||||
  GlobalList.setItemParent(this);
 | 
					  GlobalList.setItemParent(this);
 | 
				
			||||||
| 
						 | 
					@ -84,6 +86,63 @@ void Module::dump() const {
 | 
				
			||||||
  print(std::cerr);
 | 
					  print(std::cerr);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Target endian information...
 | 
				
			||||||
 | 
					Module::Endianness Module::getEndianness() const {
 | 
				
			||||||
 | 
					  std::string temp = DataLayout;
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  while (temp.length() > 0) {
 | 
				
			||||||
 | 
					    std::string token = getToken(temp, "-");
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (token[0] == 'e') {
 | 
				
			||||||
 | 
					      return LittleEndian;
 | 
				
			||||||
 | 
					    } else if (token[0] == 'E') {
 | 
				
			||||||
 | 
					      return BigEndian;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  return AnyEndianness;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Module::setEndianness(Endianness E) {
 | 
				
			||||||
 | 
					  if (DataLayout.compare("") != 0 && E != AnyEndianness)
 | 
				
			||||||
 | 
					    DataLayout.insert(0, "-");
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  if (E == LittleEndian)
 | 
				
			||||||
 | 
					    DataLayout.insert(0, "e");
 | 
				
			||||||
 | 
					  else if (E == BigEndian)
 | 
				
			||||||
 | 
					    DataLayout.insert(0, "E");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Target Pointer Size information...
 | 
				
			||||||
 | 
					Module::PointerSize Module::getPointerSize() const {
 | 
				
			||||||
 | 
					  std::string temp = DataLayout;
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  while (temp.length() > 0) {
 | 
				
			||||||
 | 
					    std::string token = getToken(temp, "-");
 | 
				
			||||||
 | 
					    char signal = getToken(token, ":")[0];
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    if (signal == 'p') {
 | 
				
			||||||
 | 
					      int size = atoi(getToken(token, ":").c_str());
 | 
				
			||||||
 | 
					      if (size == 32)
 | 
				
			||||||
 | 
					        return Pointer32;
 | 
				
			||||||
 | 
					      else if (size == 64)
 | 
				
			||||||
 | 
					        return Pointer64;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  return AnyPointerSize;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void Module::setPointerSize(PointerSize PS) {
 | 
				
			||||||
 | 
					  if (DataLayout.compare("") != 0 && PS != AnyPointerSize)
 | 
				
			||||||
 | 
					    DataLayout.insert(0, "-");
 | 
				
			||||||
 | 
					  
 | 
				
			||||||
 | 
					  if (PS == Pointer32)
 | 
				
			||||||
 | 
					    DataLayout.insert(0, "p:32:32");
 | 
				
			||||||
 | 
					  else if (PS == Pointer64)
 | 
				
			||||||
 | 
					    DataLayout.insert(0, "p:64:64");
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//===----------------------------------------------------------------------===//
 | 
					//===----------------------------------------------------------------------===//
 | 
				
			||||||
// Methods for easy access to the functions in the module.
 | 
					// Methods for easy access to the functions in the module.
 | 
				
			||||||
//
 | 
					//
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue