2018-05-15 06:42:07 +08:00
|
|
|
//===-- llvm/BinaryFormat/Wasm.cpp -------------------------------*- C++-*-===//
|
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// 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
|
2018-05-15 06:42:07 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/BinaryFormat/Wasm.h"
|
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
std::string llvm::wasm::toString(wasm::WasmSymbolType Type) {
|
|
|
|
switch (Type) {
|
2018-05-15 06:42:07 +08:00
|
|
|
case wasm::WASM_SYMBOL_TYPE_FUNCTION:
|
|
|
|
return "WASM_SYMBOL_TYPE_FUNCTION";
|
|
|
|
case wasm::WASM_SYMBOL_TYPE_GLOBAL:
|
|
|
|
return "WASM_SYMBOL_TYPE_GLOBAL";
|
2020-10-13 22:13:10 +08:00
|
|
|
case wasm::WASM_SYMBOL_TYPE_TABLE:
|
|
|
|
return "WASM_SYMBOL_TYPE_TABLE";
|
2018-05-15 06:42:07 +08:00
|
|
|
case wasm::WASM_SYMBOL_TYPE_DATA:
|
|
|
|
return "WASM_SYMBOL_TYPE_DATA";
|
|
|
|
case wasm::WASM_SYMBOL_TYPE_SECTION:
|
|
|
|
return "WASM_SYMBOL_TYPE_SECTION";
|
2018-11-14 10:46:21 +08:00
|
|
|
case wasm::WASM_SYMBOL_TYPE_EVENT:
|
|
|
|
return "WASM_SYMBOL_TYPE_EVENT";
|
2018-05-15 06:42:07 +08:00
|
|
|
}
|
|
|
|
llvm_unreachable("unknown symbol type");
|
|
|
|
}
|
|
|
|
|
[WebAssembly] clang-tidy (NFC)
Summary:
This patch fixes clang-tidy warnings on wasm-only files.
The list of checks used is:
`-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,readability-identifier-naming,modernize-*`
(LLVM's default .clang-tidy list is the same except it does not have
`modernize-*`. But I've seen in multiple CLs in LLVM the modernize style
was recommended and code was fixed based on the style, so I added it as
well.)
The common fixes are:
- Variable names start with an uppercase letter
- Function names start with a lowercase letter
- Use `auto` when you use casts so the type is evident
- Use inline initialization for class member variables
- Use `= default` for empty constructors / destructors
- Use `using` in place of `typedef`
Reviewers: sbc100, tlively, aardappel
Subscribers: dschuff, sunfish, jgravelle-google, yurydelendik, kripken, MatzeB, mgorny, rupprecht, llvm-commits
Differential Revision: https://reviews.llvm.org/D57500
llvm-svn: 353075
2019-02-05 03:13:39 +08:00
|
|
|
std::string llvm::wasm::relocTypetoString(uint32_t Type) {
|
|
|
|
switch (Type) {
|
2018-09-05 09:27:38 +08:00
|
|
|
#define WASM_RELOC(NAME, VALUE) \
|
|
|
|
case VALUE: \
|
|
|
|
return #NAME;
|
2018-05-15 06:42:07 +08:00
|
|
|
#include "llvm/BinaryFormat/WasmRelocs.def"
|
|
|
|
#undef WASM_RELOC
|
|
|
|
default:
|
|
|
|
llvm_unreachable("unknown reloc type");
|
|
|
|
}
|
|
|
|
}
|
2019-06-26 08:52:42 +08:00
|
|
|
|
|
|
|
bool llvm::wasm::relocTypeHasAddend(uint32_t Type) {
|
|
|
|
switch (Type) {
|
|
|
|
case R_WASM_MEMORY_ADDR_LEB:
|
2020-06-06 00:03:12 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_LEB64:
|
2019-06-26 08:52:42 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_SLEB:
|
2020-06-06 00:03:12 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_SLEB64:
|
2019-06-26 08:52:42 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_REL_SLEB:
|
2020-06-06 00:03:12 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_REL_SLEB64:
|
2019-06-26 08:52:42 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_I32:
|
2020-06-06 00:03:12 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_I64:
|
2020-11-11 09:46:52 +08:00
|
|
|
case R_WASM_MEMORY_ADDR_TLS_SLEB:
|
2019-06-26 08:52:42 +08:00
|
|
|
case R_WASM_FUNCTION_OFFSET_I32:
|
2020-11-13 07:05:05 +08:00
|
|
|
case R_WASM_FUNCTION_OFFSET_I64:
|
2019-06-26 08:52:42 +08:00
|
|
|
case R_WASM_SECTION_OFFSET_I32:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|