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

Consider use <stdint.h> types or something similar for C output #1237

Open
uxmal opened this issue Jan 5, 2023 · 1 comment
Open

Consider use <stdint.h> types or something similar for C output #1237

uxmal opened this issue Jan 5, 2023 · 1 comment

Comments

@uxmal
Copy link
Owner

uxmal commented Jan 5, 2023

In issue #1234, there was a complaint about the C output files Reko generates not being directly compileable. A contributing factor is that Reko is rendering internal PrimitiveType instances directly. These are not recognized by C compilers as valid code.

A possible solution is to have Reko emit types defined in <stdint.h>. Implementing it would result in:

  • PrimitiveType.Int32 being rendered as int32_t in C
  • PrimitiveType.Int16 rendered as int16_t
  • PrimitiveType.UInt64 rendered as uint64_t
    and so on.

However, there are some types that are not defined in <stdint.h>. There is no equivalent to PrimitiveType.Word32, for instance. Granted, uint32_t could be used to render Word32, but this would result in a surjection of multiple Reko PrimitiveTypes mapping onto the same <stdint.h> types. Perhaps Reko should supply a basictypes.h which contains:

typedef unsigned short int word16_t;
typedef unsigned int word32_t;
typedef unsigned long in word64_t;
typedef float float32_t;
typedef float float64_t;

For platforms with 36-bit words, a basictypes32.h should be generated, containing:

typedef int int18_t;
typedef long int int36_t;
// etc
@kimstik
Copy link

kimstik commented Jan 6, 2023

Or perhaps go further with the C23 feature: _BitInt(N)

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

No branches or pull requests

2 participants