Skip to content

Translate-C changes #3984

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

Closed
wants to merge 1 commit into from
Closed

Conversation

frmdstryr
Copy link
Contributor

@frmdstryr frmdstryr commented Dec 26, 2019

This adds/fixes a few things I ran into while translating some MCU headers:

  1. Enables warnings by default and adds a flag to disable it
  2. Adds support for right shift, add, and sub operations
  3. Adds warnings when a macro is not processed
  4. Adds a "format" to the AstNodeIntLiteral so hex / octal format can be retained when translating.

For example

#define PERIPH_BASE               (0x40000000UL) /*!< Base address of : AHB/APB Peripherals                                                   */
#define D3_AHB1PERIPH_BASE       (PERIPH_BASE + 0x18020000UL)
#define RCC_BASE              (D3_AHB1PERIPH_BASE + 0x4400UL)

Now translates to

pub const PERIPH_BASE = @as(c_ulong, 0x40000000);
pub const D3_AHB1PERIPH_BASE = PERIPH_BASE + @as(c_ulong, 0x18020000);
pub const RCC_BASE = D3_AHB1PERIPH_BASE + @as(c_ulong, 0x4400);

vs just

pub const PERIPH_BASE = @as(c_ulong, 1073741824);
// The other's are missing

Edit: Broke some stuff... will reopen if I can fix that.

@daurnimator daurnimator added the translate-c C to Zig source translation feature (@cImport) label Dec 26, 2019
@frmdstryr
Copy link
Contributor Author

Broke some stuff... will reopen if I can fix the errors.

@FireFox317
Copy link
Contributor

FireFox317 commented Dec 27, 2019

There is a PR incoming where all the translate-c code will be in zig instead of in c++. Please try to use that PR and see if your issue is fixed or wait until the self-hosted translate-c is merged (#3973)

@frmdstryr
Copy link
Contributor Author

frmdstryr commented Dec 27, 2019

Still doesn't support + in macros but everything else is in there. Thanks for commenting, I'll try to contribute to that PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
translate-c C to Zig source translation feature (@cImport)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants