EOS-Q&ACould NOT find WASM (missing: WASM_CLANG WASM_LLC WASM_LLVM_LINK)N() and _nINLINE_ACTION_SENDER N() and _n INLINE_ACTION_SENDER

1
2
3
brew update
brew install git automake libtool boost openssl [email protected] gmp ninja gettext
brew link gettext --force

安装binaryen

1
2
3
4
git clone https://github.com/WebAssembly/binaryen.git
cd binaryen
git checkout tags/1.37.14
cmake . && make

编译llvm支持WASM

1
2
3
4
5
6
7
8
9
mkdir  ~/wasm-compiler
cd ~/wasm-compiler
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/llvm.git
cd llvm/tools
git clone --depth 1 --single-branch --branch release_40 https://github.com/llvm-mirror/clang.git
cd .. && mkdir -p build && cd build
cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX=~/opt/wasm -DLLVM_TARGETS_TO_BUILD= -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD=WebAssembly -DCMAKE_BUILD_TYPE=Release ..
make -j$( sysctl -in machdep.cpu.core_count )
make install

echo “export WASM_LLVM_CONFIG=~/opt/wasm/bin/llvm-config” >> ~/.bash_profile
echo “export WASM_ROOT=~/opt/wasm” >> ~/.bash_profile
echo “export LLVM_DIR=/usr/local/Cellar/[email protected]/4.0.1_1/lib/cmake/llvm” >> ~/.bash_profile

source ~/.bash_profile

N() and _n

N(active) and “active”_n.value is the same, it converts string into base32 string representation of unsigned 64-bit integer. However, the former is deprecated now and the latter is the new standard in the latest eosio.cdt. “active”_n is a little bit different, it is converting string into a name object.

INLINE_ACTION_SENDER

#define INLINE_ACTION_SENDER(…) BOOST_PP_OVERLOAD(INLINE_ACTION_SENDER,VA_ARGS)(VA_ARGS)

1
2
3
在编译阶段把 base32 编码的字符串转换为 uint64_t 数值
contracts/eosiolib/types.hpp
#define N(X) ::eosio::string_to_name(#X)
1
2
封装 uint64_t 数值,去掉数学计算,打印输出 base32 字符串
struct name {...}
1
2
contracts/eosiolib/types.h
typedef uint64_t account_name;