llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.24k stars 12.07k forks source link

TI (Texas Instruments) C2000 Family not supported by clangd language server #114979

Open student433 opened 2 weeks ago

student433 commented 2 weeks ago

1. System Information:

We currently use a CMake project over the TI C2000 MCU and would like to deploy clangd for code analysis. The include paths are picked up by clangd after manually adjusting compile_commands.json flags for them to be recognized by clangd. Since predefined macros are picked up by clangd using target information, we are at a dead end situation as there is currently no support for the TI C2000 Family. We currently use the triple target definition msp430-none-eabi for a little help as it also comes from TI and resolve some basic pre-defines but we are still far away from our destination.

Hence, my questions are:

C:\\ti\\ccs1281\\ccs\\tools\\compiler\\ti-cgt-c2000_22.6.1.LTS\\bin\\cl2000.exe --compile_only --c_file=C:\\Users\\eclipse-workspace\\can_echo\\source\\can_transmit_receive.c -DNDEBUG --include_path=C:\\Users\\eclipse-workspace\\can_echo\\device\\driverlib --include_path=C:\\Users\\eclipse-workspace\\can_echo\\device --include_path=C:\\Users\\eclipse-workspace\\can_echo\\device\\driverlib\\inc --include_path=C:\\Users\\eclipse-workspace\\can_echo\\syscfg --include_path=C:\\ti\\ccs1281\\ccs\\tools\\compiler\\ti-cgt-c2000_22.6.1.LTS\\include -v28 -ml -mt --opt_level=off --define=_FLASH --define=_LAUNCHXL_F2800157 --diag_suppress=10063 --gen_func_subsections=on --abi=eabi --output_file=can_echo.c.obj

Thanks!

efriedma-quic commented 2 weeks ago

Implementing a new target in the clang frontend (excluding support for actually generating code) is relatively easy: you update llvm/include/llvm/TargetParser/Triple.h to parse your triple, then add a file describing your target to clang/lib/Basic/Targets/, then update clang/lib/Basic/Targets.cpp to construct your target.

(If you just need predefines, it's probably simpler to just specify them with "-D", but having a real target lets you mess with other stuff, like the widths of builtin types.)

In terms of upstreaming, I don't think we have any existing targets without a corresponding backend, but I don't think we have a formal policy stating whether we'd accept a target like this. Start a thread on discourse.llvm.org if you want to seriously pursue this.

clangd doesn't have any builtin support for parsing command-line flags in any style besides clang/clang-cl. You'll need to translate the flags yourself.