From 63ac06f404db9411dcc3805bc07ad7b732a41a3c Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Tue, 18 Jun 2024 14:42:20 +0200 Subject: [PATCH 1/3] Add a list of tokens that are always indexed Currently, the list consists of arbitrarily selected tokens from c_common_reswords list present in GCC source code. https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/c-family/c-common.cc;h=0341c44a2cd99771c3eeb44878d3df7a9ae816ea;hb=HEAD#l385 --- lib.py | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ update.py | 13 +++---- 2 files changed, 113 insertions(+), 6 deletions(-) diff --git a/lib.py b/lib.py index 3aa245e6..21802e11 100755 --- a/lib.py +++ b/lib.py @@ -169,6 +169,112 @@ def decode(byte_object): b'x' ) +# list of tokens, that are indexed as references even if no definitions are known + +always_indexed_tokens = [ + b'_Alignas', + b'_Alignof', + b'_Atomic', + b'_BitInt', + b'_Bool', + b'_Complex', + b'_Imaginary', + b'_Float16', + b'_Float32', + b'_Float64', + b'_Float128', + b'_Float32x', + b'_Float64x', + b'_Float128x', + b'_Decimal32', + b'_Decimal64', + b'_Decimal128', + b'_Fract', + b'_Accum', + b'_Sat', + b'_Static_assert', + b'_Noreturn', + b'_Generic', + b'_Thread_local', + b'__FUNCTION__', + b'__PRETTY_FUNCTION__', + b'__alignof', + b'__alignof__', + b'__asm', + b'__asm__', + b'__attribute', + b'__attribute__', + b'__auto_type', + b'__builtin_addressof', + b'__builtin_assoc_barrier', + b'__builtin_bit_cast', + b'__builtin_call_with_static_chain', + b'__builtin_choose_expr', + b'__builtin_complex', + b'__builtin_convertvector', + b'__builtin_has_attribute', + b'__builtin_launder', + b'__builtin_shuffle', + b'__builtin_shufflevector', + b'__builtin_stdc_bit_ceil', + b'__builtin_stdc_bit_floor', + b'__builtin_stdc_bit_width', + b'__builtin_stdc_count_ones', + b'__builtin_stdc_count_zeros', + b'__builtin_stdc_first_leading_one', + b'__builtin_stdc_first_leading_zero', + b'__builtin_stdc_first_trailing_one', + b'__builtin_stdc_first_trailing_zero', + b'__builtin_stdc_has_single_bit', + b'__builtin_stdc_leading_ones', + b'__builtin_stdc_leading_zeros', + b'__builtin_stdc_trailing_ones', + b'__builtin_stdc_trailing_zeros', + b'__builtin_tgmath', + b'__builtin_offsetof', + b'__builtin_types_compatible_p', + b'__builtin_va_arg', + b'__complex', + b'__complex__', + b'__const', + b'__const__', + b'__constinit', + b'__decltype', + b'__extension__', + b'__func__', + b'__imag', + b'__imag__', + b'__inline', + b'__inline__', + b'__label__', + b'__null', + b'__real', + b'__real__', + b'__restrict', + b'__restrict__', + b'__signed', + b'__signed__', + b'__thread', + b'__transaction_atomic', + b'__transaction_relaxed', + b'__transaction_cancel', + b'__typeof', + b'__typeof__', + b'__typeof_unqual', + b'__typeof_unqual__', + b'__volatile', + b'__volatile__', + b'__GIMPLE', + b'__PHI', + b'__RTL', + b'alignas', + b'alignof', + b'asm', + b'auto', + b'thread_local', + b'sizeof', +] + def isIdent(bstr): if (len(bstr) < 2 or bstr in blacklist or diff --git a/update.py b/update.py index ae662f93..823ac277 100755 --- a/update.py +++ b/update.py @@ -26,7 +26,7 @@ from threading import Thread, Lock, Event, Condition import lib -from lib import script, scriptLines +from lib import script, scriptLines, always_indexed_tokens import data from data import PathList from find_compatible_dts import FindCompatibleDTS @@ -315,11 +315,12 @@ def update_references(self, idxes): if even: tok = prefix + tok - if (db.defs.exists(tok) and - not ( (idx*idx_key_mod + line_num) in defs_idxes and - defs_idxes[idx*idx_key_mod + line_num] == tok ) and - (family != 'M' or tok.startswith(b'CONFIG_'))): - # We only index CONFIG_??? in makefiles + ref_allowed = db.defs.exists(tok) or (tok in always_indexed_tokens) + # We only index CONFIG_??? in makefiles + config_or_not_makefile = tok.startswith(b'CONFIG_') or family != 'M' + i = idx*idx_key_mod + line_num + + if ref_allowed and defs_idxes.get(i) != tok and config_or_not_makefile: if tok in idents: idents[tok] += ',' + str(line_num) else: From daa92eee80a618a8605d428bea85ed429455f7d3 Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Mon, 8 Jul 2024 15:48:17 +0200 Subject: [PATCH 2/3] Add more tokens to always indexed list Add a list of always indexed prefixes --- lib.py | 68 ++++++++++++++++++++++++++++++------------------------- update.py | 10 +++++--- 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/lib.py b/lib.py index 21802e11..54eb12a5 100755 --- a/lib.py +++ b/lib.py @@ -171,7 +171,8 @@ def decode(byte_object): # list of tokens, that are indexed as references even if no definitions are known -always_indexed_tokens = [ +always_indexed_tokens = set([ +# gcc/c-family/c-common.cc b'_Alignas', b'_Alignof', b'_Atomic', @@ -205,35 +206,6 @@ def decode(byte_object): b'__attribute', b'__attribute__', b'__auto_type', - b'__builtin_addressof', - b'__builtin_assoc_barrier', - b'__builtin_bit_cast', - b'__builtin_call_with_static_chain', - b'__builtin_choose_expr', - b'__builtin_complex', - b'__builtin_convertvector', - b'__builtin_has_attribute', - b'__builtin_launder', - b'__builtin_shuffle', - b'__builtin_shufflevector', - b'__builtin_stdc_bit_ceil', - b'__builtin_stdc_bit_floor', - b'__builtin_stdc_bit_width', - b'__builtin_stdc_count_ones', - b'__builtin_stdc_count_zeros', - b'__builtin_stdc_first_leading_one', - b'__builtin_stdc_first_leading_zero', - b'__builtin_stdc_first_trailing_one', - b'__builtin_stdc_first_trailing_zero', - b'__builtin_stdc_has_single_bit', - b'__builtin_stdc_leading_ones', - b'__builtin_stdc_leading_zeros', - b'__builtin_stdc_trailing_ones', - b'__builtin_stdc_trailing_zeros', - b'__builtin_tgmath', - b'__builtin_offsetof', - b'__builtin_types_compatible_p', - b'__builtin_va_arg', b'__complex', b'__complex__', b'__const', @@ -273,7 +245,41 @@ def decode(byte_object): b'auto', b'thread_local', b'sizeof', -] + +# https://gcc.gnu.org/onlinedocs/gcc/_005f_005fint128.html + b'__int128', + +# https://gcc.gnu.org/onlinedocs/gcc/Floating-Types.html + b'__float80', + b'__ibm128', + +# https://gcc.gnu.org/onlinedocs/gcc/Half-Precision.html + b'__fp16', + +# https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html + b'__flash', + b'__flash1', + b'__flash2', + b'__flash3', + b'__flash4', + b'__flash5', + b'__memx', + b'__far', + b'__regio_symbol', + b'__seg_fs', + b'__seg_gs', +]) + +always_indexed_prefixes = ( + b'__builtin', + +# https://gcc.gnu.org/onlinedocs/gcc/_005f_005fsync-Builtins.html + b'__sync', + +# https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html + b'__atomic', + b'__ATOMIC', +) def isIdent(bstr): if (len(bstr) < 2 or diff --git a/update.py b/update.py index 823ac277..d19f0b68 100755 --- a/update.py +++ b/update.py @@ -26,7 +26,7 @@ from threading import Thread, Lock, Event, Condition import lib -from lib import script, scriptLines, always_indexed_tokens +from lib import script, scriptLines, always_indexed_tokens, always_indexed_prefixes import data from data import PathList from find_compatible_dts import FindCompatibleDTS @@ -315,9 +315,13 @@ def update_references(self, idxes): if even: tok = prefix + tok - ref_allowed = db.defs.exists(tok) or (tok in always_indexed_tokens) + ref_allowed = \ + db.defs.exists(tok) or \ + (tok in always_indexed_tokens) or \ + any(tok.startswith(pref) for pref in always_indexed_prefixes) + # We only index CONFIG_??? in makefiles - config_or_not_makefile = tok.startswith(b'CONFIG_') or family != 'M' + config_or_not_makefile = family != 'M' or tok.startswith(b'CONFIG_') i = idx*idx_key_mod + line_num if ref_allowed and defs_idxes.get(i) != tok and config_or_not_makefile: From 2125c636769a3903085089cdc4240b4defb2abfd Mon Sep 17 00:00:00 2001 From: Franciszek Stachura Date: Wed, 10 Jul 2024 11:17:09 +0200 Subject: [PATCH 3/3] Add more always indexed tokens --- lib.py | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/lib.py b/lib.py index 54eb12a5..f7d20f88 100755 --- a/lib.py +++ b/lib.py @@ -268,6 +268,71 @@ def decode(byte_object): b'__regio_symbol', b'__seg_fs', b'__seg_gs', + +# https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros + b'__is_identifier', + +# https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros + b'__BASE_FILE__', + b'__FILE_NAME__', + b'__COUNTER__', + b'__INCLUDE_LEVEL__', + b'__TIMESTAMP__', + b'__clang__', + b'__clang_major__', + b'__clang_minor__', + b'__clang_patchlevel__', + b'__clang_version__', + b'__clang_literal_encoding__', + b'__clang_wide_literal_encoding__', + +# https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros + b'__datasizeof', + +# https://clang.llvm.org/docs/LanguageExtensions.html#vectors-and-extended-vectors + b'__bf16', + +# https://clang.llvm.org/docs/LanguageExtensions.html#type-trait-primitives + b'__array_rank', + b'__array_extent', + b'__can_pass_in_regs', + b'__reference_binds_to_temporary', + b'__reference_constructs_from_temporary', + b'__reference_converts_from_temporary', + b'__underlying_type', + +# https://clang.llvm.org/docs/LanguageExtensions.html#opencl-features + b'__remove_address_space', + +# https://clang.llvm.org/docs/LanguageExtensions.html#source-location-builtins + b'__LINE__', + b'__FUNCSIG__', + b'__FILE__', + +# https://clang.llvm.org/docs/LanguageExtensions.html#arm-aarch64-language-extensions + b'__dmb', + b'__dsb', + b'__isb', + +# https://en.cppreference.com/w/c/language/attributes + b'deprecated', + b'fallthrough', + b'maybe_unused', + b'nodiscard', + b'noreturn', + b'_Noreturn', + b'unsequenced', + b'reproducible' + +# https://en.cppreference.com/w/cpp/language/attributes + b'noreturn', + b'carries_dependency', + b'likely', + b'unlikely', + b'no_unique_address', + b'assume', + b'indeterminate', + b'optimize_for_synchronized', ]) always_indexed_prefixes = ( @@ -279,6 +344,19 @@ def decode(byte_object): # https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html b'__atomic', b'__ATOMIC', + +# https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros +# https://clang.llvm.org/docs/LanguageExtensions.html#include-file-checking-macros + b'__has', + +# https://clang.llvm.org/docs/LanguageExtensions.html#language-extensions-back-ported-to-previous-standards + b'__cpp', + +# https://clang.llvm.org/docs/LanguageExtensions.html#type-trait-primitives + b'__is', + +# https://clang.llvm.org/docs/LanguageExtensions.html#opencl-features + b'__cl', ) def isIdent(bstr):