MCPcopy Create free account
hub / github.com/aguinet/dragonffi / getBTyPortableFormatDescriptor

Function getBTyPortableFormatDescriptor

bindings/python/cobj.cpp:374–417  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

372 return "P";
373}
374std::string getBTyPortableFormatDescriptor(BasicType const* BTy)
375{
376 // We only used defined formats that have a standard size (see
377 // https://docs.python.org/2/library/struct.html)
378 const auto BKind = BTy->getBasicKind();
379 const auto Size = BTy->getSize();
380 switch (BKind) {
381 case BasicType::Float:
382 case BasicType::Double: {
383 if (Size == 4) return "f";
384 if (Size == 8) return "d";
385 break;
386 }
387#define HANDLE_BTY(CTy, F)\
388 case BasicType::getKind<CTy>():\
389 return F;
390 HANDLE_BTY(uint8_t, "B")
391 HANDLE_BTY(int8_t, "b")
392 HANDLE_BTY(uint16_t, "H")
393 HANDLE_BTY(int16_t, "h")
394 HANDLE_BTY(uint32_t, "I")
395 HANDLE_BTY(int32_t, "i")
396 HANDLE_BTY(uint64_t, "Q")
397 HANDLE_BTY(int64_t, "q")
398 default:
399 break;
400 }
401
402 const bool IsSigned = BTy->isSignedInteger();
403 switch (Size) {
404 case 1:
405 return IsSigned ? "b":"B";
406 case 2:
407 return IsSigned ? "h":"H";
408 case 4:
409 return IsSigned ? "i":"I";
410 case 8:
411 return IsSigned ? "q":"Q";
412 default:
413 break;
414 }
415
416 return std::to_string(Size) + "B";
417}
418
419std::string getPtrPortableFormatDescriptor(PointerType const* PTy)
420{

Callers

nothing calls this directly

Calls 2

isSignedIntegerMethod · 0.80
getSizeMethod · 0.45

Tested by

no test coverage detected