aboutsummaryrefslogtreecommitdiff
path: root/src/userland.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-01-29 23:33:12 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-01-29 23:33:12 -0500
commita95dce15ae4bd95cfd2266da51ba860cc6524a1b (patch)
treee761ecb74f37ff699d2e1f09d122811b101826e4 /src/userland.cpp
parent800ead2810fa573a7e94979e707a14d4e066ef77 (diff)
parent7ebc624a15c5a01d6bee8eaf9c7487b30ed1904c (diff)
downloadzig-a95dce15ae4bd95cfd2266da51ba860cc6524a1b.tar.gz
zig-a95dce15ae4bd95cfd2266da51ba860cc6524a1b.zip
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'src/userland.cpp')
-rw-r--r--src/userland.cpp58
1 files changed, 57 insertions, 1 deletions
diff --git a/src/userland.cpp b/src/userland.cpp
index 263ef0cbc3..8524be5739 100644
--- a/src/userland.cpp
+++ b/src/userland.cpp
@@ -2,7 +2,8 @@
// src-self-hosted/stage1.zig
#include "userland.h"
-#include "ast_render.hpp"
+#include "util.hpp"
+#include "zig_llvm.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -88,3 +89,58 @@ void stage2_progress_end(Stage2ProgressNode *node) {}
void stage2_progress_complete_one(Stage2ProgressNode *node) {}
void stage2_progress_disable_tty(Stage2Progress *progress) {}
void stage2_progress_update_node(Stage2ProgressNode *node, size_t completed_count, size_t estimated_total_items){}
+
+struct Stage2CpuFeatures {
+ const char *llvm_cpu_name;
+ const char *llvm_cpu_features;
+ const char *builtin_str;
+ const char *cache_hash;
+};
+
+Error stage2_cpu_features_parse(struct Stage2CpuFeatures **out, const char *zig_triple,
+ const char *cpu_name, const char *cpu_features)
+{
+ if (zig_triple == nullptr) {
+ Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
+ result->llvm_cpu_name = ZigLLVMGetHostCPUName();
+ result->llvm_cpu_features = ZigLLVMGetNativeFeatures();
+ result->builtin_str = "arch.getBaselineCpuFeatures();\n";
+ result->cache_hash = "native\n\n";
+ *out = result;
+ return ErrorNone;
+ }
+ if (cpu_name == nullptr && cpu_features == nullptr) {
+ Stage2CpuFeatures *result = allocate<Stage2CpuFeatures>(1, "Stage2CpuFeatures");
+ result->builtin_str = "arch.getBaselineCpuFeatures();\n";
+ result->cache_hash = "\n\n";
+ *out = result;
+ return ErrorNone;
+ }
+
+ const char *msg = "stage0 called stage2_cpu_features_parse with non-null cpu name or features";
+ stage2_panic(msg, strlen(msg));
+}
+
+void stage2_cpu_features_get_cache_hash(const Stage2CpuFeatures *cpu_features,
+ const char **ptr, size_t *len)
+{
+ *ptr = cpu_features->cache_hash;
+ *len = strlen(cpu_features->cache_hash);
+}
+const char *stage2_cpu_features_get_llvm_cpu(const Stage2CpuFeatures *cpu_features) {
+ return cpu_features->llvm_cpu_name;
+}
+const char *stage2_cpu_features_get_llvm_features(const Stage2CpuFeatures *cpu_features) {
+ return cpu_features->llvm_cpu_features;
+}
+void stage2_cpu_features_get_builtin_str(const Stage2CpuFeatures *cpu_features,
+ const char **ptr, size_t *len)
+{
+ *ptr = cpu_features->builtin_str;
+ *len = strlen(cpu_features->builtin_str);
+}
+
+int stage2_cmd_targets(const char *zig_triple) {
+ const char *msg = "stage0 called stage2_cmd_targets";
+ stage2_panic(msg, strlen(msg));
+}