From 83f176ba8a3bae5533470aed6a90663653f894b8 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 29 May 2024 11:14:22 -0700 Subject: Add options to speedup compilation. (#4240) * Add options to speedup compilation. * Fix. * Plumb options to DCE pass. * Revert debug change. * Fix regressions. * More optimizations. * more cleanup and fixes. * remove comment. * Fixes. * Another fix. * Fix errors. * Fix errors. * Add comments. --- source/core/slang-common.h | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source/core') diff --git a/source/core/slang-common.h b/source/core/slang-common.h index 9e73b50a9..7d455546a 100644 --- a/source/core/slang-common.h +++ b/source/core/slang-common.h @@ -84,6 +84,26 @@ namespace Slang } } +// SLANG_DEFER +template +class SlangDeferImpl +{ + F f; +public: + SlangDeferImpl(F&& f) + : f(Slang::_Move(f)) + {} + ~SlangDeferImpl() + { + f(); + } +}; + +#ifndef SLANG_DEFER_LAMBDA +#define SLANG_DEFER_LAMBDA(x) auto SLANG_CONCAT(slang_defer_, __LINE__) = SlangDeferImpl(x) +#define SLANG_DEFER(x) auto SLANG_CONCAT(slang_defer_,__LINE__) = SlangDeferImpl([&](){x;}) +#endif + // // Some macros for avoiding boilerplate // TODO: could probably deduce the size with templates, and move the whole -- cgit v1.2.3