mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 15:05:19 +00:00
![GanJingSaiyan](/assets/img/avatar_default.png)
Add aot binary analysis tool aot-analyzer, samples: ```bash # parse example.aot, and print basic information about AoT file $ ./aot-analyzer -i example.aot # parse example.aot, and print the size of text section of the AoT file $ ./aot-analyzer -t example.aot # compare these two files, and show the difference in function size between them $ ./aot-analyzer -c example.aot example.wasm ``` Signed-off-by: ganjing <ganjing@xiaomi.com>
57 lines
2.0 KiB
C++
57 lines
2.0 KiB
C++
/*
|
|
* Copyright (C) 2024 Xiaomi Corporation. All rights reserved.
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
*/
|
|
|
|
#ifndef STRING_FORMAT_H_
|
|
#define STRING_FORMAT_H_
|
|
|
|
#include <cstdarg>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "config.h"
|
|
|
|
#define PRIstringview "%.*s"
|
|
#define ANALYZER_PRINTF_STRING_VIEW_ARG(x) \
|
|
static_cast<int>((x).length()), (x).data()
|
|
|
|
#define PRItypecode "%s%#x"
|
|
|
|
#define ANALYZER_DEFAULT_SNPRINTF_ALLOCA_BUFSIZE 128
|
|
#define ANALYZER_SNPRINTF_ALLOCA(buffer, len, format) \
|
|
va_list args; \
|
|
va_list args_copy; \
|
|
va_start(args, format); \
|
|
va_copy(args_copy, args); \
|
|
char fixed_buf[ANALYZER_DEFAULT_SNPRINTF_ALLOCA_BUFSIZE]; \
|
|
char *buffer = fixed_buf; \
|
|
size_t len = \
|
|
analyzer_vsnprintf(fixed_buf, sizeof(fixed_buf), format, args); \
|
|
va_end(args); \
|
|
if (len + 1 > sizeof(fixed_buf)) { \
|
|
buffer = static_cast<char *>(alloca(len + 1)); \
|
|
len = analyzer_vsnprintf(buffer, len + 1, format, args_copy); \
|
|
} \
|
|
va_end(args_copy)
|
|
|
|
namespace analyzer {
|
|
|
|
inline std::string ANALYZER_PRINTF_FORMAT(1, 2)
|
|
StringPrintf(const char *format, ...)
|
|
{
|
|
va_list args;
|
|
va_list args_copy;
|
|
va_start(args, format);
|
|
va_copy(args_copy, args);
|
|
size_t len = analyzer_vsnprintf(nullptr, 0, format, args) + 1;
|
|
std::vector<char> buffer(len);
|
|
va_end(args);
|
|
analyzer_vsnprintf(buffer.data(), len, format, args_copy);
|
|
va_end(args_copy);
|
|
return std::string(buffer.data(), len - 1);
|
|
}
|
|
|
|
} // namespace analyzer
|
|
#endif
|