Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support XC8 2.x #3

Open
Elemecca opened this issue Mar 16, 2019 · 3 comments
Open

Support XC8 2.x #3

Elemecca opened this issue Mar 16, 2019 · 3 comments

Comments

@Elemecca
Copy link
Owner

Currently only XC8 v1.x is supported, although v2.x works with the legacy command-line driver (see last paragraph).

In v2.x Microchip switched from their proprietary HI-TECH C frontend to Clang in order to support C99. Rather than implement PIC codegen in LLVM, though, they wrote a translator from LLVM's IR to p-code (the HI-TECH IR), which is then passed through the same code generator as the old HI-TECH frontend. XC8 still includes the HI-TECH C frontend to support older projects.

Some code (M-Stack, notably) that worked under HI-TECH C does not compile in Clang. Also, the LLVM IR translation currently produces larger and less efficient code than the IR generated by HI-TECH C. Many projects have declined to upgrade until some of the kinks are worked out. We will therefore have to support both the HI-TECH C and Clang frontends for the foreseeable future.

v2.x also introduces a new compiler command-line driver, xc8-cc, which uses an option format more in line with Clang and GCC. It supports both C frontends via the -std option: -std=c99 for Clang and -std=c90 or -std=c89 for HI-TECH C. The old command-line driver xc8 is still included. We will need to support both command-line drivers, both so v1.x still works and to support projects already using the v1.x driver who want to upgrade to v2.x without changing their compiler options.

@Elemecca
Copy link
Owner Author

Elemecca commented Mar 16, 2019

It looks like @enbyted has already done some work on this in enbyted@f688dc8

I'm not going to merge that directly as it pushes users to use xc8-cc more aggressively than I'm comfortable with and doesn't provide a way to select the command-line driver, C frontend, or C standard.

I also want to see if I can get CMake to detect xc8-cc as Clang and avoid having to write fully custom compiler support for it.

@Elemecca
Copy link
Owner Author

So apparently xc8-cc, despite being a frontend to Clang, is entirely custom and uses mostly GCC-style options, probably for compatibility with XC16 and XC32. It might be possible to feed CMake pic/bin/clang and have it use its native Clang support, but that seems dangerous. It's probably best to just write custom compiler support.

@enbyted
Copy link
Contributor

enbyted commented Mar 17, 2019

If you have an idea in mind how it should work I'd love to work on it as I'm using this CMake setup with all new projects currently.

It probably isn't feasible to use clang directly, as we'd have to accurately emulate all options set by xc8-cc. However in my limited usage I didn't encounter any command-line incompatibilities with GCC - maybe it would be possible to use slightly modified GCC compiler support?

I've never dug so deep in CMake, but hey, there's a lot to learn!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants