[PATCH] D154706: [RISCV] Add XLEN width integer type: riscv_int.h

Kito Cheng via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 9 20:01:56 PDT 2023


kito-cheng updated this revision to Diff 538497.
kito-cheng added a comment.

Changes:

- Define __RISCV_INT_H


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154706/new/

https://reviews.llvm.org/D154706

Files:
  clang/lib/Headers/CMakeLists.txt
  clang/lib/Headers/riscv_int.h


Index: clang/lib/Headers/riscv_int.h
===================================================================
--- /dev/null
+++ clang/lib/Headers/riscv_int.h
@@ -0,0 +1,62 @@
+/*===- riscv_int.h - RISC-V: XLEN-width integer type and format conversion --===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===-----------------------------------------------------------------------===
+ */
+
+#ifndef __RISCV_INT_H
+#define __RISCV_INT_H
+
+#include <inttypes.h>
+#include <stdint.h>
+
+#if __riscv_xlen == 32
+typedef int32_t __riscv_int_xlen_t;
+typedef uint32_t __riscv_uint_xlen_t;
+
+#define __RISCV_INT_XLEN_MIN INT32_MIN
+#define __RISCV_INT_XLEN_MAX INT32_MAX
+#define __RISCV_UINT_XLEN_MAX UINT32_MAX
+
+#define __RISCV_PRIdXLEN PRId32
+#define __RISCV_PRIiXLEN PRIi32
+#define __RISCV_PRIoXLEN PRIo32
+#define __RISCV_PRIuXLEN PRIu32
+#define __RISCV_PRIxXLEN PRIx32
+#define __RISCV_PRIXXLEN PRIX32
+
+#define __RISCV_SCNdXLEN SCNd32
+#define __RISCV_SCNiXLEN SCNi32
+#define __RISCV_SCNoXLEN SCNo32
+#define __RISCV_SCNuXLEN SCNu32
+#define __RISCV_SCNxXLEN SCNx32
+
+#elif __riscv_xlen == 64
+typedef int64_t __riscv_int_xlen_t;
+typedef uint64_t __riscv_uint_xlen_t;
+
+#define __RISCV_INT_XLEN_MIN INT64_MIN
+#define __RISCV_INT_XLEN_MAX INT64_MAX
+#define __RISCV_UINT_XLEN_MAX UINT64_MAX
+
+#define __RISCV_PRIdXLEN PRId64
+#define __RISCV_PRIiXLEN PRIi64
+#define __RISCV_PRIoXLEN PRIo64
+#define __RISCV_PRIuXLEN PRIu64
+#define __RISCV_PRIxXLEN PRIx64
+#define __RISCV_PRIXXLEN PRIX64
+
+#define __RISCV_SCNdXLEN SCNd64
+#define __RISCV_SCNiXLEN SCNi64
+#define __RISCV_SCNoXLEN SCNo64
+#define __RISCV_SCNuXLEN SCNu64
+#define __RISCV_SCNxXLEN SCNx64
+
+#else
+#error "Unknown XLEN"
+#endif
+
+#endif
Index: clang/lib/Headers/CMakeLists.txt
===================================================================
--- clang/lib/Headers/CMakeLists.txt
+++ clang/lib/Headers/CMakeLists.txt
@@ -99,6 +99,7 @@
   )
 
 set(riscv_files
+  riscv_int.h
   riscv_ntlh.h
   )
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D154706.538497.patch
Type: text/x-patch
Size: 2144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230710/95bba6f8/attachment-0001.bin>


More information about the cfe-commits mailing list