Browse Source

[common] add stringify

wangxiaoyao 2 years ago
parent
commit
bc932aa6d6

+ 2 - 2
components/lwp/lwp_syscall.c

@@ -28,11 +28,11 @@
 #include <dfs_select.h>
 #endif
 
+#include "syscall_data.h"
+
 #if (defined(RT_USING_SAL) && defined(SAL_USING_POSIX))
 #include <sys/socket.h>
 
-#include "syscall_data.h"
-
 #define SYSCALL_NET(f)      f
 #else
 #define SYSCALL_NET(f)      SYSCALL_SIGN(sys_notimpl)

+ 2 - 3
components/lwp/syscall_data.h

@@ -10,8 +10,7 @@
 #ifndef __SYSCALL_DATA_H__
 #define __SYSCALL_DATA_H__
 
-#define xstr(x...)	#x
-#define str(x...)	xstr(x)
+#include <rtthread.h>
 
 /**
  * @brief signature for syscall, used to locate syscall metadata.
@@ -28,6 +27,6 @@
  */
 #define SYSCALL_SIGN(func) \
     (void *)func,          \
-        str(func)
+        RT_STRINGIFY(func)
 
 #endif /* __SYSCALL_DATA_H__ */

+ 5 - 0
include/rtdef.h

@@ -118,6 +118,11 @@ typedef rt_base_t                       rt_off_t;       /**< Type for offset */
 #define __ARMCC_GNUC__
 #endif
 
+/* Common Utilities */
+
+#define _RT_STRINGIFY(x...)	#x
+#define RT_STRINGIFY(x...) _RT_STRINGIFY(x)
+
 /* Compiler Related Definitions */
 #if defined(__CC_ARM) || defined(__CLANG_ARM)           /* ARM Compiler */
     #include <stdarg.h>

+ 5 - 9
libcpu/risc-v/t-head/c906/opcode.h

@@ -18,10 +18,6 @@
  * It's painful to port this file, and should be really careful.
  */
 
-#define ___TOSTR(str) #str
-#define __TOSTR(str) ___TOSTR(str)
-#define _TOSTR(str) __TOSTR(str)
-
 /**
  * @brief RISC-V instruction formats
  */
@@ -35,7 +31,7 @@
  * 31      25    20    15      12   7        0
  */
 #define __OPC_INSN_FORMAT_R(opcode, func3, func7, rd, rs1, rs2) \
-    ".insn r "_TOSTR(opcode)","_TOSTR(func3)","_TOSTR(func7)","_TOSTR(rd)","_TOSTR(rs1)","_TOSTR(rs2)
+    ".insn r "RT_STRINGIFY(opcode)","RT_STRINGIFY(func3)","RT_STRINGIFY(func7)","RT_STRINGIFY(rd)","RT_STRINGIFY(rs1)","RT_STRINGIFY(rs2)
 
 /**
  * @brief Xuantie T-HEAD extension ISA format
@@ -54,11 +50,11 @@
 
 #define OPC_ICACHE_IALL         "icache.iall"
 
-#define OPC_DCACHE_CVA(rs1)     "dcache.cva "_TOSTR(rs1)
-#define OPC_DCACHE_IVA(rs1)     "dcache.iva "_TOSTR(rs1)
-#define OPC_DCACHE_CIVA(rs1)    "dcache.civa "_TOSTR(rs1)
+#define OPC_DCACHE_CVA(rs1)     "dcache.cva "RT_STRINGIFY(rs1)
+#define OPC_DCACHE_IVA(rs1)     "dcache.iva "RT_STRINGIFY(rs1)
+#define OPC_DCACHE_CIVA(rs1)    "dcache.civa "RT_STRINGIFY(rs1)
 
-#define OPC_ICACHE_IVA(rs1)     "icache.iva "_TOSTR(rs1)
+#define OPC_ICACHE_IVA(rs1)     "icache.iva "RT_STRINGIFY(rs1)
 #else /* !_TOOLCHAIN_NOT_SUPP_THEAD_ISA_ */
 #define OPC_SYNC                ".long 0x0180000B"
 #define OPC_SYNC_I              ".long 0x01A0000B"