nstar icon indicating copy to clipboard operation
nstar copied to clipboard

Target-specific features

Open Mesabloo opened this issue 3 years ago • 0 comments

This is impossible, at such low-level, to handle everything the same way, without inconsistencies across architectures.

This is why #ifdef _WIN32 comes in handy in C: it allows compiling a specific chunk of code only for Windows (it also works for some other OS depending on which preprocessor directive you check). It is also possible to do the same according to the target architecture.

Because this will be useful, e.g. to handle different calling conventions for FFI bindings, target-specific blocks have to be implemented. The syntax would be pretty simple:

<os> ::= 'windows' | 'linux' | 'macos' | 'bsd' | 'any'
<arch> ::= 'x86' | 'amd64' | 'arm' | 'aarch64' | ... | 'any'
<target> ::= <os>-<arch>
<target-block> ::= 'target' <target> '{' <sections> '}'

This allows compiling some chunk of code (either data or instructions) according to the target platform, nicely handling different calling conventions (e.g. everything on the stack for x86, populate registers before for amd64, etc).

We may also want to be able to place those blocks around two or three instructions. The syntax above does not take that in account.

Mesabloo avatar Jan 04 '21 10:01 Mesabloo