Provide initial implementations of Memory and Process concepts for various
authorReid Spencer <rspencer@reidspencer.com>
Sat, 11 Sep 2004 04:59:30 +0000 (04:59 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Sat, 11 Sep 2004 04:59:30 +0000 (04:59 +0000)
platforms.
Implement GetLLVMSuffix function for the Path concept.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16292 91177308-0d34-0410-b5e6-96231b3b80d8

28 files changed:
lib/System/AIX/Memory.cpp [new file with mode: 0644]
lib/System/AIX/Path.cpp
lib/System/AIX/Process.cpp [new file with mode: 0644]
lib/System/Cygwin/Memory.cpp [new file with mode: 0644]
lib/System/Cygwin/Path.cpp
lib/System/Cygwin/Process.cpp [new file with mode: 0644]
lib/System/Darwin/Memory.cpp [new file with mode: 0644]
lib/System/Darwin/Path.cpp
lib/System/Darwin/Process.cpp [new file with mode: 0644]
lib/System/FreeBSD/Memory.cpp [new file with mode: 0644]
lib/System/FreeBSD/Path.cpp
lib/System/FreeBSD/Process.cpp [new file with mode: 0644]
lib/System/Interix/Memory.cpp [new file with mode: 0644]
lib/System/Interix/Path.cpp
lib/System/Interix/Process.cpp [new file with mode: 0644]
lib/System/Linux/Memory.cpp [new file with mode: 0644]
lib/System/Linux/Path.cpp
lib/System/Linux/Process.cpp [new file with mode: 0644]
lib/System/Memory.cpp [new file with mode: 0644]
lib/System/Path.cpp
lib/System/Process.cpp [new file with mode: 0644]
lib/System/SunOS/Memory.cpp [new file with mode: 0644]
lib/System/SunOS/Path.cpp
lib/System/SunOS/Process.cpp [new file with mode: 0644]
lib/System/Win32/Memory.cpp [new file with mode: 0644]
lib/System/Win32/Memory.inc [new file with mode: 0644]
lib/System/Win32/Path.cpp [new file with mode: 0644]
lib/System/Win32/Path.inc [new file with mode: 0644]

diff --git a/lib/System/AIX/Memory.cpp b/lib/System/AIX/Memory.cpp
new file mode 100644 (file)
index 0000000..b4e9a9f
--- /dev/null
@@ -0,0 +1,54 @@
+//===- AIX/Memory.cpp - AIX Memory Implementation ---------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the AIX specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/types.h>
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only AIX specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  if (pa == (void*)-1) {
+    throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    throw std::string("Can't release RWX Memory: ") + sterror(errno);
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index e49a593bc896cd0a0a8d312047321167938d5c8c..aef8e033ecd373864bc28703331ee1ef23b40a27 100644 (file)
@@ -43,6 +43,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "so";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/AIX/Process.cpp b/lib/System/AIX/Process.cpp
new file mode 100644 (file)
index 0000000..53b724a
--- /dev/null
@@ -0,0 +1,22 @@
+//===- AIX/Process.cpp - AIX Process Implementation ----------- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the AIX specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only AIX specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Cygwin/Memory.cpp b/lib/System/Cygwin/Memory.cpp
new file mode 100644 (file)
index 0000000..4c0123b
--- /dev/null
@@ -0,0 +1,54 @@
+//===- Cygwin/Memory.cpp - Cygwin Memory Implementation ---------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Cygwin specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/types.h>
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Cygwin specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  if (pa == (void*)-1) {
+    throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    throw std::string("Can't release RWX Memory: ") + sterror(errno);
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index 658c0cbe43b2fea17860b8c2126c42af40db35a8..5b7d02ff9377986fadef332a8faff32f3b006c9b 100644 (file)
@@ -47,6 +47,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "dll.a";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Cygwin/Process.cpp b/lib/System/Cygwin/Process.cpp
new file mode 100644 (file)
index 0000000..46bcbcc
--- /dev/null
@@ -0,0 +1,22 @@
+//===- Cygwin/Process.cpp - Cygwin Process Implementation ----- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Cygwin specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Cygwin specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Darwin/Memory.cpp b/lib/System/Darwin/Memory.cpp
new file mode 100644 (file)
index 0000000..a6a8883
--- /dev/null
@@ -0,0 +1,62 @@
+//===- Darwin/Memory.cpp - Darwin Memory Implementation ---------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Darwin specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Darwin specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+/// AllocateRWXMemory - Allocate a slab of memory with read/write/execute
+/// permissions.  This is typically used for JIT applications where we want
+/// to emit code to the memory then jump to it.  Getting this type of memory
+/// is very OS specific.
+///
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANON, -1, 0);
+  if (pa == MAP_FAILED) {
+    char msg[MAXPATHLEN];
+    strerror_r(errno, msg, MAXPATHLEN-1);
+    throw std::string("Can't allocate RWX Memory: ") + msg;
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    char msg[MAXPATHLEN];
+    strerror_r(errno, msg, MAXPATHLEN-1);
+    throw std::string("Can't release RWX Memory: ") + msg;
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index 165bbc64b5ee24457293cbe8d01088aef87b05fd..33d15d1fb97fed2ccd6717b1999e5f393c4cc62f 100644 (file)
@@ -43,6 +43,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "dyld";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Darwin/Process.cpp b/lib/System/Darwin/Process.cpp
new file mode 100644 (file)
index 0000000..a9e6c11
--- /dev/null
@@ -0,0 +1,22 @@
+//===- Darwin/Process.cpp - Darwin Process Implementation ----- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Darwin specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Darwin specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/FreeBSD/Memory.cpp b/lib/System/FreeBSD/Memory.cpp
new file mode 100644 (file)
index 0000000..16fa849
--- /dev/null
@@ -0,0 +1,53 @@
+//===- FreeBSD/Memory.cpp - FreeBSD Memory Implementation -------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the FreeBSD specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only FreeBSD specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANON|MAP_NOCORE, -1, 0);
+  if (pa == (void*)-1) {
+    throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    throw std::string("Can't release RWX Memory: ") + sterror(errno);
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index 3722b1e6a57e2611d92f2d2bab8075b807e405f1..61b25024b1ec6be0003e8335f7a95ffa40f63bab 100644 (file)
@@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "so";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/FreeBSD/Process.cpp b/lib/System/FreeBSD/Process.cpp
new file mode 100644 (file)
index 0000000..92341c0
--- /dev/null
@@ -0,0 +1,22 @@
+//===- FreeBSD/Process.cpp - FreeBSD Process Implementation --- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the FreeBSD specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only FreeBSD specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Interix/Memory.cpp b/lib/System/Interix/Memory.cpp
new file mode 100644 (file)
index 0000000..b0791ef
--- /dev/null
@@ -0,0 +1,53 @@
+//===- Interix/Memory.cpp - Interix Memory Implementation -------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Interix specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Interix specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANON|MAP_NOCORE, -1, 0);
+  if (pa == (void*)-1) {
+    throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    throw std::string("Can't release RWX Memory: ") + sterror(errno);
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index ea009e232ded6a1d9d2b9fe1300d813df0218ca9..47f6c5d7db1610593572cef4393088cdd8ad3da6 100644 (file)
@@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "dll";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Interix/Process.cpp b/lib/System/Interix/Process.cpp
new file mode 100644 (file)
index 0000000..2890a78
--- /dev/null
@@ -0,0 +1,22 @@
+//===- Interix/Process.cpp - Interix Process Implementation --- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Interix specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Interix specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Linux/Memory.cpp b/lib/System/Linux/Memory.cpp
new file mode 100644 (file)
index 0000000..1bc6fd9
--- /dev/null
@@ -0,0 +1,62 @@
+//===- Linux/Memory.cpp - Linux Memory Implementation -----*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Linux specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Linux specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+/// AllocateRWXMemory - Allocate a slab of memory with read/write/execute
+/// permissions.  This is typically used for JIT applications where we want
+/// to emit code to the memory then jump to it.  Getting this type of memory
+/// is very OS specific.
+///
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, 0, 0);
+  if (pa == MAP_FAILED) {
+    char msg[MAXPATHLEN];
+    strerror_r(errno, msg, MAXPATHLEN-1);
+    throw std::string("Can't allocate RWX Memory: ") + msg;
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    char msg[MAXPATHLEN];
+    strerror_r(errno, msg, MAXPATHLEN-1);
+    throw std::string("Can't release RWX Memory: ") + msg;
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index 8ec35b3c4a4aad7e3fbb64d16c70f9d146f771ba..665c272841e81499a79e011241f41945908fe0e6 100644 (file)
@@ -45,6 +45,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "so";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Linux/Process.cpp b/lib/System/Linux/Process.cpp
new file mode 100644 (file)
index 0000000..a779f70
--- /dev/null
@@ -0,0 +1,22 @@
+//===- Linux/Process.cpp - Linux Process Implementation ------- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Linux specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/SUS/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Linux specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Memory.cpp b/lib/System/Memory.cpp
new file mode 100644 (file)
index 0000000..6aa5cbc
--- /dev/null
@@ -0,0 +1,30 @@
+//===- Memory.cpp - Memory Handling Support ---------------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file defines some helpful functions for allocating memory and dealing
+// with memory mapped files
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/System/Memory.h"
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only TRULY operating system
+//===          independent code. 
+//===----------------------------------------------------------------------===//
+
+}
+
+// Include the platform-specific parts of this class.
+#include "platform/Memory.cpp"
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index fd7fd4f665b7fd27b3f1e93b0653fac318f20289..ace8505d6130aa692750d5ccd9c999a0f67621fe 100644 (file)
@@ -21,16 +21,6 @@ using namespace sys;
 //===          independent code. 
 //===----------------------------------------------------------------------===//
 
-bool
-Path::is_file() const {
-  return (is_valid() && path[path.length()-1] != '/');
-}
-
-bool
-Path::is_directory() const {
-  return (is_valid() && path[path.length()-1] == '/');
-}
-
 }
 
 // Include the truly platform-specific parts of this class.
diff --git a/lib/System/Process.cpp b/lib/System/Process.cpp
new file mode 100644 (file)
index 0000000..aba9bfa
--- /dev/null
@@ -0,0 +1,29 @@
+//===-- Process.cpp - Implement OS Process Concept --------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+//  This header file implements the operating system Process concept.
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/System/Process.h"
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only TRULY operating system
+//===          independent code. 
+//===----------------------------------------------------------------------===//
+
+}
+
+// Include the platform-specific parts of this class.
+#include "platform/Process.cpp"
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/SunOS/Memory.cpp b/lib/System/SunOS/Memory.cpp
new file mode 100644 (file)
index 0000000..dd15f13
--- /dev/null
@@ -0,0 +1,54 @@
+//===- SunOS/Memory.cpp - SunOS Memory Implementation -----------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the SunOS specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic unix implementation
+#include "../Unix/Memory.cpp"
+#include "llvm/System/Process.h"
+#include <sys/types.h>
+#include <sys/mman.h>
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only SunOS specific code 
+//===          and must not be generic UNIX code (see ../Unix/Memory.cpp)
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory& M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  static const long pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+
+  void *pa = mmap(0, pageSize*NumPages, PROT_READ|PROT_WRITE|PROT_EXEC,
+                  MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
+  if (pa == (void*)-1) {
+    throw std::string("Can't allocate RWX Memory: ") + strerror(errno);
+  }
+  M.Address = pa;
+  M.AllocSize = NumPages*pageSize;
+  return pa;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 || M.AllocSize == 0) return;
+  if (0 != munmap(M.Address, M.AllocSize)) {
+    throw std::string("Can't release RWX Memory: ") + sterror(errno);
+  }
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index 3499d525874ad648ffa4731c6d719177dd09eaa0..4ba83ff89ee856a402b57defe0b8acb7106d4ffb 100644 (file)
@@ -47,6 +47,11 @@ Path::GetTemporaryDirectory() {
   return result;
 }
 
+std::string
+Path::GetDLLSuffix() {
+  return "so";
+}
+
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/SunOS/Process.cpp b/lib/System/SunOS/Process.cpp
new file mode 100644 (file)
index 0000000..f8b11b0
--- /dev/null
@@ -0,0 +1,22 @@
+//===- SunOS/Process.cpp - SunOS Process Implementation ------- -*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the SunOS specific implementation of the Process class.
+//
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Process.cpp"
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only SunOS specific code 
+//===          and must not be generic UNIX code (see ../Unix/Process.cpp)
+//===----------------------------------------------------------------------===//
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Win32/Memory.cpp b/lib/System/Win32/Memory.cpp
new file mode 100644 (file)
index 0000000..8a9ae05
--- /dev/null
@@ -0,0 +1,44 @@
+//===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Win32 specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+#include <llvm/System/Process.h>
+#include "windows.h"
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Win32 specific code.
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory&M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  unsigned pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+  void *P = VirtualAlloc(0, NumPages*pageSize, MEM_COMMIT, 
+                         PAGE_EXECUTE_READWRITE);
+  if (P == 0) {
+    throw std::string("Couldn't allocate ") + utostr(NumBytes) + 
+        " bytes of executable memory!";
+  }
+  M.Address = P;
+  M.AllocSize = NumBytes;
+  return P;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 ) return;
+  VirtualFree(M.Address, M.AllocSize, MEM_DECOMMIT, PAGE_NOACCESS);
+}
diff --git a/lib/System/Win32/Memory.inc b/lib/System/Win32/Memory.inc
new file mode 100644 (file)
index 0000000..8a9ae05
--- /dev/null
@@ -0,0 +1,44 @@
+//===- Win32/Memory.cpp - Win32 Memory Implementation -----------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Win32 specific implementation of various Memory
+// management utilities
+//
+//===----------------------------------------------------------------------===//
+
+#include <llvm/System/Process.h>
+#include "windows.h"
+
+namespace llvm {
+using namespace sys;
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Win32 specific code.
+//===----------------------------------------------------------------------===//
+
+void* Memory::AllocateRWX(Memory&M, unsigned NumBytes) {
+  if (NumBytes == 0) return 0;
+
+  unsigned pageSize = Process::GetPageSize();
+  unsigned NumPages = (NumBytes+pageSize-1)/pageSize;
+  void *P = VirtualAlloc(0, NumPages*pageSize, MEM_COMMIT, 
+                         PAGE_EXECUTE_READWRITE);
+  if (P == 0) {
+    throw std::string("Couldn't allocate ") + utostr(NumBytes) + 
+        " bytes of executable memory!";
+  }
+  M.Address = P;
+  M.AllocSize = NumBytes;
+  return P;
+}
+
+void Memory::ReleaseRWX(Memory& M) {
+  if (M.Address == 0 ) return;
+  VirtualFree(M.Address, M.AllocSize, MEM_DECOMMIT, PAGE_NOACCESS);
+}
diff --git a/lib/System/Win32/Path.cpp b/lib/System/Win32/Path.cpp
new file mode 100644 (file)
index 0000000..1a0eda4
--- /dev/null
@@ -0,0 +1,33 @@
+//===- Win32/Path.cpp - Win32 Path Implementation ---------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Win32 specific implementation of the Path class.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Win32 specific code 
+//===          and must not be generic UNIX code (see ../Unix/Path.cpp)
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Path.cpp"
+
+namespace llvm {
+using namespace sys;
+
+
+std::string
+Path::GetDLLSuffix() {
+  return "dll";
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
diff --git a/lib/System/Win32/Path.inc b/lib/System/Win32/Path.inc
new file mode 100644 (file)
index 0000000..1a0eda4
--- /dev/null
@@ -0,0 +1,33 @@
+//===- Win32/Path.cpp - Win32 Path Implementation ---------------*- C++ -*-===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by Reid Spencer and is distributed under the 
+// University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
+//
+// This file provides the Win32 specific implementation of the Path class.
+//
+//===----------------------------------------------------------------------===//
+
+//===----------------------------------------------------------------------===//
+//=== WARNING: Implementation here must contain only Win32 specific code 
+//===          and must not be generic UNIX code (see ../Unix/Path.cpp)
+//===----------------------------------------------------------------------===//
+
+// Include the generic Unix implementation
+#include "../Unix/Path.cpp"
+
+namespace llvm {
+using namespace sys;
+
+
+std::string
+Path::GetDLLSuffix() {
+  return "dll";
+}
+
+}
+
+// vim: sw=2 smartindent smarttab tw=80 autoindent expandtab