Fix register printing in disassembling of push/pop of segment registers and in/out...
[oota-llvm.git] / runtime / libprofile / GCDAProfiling.c
index 8ab42276003252aa2ceebda126d982f6e3d6e9e1..ac3a62c79f4bbc7a1e60e5697e72cbc53a59310f 100644 (file)
@@ -26,6 +26,9 @@
 #include <string.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#ifdef _MSC_VER
+#include <direct.h>
+#endif
 
 /* #define DEBUG_GCDAPROFILING */
 
@@ -49,7 +52,7 @@ static void write_int64(uint64_t i) {
 }
 
 static uint32_t length_of_string(const char *s) {
-  return (strlen(s) + 5) / 4;
+  return (strlen(s) / 4) + 1;
 }
 
 static void write_string(const char *s) {
@@ -86,7 +89,11 @@ static void recursive_mkdir(const char *filename) {
       pathname = malloc(i + 1);
       strncpy(pathname, filename, i);
       pathname[i] = '\0';
+#ifdef _WIN32
+      _mkdir(pathname);
+#else
       mkdir(pathname, 0750);  /* some of these will fail, ignore it. */
+#endif
       free(pathname);
     }
   }
@@ -107,7 +114,11 @@ void llvm_gcda_start_file(const char *orig_filename) {
   output_file = fopen(filename, "wb");
 
   /* gcda file, version 404*, stamp LLVM. */
+#ifdef __APPLE__
+  fwrite("adcg*204MVLL", 12, 1, output_file);
+#else
   fwrite("adcg*404MVLL", 12, 1, output_file);
+#endif
 
 #ifdef DEBUG_GCDAPROFILING
   printf("llvmgcda: [%s]\n", orig_filename);