Skip to content

Commit

Permalink
feat(c): modify defineDirectDeclarator rule in C.g4
Browse files Browse the repository at this point in the history
Modify the `defineDirectDeclarator` rule in `C.g4` to only allow a single expression instead of a comma-separated list. This change simplifies the rule and improves readability.

feat(chapi-ast-c): add timing information to CFullIdentListenerTest

Add timing information to the `CFullIdentListenerTest` class in order to measure the execution time of the analysis process. This helps to identify slow macro processing and optimize performance.

feat(chapi-ast-c): add SlowMacro.c test resource

Add a new test resource file, `SlowMacro.c`, which contains Windows-specific code for handling thread attachment and detachment. This file also includes macros for handling TLS (Thread Local Storage) and includes timing information for performance analysis.
  • Loading branch information
phodal committed Jan 31, 2024
1 parent 3fe1789 commit 8536913
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion chapi-ast-c/src/main/antlr/C.g4
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ directDeclarator
| '(' typeSpecifier? pointer directDeclarator ')' #functionPointerDirectDeclarator // function pointer like: (__cdecl *f)
//singleLineMacroDeclaration
// #define KUMAX(x) ((uintmax_t)x##ULL)
| '#' '#'? macroKeywords? expression* (',' (expression | directDeclarator))* #defineDirectDeclarator
| '#' '#'? macroKeywords? expression #defineDirectDeclarator
// #define KUMAX(x) ((uintmax_t)x##ULL)
// | '#' Identifier #macroCastDeclarator
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ internal class CFullIdentListenerTest {
// val content = "/Users/phodal/Downloads/redis-unstable/deps/jemalloc/src"
File(content).walkTopDown().forEach {
if (it.isFile && (it.extension == "c" || it.extension == "h")) {
val start = System.currentTimeMillis()
println("Analyse ${it.path}")
CAnalyser().analysis(it.readText(), it.name)
val end = System.currentTimeMillis()
val seconds = (end - start) / 1000
println("cost ${end - start}ms ~ ${seconds}s")
}
}
}
Expand Down
36 changes: 36 additions & 0 deletions chapi-ast-c/src/test/resources/realworld/SlowMacro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifdef _WIN32
static BOOL WINAPI
_tls_callback(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
switch (fdwReason) {
#ifdef JEMALLOC_LAZY_LOCK
case DLL_THREAD_ATTACH:
isthreaded = true;
break;
#endif
case DLL_THREAD_DETACH:
_malloc_thread_cleanup();
break;
default:
break;
}
return true;
}

#ifdef read
# undef read
#endif

#ifdef _MSC_VER
# ifdef _M_IX86
# pragma comment(linker, "/INCLUDE:__tls_used")
# pragma comment(linker, "/INCLUDE:_tls_callback")
# else
# pragma comment(linker, "/INCLUDE:_tls_used")
# pragma comment(linker, "/INCLUDE:" STRINGIFY(tls_callback) )
# endif
# pragma section(".CRT$XLY",long,read)
#endif
JEMALLOC_SECTION(".CRT$XLY") JEMALLOC_ATTR(used)
BOOL (WINAPI *const tls_callback)(HINSTANCE hinstDLL,
DWORD fdwReason, LPVOID lpvReserved) = _tls_callback;
#endif

0 comments on commit 8536913

Please sign in to comment.