[問題] 關於 LLVM 的 APInt 轉換回 unsigned

看板CompilerDev作者 (eopXD)時間2年前 (2021/08/26 14:33), 2年前編輯推噓0(004)
留言4則, 2人參與, 2年前最新討論串1/1
各位大大好, 覺得有 Compiler 版實在是太酷了! 在下有一個關於 APInt 的問題想要請教 >< 根據 APInt 在 doxygen 上的描述: 「APInt is a functional replacement for common case unsigned integer type like "unsigned", "unsigned long" or "uint64_t".」 但是當在 LLVM 想要把 APInt 轉換回 unsigned 這種 plain data type 時, 卻只有 roundToDouble 這種轉換浮點數的函數可以呼叫。 想要得到 unsigned int 就還需要 double -> unsigned 的轉換。 請問是我誤會 APInt 的角色嗎?還是它的設計本來就不想要使用者轉回 unsigned 來做操作? 以上是我的問題,謝謝願意閱讀本文的大大。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.136.183.67 (臺灣) ※ 文章網址: https://www.ptt.cc/bbs/CompilerDev/M.1629959608.A.2D6.html

08/26 14:55, 2年前 , 1F
getRawData() 是你想要的嗎?
08/26 14:55, 1F

08/26 14:56, 2年前 , 2F
因為它可以存超過64bit
08/26 14:56, 2F

08/26 15:13, 2年前 , 3F
小於 64bits 的話可以用 getZExtValue、getSExtValue
08/26 15:13, 3F

08/26 15:13, 2年前 , 4F
所以它有可能要回傳陣列給你,所以它給的是pointer
08/26 15:13, 4F
回 oToToT: 原來如此,當初有看到 getRawData 覺得 prototype 是指標所以沒有細看。 回 Lipraxde: 居然藏身在 Value Characterization 分類底下,這的確可以拿來使用! 謝謝兩位大大的回覆(而且好速! 小弟解惑了! ※ 編輯: eopXD (223.136.183.67 臺灣), 08/26/2021 15:53:58 ※ 編輯: eopXD (223.136.183.67 臺灣), 08/26/2021 15:54:55 ※ 編輯: eopXD (223.136.183.67 臺灣), 08/26/2021 16:00:41
文章代碼(AID): #1X9pMuBM (CompilerDev)