if(${LIBRF_COMPILER_SETTING} STREQUAL "msvc") | if(${LIBRF_COMPILER_SETTING} STREQUAL "msvc") | ||||
option(LIBRF_INLINE_STATE "Enable Inline state" OFF) | |||||
option(LIBRF_INLINE_STATE "Enable Inline state" ON) | |||||
elseif ("${LIBRF_COMPILER_SETTING}" STREQUAL "clang_on_msvc") | elseif ("${LIBRF_COMPILER_SETTING}" STREQUAL "clang_on_msvc") | ||||
option(LIBRF_INLINE_STATE "Enable Inline state" OFF) | |||||
option(LIBRF_INLINE_STATE "Enable Inline state" ON) | |||||
elseif(${LIBRF_COMPILER_SETTING} STREQUAL "clang") | elseif(${LIBRF_COMPILER_SETTING} STREQUAL "clang") | ||||
option(LIBRF_INLINE_STATE "Enable Inline state" OFF) | |||||
option(LIBRF_INLINE_STATE "Enable Inline state" ON) | |||||
elseif(${LIBRF_COMPILER_SETTING} STREQUAL "gcc") | elseif(${LIBRF_COMPILER_SETTING} STREQUAL "gcc") | ||||
option(LIBRF_INLINE_STATE "Enable Inline state" OFF) | option(LIBRF_INLINE_STATE "Enable Inline state" OFF) | ||||
else() | else() |
} | } | ||||
//clang : 平均 256 字节 | //clang : 平均 256 字节 | ||||
//msvc : 平均 320 字节(vs2022,17.7.4) | |||||
//msvc : 平均 304 字节(vs2022,17.7.4) | |||||
#if LIBRF_TUTORIAL_STAND_ALONE | #if LIBRF_TUTORIAL_STAND_ALONE | ||||
int main() | int main() |
#ifndef RESUMEF_INLINE_STATE | #ifndef RESUMEF_INLINE_STATE | ||||
#if defined(__clang__) || defined(_MSC_VER) | #if defined(__clang__) || defined(_MSC_VER) | ||||
/* #undef RESUMEF_INLINE_STATE */ | |||||
#define RESUMEF_INLINE_STATE 1 | |||||
#else | #else | ||||
/* #undef RESUMEF_INLINE_STATE */ | |||||
#define RESUMEF_INLINE_STATE 0 | |||||
#endif //defined(__clang__) || defined(_MSC_VER) | #endif //defined(__clang__) || defined(_MSC_VER) | ||||
#endif //RESUMEF_INLINE_STATE | #endif //RESUMEF_INLINE_STATE | ||||
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size; | char* ptr = reinterpret_cast<char*>(h.address()) - _State_size; | ||||
return reinterpret_cast<state_type*>(ptr); | return reinterpret_cast<state_type*>(ptr); | ||||
#elif defined(_MSC_VER) | #elif defined(_MSC_VER) | ||||
char* ptr = reinterpret_cast<char*>(this) - _State_size; | |||||
auto h = coroutine_handle<promise_type>::from_promise(*this); | |||||
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size; | |||||
return reinterpret_cast<state_type*>(ptr); | return reinterpret_cast<state_type*>(ptr); | ||||
#else | #else | ||||
#error "Unknown compiler" | #error "Unknown compiler" |
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size; | char* ptr = reinterpret_cast<char*>(h.address()) - _State_size; | ||||
return reinterpret_cast<state_type*>(ptr); | return reinterpret_cast<state_type*>(ptr); | ||||
#elif defined(_MSC_VER) | #elif defined(_MSC_VER) | ||||
char* ptr = reinterpret_cast<char*>(this) - _State_size; | |||||
auto h = coroutine_handle<promise_type>::from_promise(*reinterpret_cast<promise_type*>(this)); | |||||
char* ptr = reinterpret_cast<char*>(h.address()) - _State_size; | |||||
return reinterpret_cast<state_type*>(ptr); | return reinterpret_cast<state_type*>(ptr); | ||||
//char* ptr = reinterpret_cast<char*>(this) - _State_size; | |||||
//return reinterpret_cast<state_type*>(ptr); | |||||
#else | #else | ||||
#error "Unknown compiler" | #error "Unknown compiler" | ||||
#endif | #endif |
std::cout << " frame ptr=" << frame_ptr << "," << (void*)&frame_ptr << std::endl; | std::cout << " frame ptr=" << frame_ptr << "," << (void*)&frame_ptr << std::endl; | ||||
std::cout << " frame end=" << (void*)((char*)(frame_ptr)+_coro_frame_size()) << std::endl; | std::cout << " frame end=" << (void*)((char*)(frame_ptr)+_coro_frame_size()) << std::endl; | ||||
std::cout << " promise ptr=" << promise << "," << (void*)&promise << std::endl; | |||||
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << std::endl; | |||||
std::cout << " state ptr=" << state << "," << (void*)&state << std::endl; | |||||
std::cout << " promise ptr=" << promise << "," << (void*)&promise << ",offset=" << ((char*)promise - (char*)frame_ptr) << std::endl; | |||||
std::cout << " handle ptr=" << handler.address() << "," << (void*)&handler << ",offset=" << ((char*)handler.address() - (char*)frame_ptr) << std::endl; | |||||
std::cout << " state ptr=" << state << "," << (void*)&state << ",offset=" << ((char*)state - (char*)frame_ptr) << std::endl; | |||||
std::cout << " parent ptr=" << state->get_parent() << std::endl; | std::cout << " parent ptr=" << state->get_parent() << std::endl; | ||||
std::cout << " x=" << x << ", &x=" << std::addressof(x) << std::endl; | std::cout << " x=" << x << ", &x=" << std::addressof(x) << std::endl; |