ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.42k stars 2.52k forks source link

Zig - Can't translate C's __asm macro #13968

Open rilysh opened 1 year ago

rilysh commented 1 year ago

Zig Version

0.11.0-dev.746+4832677c3

Steps to Reproduce and Observed Behavior

I was playing with Zig's inline ASM, however, I encountered with this error when trying to use __cpuid_count from cpuid.h Error: unable to translate macro: undefined identifier __asm

const std = @import("std");
const c = @cImport(@cInclude("cpuid.h"));

pub fn count(out:[4] i32, eax: i32, ecx: i32) void {
    c.__cpuid_count(eax, ecx, out[0], out[1], out[2], out[3]);
}

pub fn main() !void {
   var cpu_info:[4] i32 = undefined;
   count(cpu_info, 1, 0);
}

I know there's already asm keyword exists in Zig, and instead of using cpuid.h we can manually pass these with Zig's inline ASM, however, __asm is a quite often occurrence macro in C, and manually reimplementation would be much harder and time-consuming.

Expected Behavior

This error shouldn't happen, and Zig should be able to translate C's __asm.

Banacial commented 1 year ago

Got tons of these errors, when including windows.h

A short overview: Macros

rilysh commented 1 year ago

Zig still lags behind proper C translation support. I'd recommend creating a new issue page instead of using this one. I reported this bug, last year in December and there are no updates on this. Since then I haven't really touched Zig.