/JIT/PyTypeBuilder.cc

http://unladen-swallow.googlecode.com/ · C++ · 19 lines · 16 code · 3 blank · 0 comment · 1 complexity · c6e2ded74e91f513a5f79bac59297cdb MD5 · raw file

  1. #include "JIT/PyTypeBuilder.h"
  2. #include "JIT/global_llvm_data.h"
  3. #include "llvm/ExecutionEngine/ExecutionEngine.h"
  4. #include "llvm/Target/TargetData.h"
  5. unsigned int
  6. _PyTypeBuilder_GetFieldIndexFromOffset(
  7. const llvm::StructType *type, size_t offset)
  8. {
  9. const llvm::TargetData *target_data =
  10. PyGlobalLlvmData::Get()->getExecutionEngine()->getTargetData();
  11. const llvm::StructLayout *layout = target_data->getStructLayout(type);
  12. unsigned int index = layout->getElementContainingOffset(offset);
  13. assert(layout->getElementOffset(index) == offset &&
  14. "offset must be at start of element");
  15. return index;
  16. }