TI C2000 compiler not recognized by VS Code - visual-studio-code

I am trying to set TI C2000 C/C++ compiler (cl2000.exe) in the "compilerPath", but the VS Code says:
Unable to resolve configuration with compilerPath ".../bin/cl2000.exe". Using "cl.exe" instead.
Is there a way to make this work, eg to manually specify where to find include files etc., or compilers other than big ones (gcc, clang) just do not work with VS Code no matter what I do?
I do not need features like debugger, library documentation etc., but I do need intellisense (msvc-x64). I could just use cl.exe as a defined compiler, but it does not recognize some compiler-specific stuff like __attributes__((ramfunc)), it does not use proper <stdint.h> etc.

With the current C/C++ extension (v1.7.1) I don't think what you want is achievable, as it seems it needs to have some kind of integration with the compiler to extract a lot of "hidden" information from it, and currently only Microsoft's C compiler, Clang and GCC are supported (source).
In any case, you can get a lot of functionality working with the right c_cpp_settings.json.
Here's a copy of my current setup for a project on the F280049C. I have the motor control SDK added as a submodule on the project folder, something you might not need. Make sure that you add all the different SDKs and other bits and bobs that are relevant to your project.
For the defines property, I checked the project properties in Code Composer, and then in CSS Build / C2000 Compiler / Predefined Symbols there's a list of defines passed at the command line. There's a bunch of "hidden" defines that I don't know how to get, see my comment in the code below. Take the ones on the example with a pinch of salt, your defines might be different.
The C and C++ standard can be checked in the flags passed in the command line (in my project they are C++03 and C11).
Compiler Path has to be left empty (""), as the extension can't use the C2000 compiler, that's why you get the Unable to resolve configuration with compilerPath ".../bin/cl2000.exe". Using "cl.exe" instead. error. I guess VS Code sees the "cl.exe" compiler, a compiler the C/C++ extension can use (it's Microsoft's VS compiler, maybe the fact that its name is similar to TI's is misleading you there)
About the intelliSense mode, nothing will work with the devilish architecture of the C2000. I prefer to set intelliSense to 32 bits, but that's just as wrong as 64 bits, so pick your poison there. Keep in mind that things like the values of sizeof or pointers will be wrong in VS Code (as you are telling it to treat them as a 32 bit architecture).
Try this config. You will get lots of red squiggly lines under some includes, but most of them should be in your browse path and can be automatically added by clicking in the yellow bulb icon.
{
"env": {
"SDKPath": "${workspaceFolder}/../lib/C2000Ware_MotorControl_SDK_3_01_00_00",
"StdLibPath": "C:/ti/ccs1031/ccs/tools/compiler/ti-cgt-c2000_20.2.5.LTS",
"XDCTools": "C:/ti/ccs1031/xdctools_3_62_00_08_core",
"TIBIOS": "C:/ti/bios_6_83_00_18/packages/"
},
"configurations": [
{
"name": "TI",
"includePath": [
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${StdLibPath}/**",
"${SDKPath}/**",
"${XDCTools}/**",
"${TIBIOS}/**"
]
},
"defines": [
"_F28004x",
"DEBUG",
"_INLINE",
"_FLASH",
"DRV8353_SPI",
// Hidden predefined symbols. They are set by the compiler by default, but
// they are not output on the command line and I haven't found a way to
// list them yet
// needed for STL (see s_c__system.h)
"_STLP_COMPILER",
"__TI_COMPILER_VERSION__"
],
"compilerPath": "",
"cStandard": "c11",
"cppStandard": "c++03",
"intelliSenseMode": "gcc-x86"
}
],
"version": 4
}
Keep in mind that when working with microcontrollers there's a lot of customization to do, but I think this will get you on the good track.

Related

Fortran declarations using PETSc's key words not recognized in VSCode

I'm using VSCode with Modern Fortran+fortls to write Fortran code with PETSc library. The declaration using PETSc's key words seems not being recognized at all. I tried to include the path of PETSc library and header files in .fortls file using include_dirs etc, but it does not resolve the issue. Can anyone give me a hint so the all the keywords and function declarations in PETSc can be handled by fortls? Thanks a lot
I used the following in the .fortls file
{
"source_dirs": ["./**","./src/**",
"/Users/apple/local/petsc/osx-gfc/include/**",
"/Users/apple/local/petsc/include/**",
"/Users/apple/local/petsc/include/petsc/finclude",
"/Users/apple/local/petsc/src/vec/f90-mod",
"/Users/apple/local/petsc/src/ksp/f90-mod",
"/Users/apple/local/petsc/src/vec/f90-mod",
"/Users/apple/local/petsc/src/dm/f90-mod",
"/Users/apple/local/petsc/src/mat/f90-mod"
],
"include_dirs": ["./include/**",
"/Users/apple/local/petsc/osx-gfc/include/**",
"/Users/apple/local/petsc/include/**",
"/Users/apple/local/petsc/include/petsc/finclude/",
"/Users/apple/local/petsc/src/ksp/f90-mod",
"/Users/apple/local/petsc/src/vec/f90-mod",
"/Users/apple/local/petsc/src/snes/f90-mod"
],
"ext_source_dirs": ["/Users/apple/local/petsc/src/snes/f90-mod/",
"/Users/apple/local/petsc/src/sys/f90-mod/",
"/Users/apple/local/petsc/osx-gfc/include/**",
"/Users/apple/local/petsc/src/vec/f90-mod",
"/Users/apple/local/petsc/src/dm/f90-mod",
"/Users/apple/local/petsc/src/mat/f90-mod",
"/Users/apple/local/petsc/src/ksp/f90-mod",
"/Users/apple/local/petsc/src/vec/f90-mod"
],
"hover_language": "fortran90",
"hover_signature": true,
"use_signature_help": true
}
But the type keyword like SNES and KSP are not recognized by the IDE at all.
You need to slightly tweak your language server settings. You are attempting to use the PETSc preprocessor variables without "defining" them in the language server. Parsing files containing preprocessor macros can sometimes be a bit flimsy in the language server.
Assuming you are using fortls you can define preprocessor definitions as shown in the documentation, see: https://gnikit.github.io/fortls/options.html#pp-defs
You should also be able to do that via the VS Code settings.
Beware of this bug (https://github.com/gnikit/fortls/issues/72) where defining a preprocessor macro will override actual fortran tokens like .IF or ELSE
Full disclosure I am the author of fortls and the Modern Fortran vscode extension

MPI Autocompletion in Visual Studio Code

I'm trying to use Visual Studio Code to develop Fortran MPI programs. However, while I can successfully build and run them just fine, it would be very helpful for me if I can use intellisense/autocompletion features for MPI (as well as other external modules). I have /usr/lib/openmpi/ (which contains mpi_f08.mod) as part of fortran.includePaths in my settings.json. However, when I use mpi_f08, I get the problem message from VS Code Module "mpi_f08" not found in project. Here is a minimal CMake build example:
! hello.f90
program hello
use mpi_f08
implicit none
integer :: ierror, nproc, my_rank
call MPI_Init()
call MPI_Comm_size(MPI_COMM_WORLD, nproc, ierror)
call MPI_Comm_rank(MPI_COMM_WORLD, my_rank, ierror)
print*, "hello from rank ", my_rank
call MPI_Finalize()
end program hello
# CMakeLists.txt
cmake_minimum_required(VERSION 3.12)
project(hello_mpi)
enable_language(Fortran)
find_package(MPI REQUIRED)
add_executable(hello_mpi hello.f90)
include_directories(${MPI_Fortran_INCLUDE_PATH})
target_link_libraries(hello_mpi PUBLIC ${MPI_Fortran_LIBRARIES})
I would like to be able to (i) get rid of the warning/message and more importantly (ii) enable suggestions from MPI when I press CTRL+space as it would if I was calling from an internal module.
I'll post a partial answer since it's better than nothing, hopefully this helps someone else and/or enables someone else to answer my question fully.
It seems the issue relates to the Fortran language server, which can be configured by adding a .fortls JSON file, as explained on its Github README: https://github.com/hansec/fortran-language-server
I added the following, which allowed it to find not only local modules but also MPI (and the external module json-fortran):
{
"source_dirs": ["src", "."],
"ext_source_dirs": [
"/path/to/json-fortran/src",
"/path/to/openmpi-4.1.2/ompi/mpi/fortran/use-mpi-f08",
]
}
This doesn't capture all functions in json-fortran, which I think is because of its .inc files, as it doesn't give me function pointers like json_file::get at autocomplete.
As for MPI, this kind of works, as it gives me all the functions I can think of needing, but with _f08 appended to the end of it. I don't know the inner workings of OpenMPI but I guess e.g. MPI_Init wraps MPI_Init_f08 for reasons of backward compatibility. For now I can simply autocomplete to the _f08 version and remove that bit manually. (I also tried adding openmpi-4.1.2/ompi/mpi/fortran/use-mpi-tkr and openmpi-4.1.2/ompi/mpi/fortran/mpif.h but no luck).
Would be nice to get this detail sorted though. It is also mildly annoying that I must manually include the source dirs now (removing it makes it not find local modules).

Configure Visual Studio Code suggestions

What's the best way to identify which Visual Studio Code setting is generating / allowing various suggestions to pop up (so it can be turned off)? In particular I'd like to eliminate these three from ever showing.
Those suggestions are types from the standard library. The TypeScript service that powers VS Code's JavaScript and TypeScript language features loads these types from .d.ts files in order to understand the signatures of standard JavaScript library functions such as parseInt or Promise.
To find out where a type is coming from, try using workspace symbol search (cmdT):
In this case, these types come from the standard lib.d.ts file that TypeScript loads automatically. TypeScript will also automatically load a d.ts file for the DOM api.
To disable these suggestions, create a jsconfig.json at the root of your project with the contents:
{
"compilerOptions": {
"lib": []
}
}
This tells typescript not to include any extra typings files for the core libraries. You can also select which typings you want to include:
{
"compilerOptions": {
"lib": [
"es2015"
]
}
}
See the documentation for a list of valid lib options
If you notice any bugs with this behavior or have any suggestions on how this could be improved, please file an issue against VS Code
Update
To discover where a type suggestion is coming from, you may also be able to write:
/**
* #type {AsyncResultObjectCallback}
*/
var placeholer;
And then run go to type definition on placeholder. Even using "lib": [], you may still be seeing suggestions from #types files or node packages that include d.ts files

Gwt i18n > generating properties files

I'm using GWT in my stuff, and I would like to make it,
international, so I use GWT constants method.
I have a java file with defaults, and I now need to make properties files.
In a remember, there is a special thing to do (or done automagically) to generate
a kind of template where all constants are generated with empty labels for other langages.
Did I dream this ?
(using eclipse indigo to develop webapp with gwt but not gae)
[edit:]
this was not a dream, it's i18ncreator:
http://code.google.com/intl/fr-FR/webtoolkit/doc/latest/RefCommandLineTools.html#i18nCreator
but I can't make it working on windows :-(
[edit again ]
due to this issue : http://code.google.com/p/google-web-toolkit/issues/detail?id=5113
recommended solution is use i18ncreator in gwt 1.7 (!)
you should see the page on locales in GWT
I had the same issue. I was looking all over the place for the answer but could not find an answer; either in the docs or on stackoverflow.
So I asked in the GWT gitter channel and was told to use the compiler argument
-extra <destination-folder-name>
to generate the .properties files from the Interface files.
Steps in eclipse:
Select project you want to compile
[right click] -> Google -> GWT Compile
In the window that opens, open the Advanded options.
Add the following additional compiler argument -extra <destination-folder-name>
Compile
This should generate the *.properties files in the /destination-folder-name.
NOTE: This only generates the .properties files. It does not actually compile the application with all the locales for deploy.
Move the MyInterfaceExtension_*.properties to be right beside the MyInterfaceExtension.java file.
Make copies for each locale i.e. MyInterfaceExtension_fr_CA.properties, MyInterfaceExtension_fr_FR.properties, etc..
Translate them
Then run the compilation process again with out the -extra <destination-folder-name> option. Because it is not needed anymore.
This will compile with all the locales you enabled. You can now deploy the app the usual way.
Quick Tips:
When compiling for the first time in order to generate the .properties file, I commented out the locales in the module definition file so that the compiler will not sit there and compile again and again for every browser and every locale
i.e. supported_browser_count x enabled_locale_count = 5 browsers x 3 locales = 15 compilation Permutations, which is going to increase your compilation time.
Because, all I needed was that one *_en.properties file.
For the second compilation, after you copied and translated the properties files for each locale, you have to enable all the locales you want to support and compile.
Credits:
github #niloc132 : Colin Alworth
github #ibaca : Ignacio Baca Moreno-Torres
For helping me with this.
For my project, I used the i18n-Creator
http://code.google.com/webtoolkit/doc/latest/DevGuideI18n.html#DevGuidePropertiesFiles
It kind of does the opposite of what you are asking for. With the i18n-creator, you create the properties files for the various locales and run the script that is generated with the i18n-creator, and it will generate the constants interface.
I haven't heard yet of this feature in Eclipse but IntelliJ IDEA has this feature, you just create the Constants Interface class and the properties file. If you add a method in the class file it will warn you to add the property or the other way around. HTH.

MS VS-2005 Compiler optimization not removing unused/unexecuted code

I have a workspace built using MS-Visual Studio 2005 with all C code.In that i see many functions which are not called but they are still compiled(they are not under any compile time macro to disable them from compiling).
I set following optimization settings for the MS-VS2005 project to remove that unused code:-
Optimization level - /Ox
Enable whole program optimization - /GL
I tried both Favor speed /Ot and Favor Size /Os
Inspite of all these options, when i see the linker generated map file, I see the symbols(unsed functions) names present in the map file.
Am I missing something? I want to completely remove the unused code.
How do I do this?
The compiler compiles C files one-at-a-time. Therefore, while compiling a C-file that does contains an unused function, the compiler cannot be sure that it will not be called from another file and hence it will compile that function too. However, if that function were declared as static (file-scope), then the compiler would know it is not used and hence remove it.
Even with whole program optimization, I think it would still not be done since the compilation could be for a library.
Linkers do something similar to what you are looking for. If your code links against a library containing multiple objects, then any objects that do not contain functions used by your code (directly or indirectly) would not be included in the final executable.
One option would be to separate your code into individual libraries and object files.
PS - This is just my guess. The behavior of the compiler (with whole program optimization) or linker essentially depends on the design choices of that particular compiler or linker
On our projects we have a flag set under the project properties\Linker\Refrences. We set it to Eliminate Unreferenced Data (/OPT:REF), according to the description this is supposed to remove function calls or data that are never used. I am just going by the description, I have never tested this or worked with it. But I just happened to see it within the last hour and figured it might be something you could try.