Commit 5974f95cb7

Andrew Kelley <andrew@ziglang.org>
2020-01-21 07:48:25
add cpus and cpu features to zig targets
1 parent 0c2dde2
Changed files (2)
src-self-hosted/print_targets.zig
@@ -177,6 +177,41 @@ pub fn cmdTargets(
     }
     try jws.endArray();
 
+    try jws.objectField("cpus");
+    try jws.beginObject();
+    inline for (@typeInfo(Target.Arch).Union.fields) |field| {
+        try jws.objectField(field.name);
+        try jws.beginObject();
+        const arch = @unionInit(Target.Arch, field.name, undefined);
+        for (arch.allCpus()) |cpu| {
+            try jws.objectField(cpu.name);
+            try jws.beginArray();
+            for (arch.allFeaturesList()) |feature, i| {
+                if (cpu.features.isEnabled(@intCast(u8, i))) {
+                    try jws.arrayElem();
+                    try jws.emitString(feature.name);
+                }
+            }
+            try jws.endArray();
+        }
+        try jws.endObject();
+    }
+    try jws.endObject();
+
+    try jws.objectField("cpuFeatures");
+    try jws.beginObject();
+    inline for (@typeInfo(Target.Arch).Union.fields) |field| {
+        try jws.objectField(field.name);
+        try jws.beginArray();
+        const arch = @unionInit(Target.Arch, field.name, undefined);
+        for (arch.allFeaturesList()) |feature| {
+            try jws.arrayElem();
+            try jws.emitString(feature.name);
+        }
+        try jws.endArray();
+    }
+    try jws.endObject();
+
     try jws.objectField("native");
     try jws.beginObject();
     {
BRANCH_TODO
@@ -1,5 +0,0 @@
-Finish these thigns before merging teh branch
-
- * zig targets
-   - use non-reflection based cpu detection?
-