kito-cheng created this revision.
kito-cheng added a reviewer: asb.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, 
luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, 
PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, 
shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
kito-cheng requested review of this revision.
Herald added subscribers: cfe-commits, wangpc, eopXD.
Herald added a project: clang.

`riscv_int.h` contain `int_xlen_t`, `uint_xlen_t` and related marco.

See also: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/14


Repository:
  rG LLVM Github Monorepo

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,61 @@
+/*===------ riscv_intrinsic.h - RISC-V  ------------===
+ *
+ * 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
+
+#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
   )
 


Index: clang/lib/Headers/riscv_int.h
===================================================================
--- /dev/null
+++ clang/lib/Headers/riscv_int.h
@@ -0,0 +1,61 @@
+/*===------ riscv_intrinsic.h - RISC-V  ------------===
+ *
+ * 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
+
+#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
   )
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to