Introduce two separate classes of processor detection:
authordeanm@chromium.org <deanm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 5 May 2009 12:06:20 +0000 (12:06 +0000)
committerdeanm@chromium.org <deanm@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 5 May 2009 12:06:20 +0000 (12:06 +0000)
- TARGET, the architecture we will generate code for.
  This is brought it from the build system.
- HOST, the architecture our C++ compiler is building for.
  This is detected automatically based on compiler defines.

This adds macros for 32 or 64 bit, and cleans up some
include conditionals, etc.

Review URL: http://codereview.chromium.org/99355

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1864 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

16 files changed:
SConstruct
src/codegen.h
src/execution.cc
src/frames-inl.h
src/globals.h
src/jsregexp.cc
src/jsregexp.h
src/macro-assembler.h
src/objects.cc
src/utils.h
src/virtual-frame.h
test/cctest/test-regexp.cc
tools/gyp/v8.gyp
tools/v8.xcodeproj/project.pbxproj
tools/visual_studio/arm.vsprops
tools/visual_studio/ia32.vsprops

index ac210d5afa53eb656e3d15e048641312b1a32f95..0c506790e803a9b2ccd2dc1739fa4778a36ac7cd 100644 (file)
@@ -149,13 +149,13 @@ LIBRARY_FLAGS = {
       }
     },
     'arch:ia32': {
-      'CPPDEFINES':   ['V8_ARCH_IA32', 'ILP32']
+      'CPPDEFINES':   ['V8_TARGET_ARCH_IA32']
     },
     'arch:arm': {
-      'CPPDEFINES':   ['V8_ARCH_ARM', 'ILP32']
+      'CPPDEFINES':   ['V8_TARGET_ARCH_ARM']
     },
     'arch:x64': {
-      'CPPDEFINES':   ['V8_ARCH_X64', 'LP64']
+      'CPPDEFINES':   ['V8_TARGET_ARCH_X64']
     },
     'prof:oprofile': {
       'CPPDEFINES':   ['ENABLE_OPROFILE_AGENT']
@@ -173,7 +173,7 @@ LIBRARY_FLAGS = {
       'CCPDBFLAGS':   ['/Zi']
     },
     'arch:ia32': {
-      'CPPDEFINES':   ['V8_ARCH_IA32']
+      'CPPDEFINES':   ['V8_TARGET_ARCH_IA32']
     },
     'mode:debug': {
       'CCFLAGS':      ['/Od', '/Gm'],
@@ -239,7 +239,7 @@ V8_EXTRA_FLAGS = {
       'LIBS': ['winmm', 'ws2_32']
     },
     'arch:arm': {
-      'CPPDEFINES':   ['V8_ARCH_ARM'],
+      'CPPDEFINES':   ['V8_TARGET_ARCH_ARM'],
       # /wd4996 is to silence the warning about sscanf
       # used by the arm simulator.
       'WARNINGFLAGS': ['/wd4996']
@@ -348,7 +348,7 @@ CCTEST_EXTRA_FLAGS = {
       'CPPDEFINES': ['USING_V8_SHARED']
     },
     'arch:ia32': {
-      'CPPDEFINES': ['V8_ARCH_IA32']
+      'CPPDEFINES': ['V8_TARGET_ARCH_IA32']
     }
   }
 }
@@ -442,7 +442,7 @@ SAMPLE_FLAGS = {
       }
     },
     'arch:ia32': {
-      'CPPDEFINES':     ['V8_ARCH_IA32']
+      'CPPDEFINES':     ['V8_TARGET_ARCH_IA32']
     },
     'mode:debug': {
       'CCFLAGS':   ['/Od'],
index 3d4599523257e7f4ca32f7163c13d9e0f15163cb..650ce3bf82f6c189d7b1ba01602d76ba14b864c8 100644 (file)
 enum OverwriteMode { NO_OVERWRITE, OVERWRITE_LEFT, OVERWRITE_RIGHT };
 
 
-#ifdef V8_ARCH_ARM
-#include "arm/codegen-arm.h"
-#endif
-
-#ifdef V8_ARCH_X64
-#include "x64/codegen-x64.h"
-#endif
-
-#ifdef V8_ARCH_IA32
+#if V8_TARGET_ARCH_IA32
 #include "ia32/codegen-ia32.h"
+#elif V8_TARGET_ARCH_X64
+#include "x64/codegen-x64.h"
+#elif V8_TARGET_ARCH_ARM
+#include "arm/codegen-arm.h"
 #endif
 
 namespace v8 { namespace internal {
index eb39d640fa7533abb5b8a2b18719df9124cc3cf4..32dde9e4c9de760c05a06caf3ff6f74afef75858 100644 (file)
 #include "api.h"
 #include "codegen-inl.h"
 
-#ifdef V8_ARCH_ARM
-#include "arm/simulator-arm.h"
-#endif
-
-#ifdef V8_ARCH_X64
-#include "x64/simulator-x64.h"
-#endif
-
-#ifdef V8_ARCH_IA32
+#if V8_TARGET_ARCH_IA32
 #include "ia32/simulator-ia32.h"
+#elif V8_TARGET_ARCH_X64
+#include "x64/simulator-x64.h"
+#elif V8_TARGET_ARCH_ARM
+#include "arm/simulator-arm.h"
 #endif
 
 #include "debug.h"
index 8244c672497eccaf62bd6bd94bef18db723ef146..bf46f6bf7b5fbd1a6aef48ef328324e5f54054be 100644 (file)
 #define V8_FRAMES_INL_H_
 
 #include "frames.h"
-#ifdef V8_ARCH_ARM
-#include "arm/frames-arm.h"
-#endif
-
-#ifdef V8_ARCH_X64
-#include "x64/frames-x64.h"
-#endif
 
-#ifdef V8_ARCH_IA32
+#if V8_TARGET_ARCH_IA32
 #include "ia32/frames-ia32.h"
+#elif V8_TARGET_ARCH_X64
+#include "x64/frames-x64.h"
+#elif V8_TARGET_ARCH_ARM
+#include "arm/frames-arm.h"
 #endif
 
-
 namespace v8 { namespace internal {
 
 
index 6436d9d6e4600c4c2e5197cabe5042bbc97038d8..d4f4eee21e67cc4824a13dcb408ae1a9ca66367d 100644 (file)
 
 namespace v8 { namespace internal {
 
+// Processor architecture detection.  For more info on what's defined, see:
+//   http://msdn.microsoft.com/en-us/library/b0084kay.aspx
+//   http://www.agner.org/optimize/calling_conventions.pdf
+//   or with gcc, run: "echo | gcc -E -dM -"
+#if defined(_M_X64) || defined(__x86_64__)
+#define V8_HOST_ARCH_X64 1
+#define V8_HOST_ARCH_64_BIT 1
+#define V8_HOST_CAN_READ_UNALIGNED 1
+#elif defined(_M_IX86) || defined(__i386__)
+#define V8_HOST_ARCH_IA32 1
+#define V8_HOST_ARCH_32_BIT 1
+#define V8_HOST_CAN_READ_UNALIGNED 1
+#elif defined(__ARMEL__)
+#define V8_HOST_ARCH_ARM 1
+#define V8_HOST_ARCH_32_BIT 1
+#else
+#error Your architecture was not detected as supported by v8
+#endif
+
 // Support for alternative bool type. This is only enabled if the code is
 // compiled with USE_MYBOOL defined. This catches some nasty type bugs.
 // For instance, 'bool b = "false";' results in b == true! This is a hidden
@@ -53,22 +72,20 @@ typedef byte* Address;
 // Define our own macros for writing 64-bit constants.  This is less fragile
 // than defining __STDC_CONSTANT_MACROS before including <stdint.h>, and it
 // works on compilers that don't have it (like MSVC).
+#if V8_HOST_ARCH_64_BIT
 #ifdef _MSC_VER
 #define V8_UINT64_C(x)  (x ## UI64)
 #define V8_INT64_C(x)   (x ## I64)
 #else
-#define V8_UINT64_C(x)  (x ## ULL)
-#define V8_INT64_C(x)   (x ## LL)
+#define V8_UINT64_C(x)  (x ## UL)
+#define V8_INT64_C(x)   (x ## L)
 #endif
+#endif  // V8_HOST_ARCH_64_BIT
 
 // Code-point values in Unicode 4.0 are 21 bits wide.
 typedef uint16_t uc16;
 typedef int32_t uc32;
 
-#if defined(V8_ARCH_IA32) || defined(V8_ARCH_X64)
-#define CAN_READ_UNALIGNED 1
-#endif
-
 // -----------------------------------------------------------------------------
 // Constants
 
@@ -86,7 +103,7 @@ const int kIntSize      = sizeof(int);     // NOLINT
 const int kDoubleSize   = sizeof(double);  // NOLINT
 const int kPointerSize  = sizeof(void*);   // NOLINT
 
-#ifdef V8_ARCH_X64
+#if V8_HOST_ARCH_64_BIT
 const int kPointerSizeLog2 = 3;
 #else
 const int kPointerSizeLog2 = 2;
@@ -123,7 +140,7 @@ const int kBitsPerInt = kIntSize * kBitsPerByte;
 
 // Zap-value: The value used for zapping dead objects.
 // Should be a recognizable hex value tagged as a heap object pointer.
-#ifdef V8_ARCH_X64
+#ifdef V8_HOST_ARCH_64_BIT
 const Address kZapValue =
     reinterpret_cast<Address>(V8_UINT64_C(0xdeadbeedbeadbeed));
 const Address kHandleZapValue =
@@ -493,7 +510,7 @@ F FUNCTION_CAST(Address addr) {
 // exception'.
 //
 // Bit_cast uses the memcpy exception to move the bits from a variable of one
-// type o a variable of another type.  Of course the end result is likely to
+// type of a variable of another type.  Of course the end result is likely to
 // be implementation dependent.  Most compilers (gcc-4.2 and MSVC 2005)
 // will completely optimize bit_cast away.
 //
index 1757f5241c5cc1a37cbc70f2c1471d016df392c8..ebaefc0d7ecd8ac9feb148a50475c498f67e80c6 100644 (file)
 #include "regexp-macro-assembler-irregexp.h"
 #include "regexp-stack.h"
 
-#ifdef V8_ARCH_ARM
-#include "arm/regexp-macro-assembler-arm.h"
-#endif
-
-#ifdef V8_ARCH_X64
-#include "x64/macro-assembler-x64.h"
-#include "x64/regexp-macro-assembler-x64.h"
-#endif
-
-#ifdef V8_ARCH_IA32
+#ifdef V8_TARGET_ARCH_IA32
 #include "ia32/macro-assembler-ia32.h"
 #include "ia32/regexp-macro-assembler-ia32.h"
+#elif V8_TARGET_ARCH_X64
+#include "x64/macro-assembler-x64.h"
+#include "x64/regexp-macro-assembler-x64.h"
+#elif V8_TARGET_ARCH_ARM
+#include "arm/regexp-macro-assembler-arm.h"
 #endif
 
 #include "interpreter-irregexp.h"
@@ -431,13 +427,7 @@ Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp,
   Handle<String> original_subject = subject;
   Handle<FixedArray> regexp(FixedArray::cast(jsregexp->data()));
   if (UseNativeRegexp()) {
-#ifdef V8_ARCH_ARM
-    UNREACHABLE();
-#endif
-#ifdef V8_ARCH_X64
-    UNIMPLEMENTED();
-#endif
-#ifdef V8_ARCH_IA32
+#if V8_TARGET_ARCH_IA32
     RegExpMacroAssemblerIA32::Result res;
     do {
       bool is_ascii = subject->IsAsciiRepresentation();
@@ -461,6 +451,8 @@ Handle<Object> RegExpImpl::IrregexpExec(Handle<JSRegExp> jsregexp,
         || res == RegExpMacroAssemblerIA32::FAILURE);
 
     rc = (res == RegExpMacroAssemblerIA32::SUCCESS);
+#else
+    UNREACHABLE();
 #endif
   } else {
     bool is_ascii = subject->IsAsciiRepresentation();
@@ -2521,7 +2513,7 @@ void LoopChoiceNode::Emit(RegExpCompiler* compiler, Trace* trace) {
 
 int ChoiceNode::CalculatePreloadCharacters(RegExpCompiler* compiler) {
   int preload_characters = EatsAtLeast(4, 0);
-#ifdef CAN_READ_UNALIGNED
+#ifdef V8_HOST_CAN_READ_UNALIGNED
   bool ascii = compiler->ascii();
   if (ascii) {
     if (preload_characters > 4) preload_characters = 4;
@@ -4445,13 +4437,13 @@ RegExpEngine::CompilationResult RegExpEngine::Compile(RegExpCompileData* data,
   NodeInfo info = *node->info();
 
   if (RegExpImpl::UseNativeRegexp()) {
-#ifdef V8_ARCH_ARM
+#ifdef V8_TARGET_ARCH_ARM
     UNREACHABLE();
 #endif
-#ifdef V8_ARCH_X64
+#ifdef V8_TARGET_ARCH_X64
     UNREACHABLE();
 #endif
-#ifdef V8_ARCH_IA32
+#ifdef V8_TARGET_ARCH_IA32
     RegExpMacroAssemblerIA32::Mode mode;
     if (is_ascii) {
       mode = RegExpMacroAssemblerIA32::ASCII;
index c0d50a3088da11b439f83797fbf3b76f199cf100..9fa0ecef0f716ee88aed1af24447b431a116793b 100644 (file)
@@ -37,14 +37,10 @@ class RegExpMacroAssembler;
 class RegExpImpl {
  public:
   static inline bool UseNativeRegexp() {
-#ifdef V8_ARCH_ARM
-    return false;
-#endif
-#ifdef V8_ARCH_X64
-    return false;
-#endif
-#ifdef V8_ARCH_IA32
+#ifdef V8_TARGET_ARCH_IA32
     return FLAG_regexp_native;
+#else
+  return false;
 #endif
   }
   // Creates a regular expression literal in the old space.
index 2d93dac841225ddce816afed6d53d48399f8f4d1..116381bb3164c5fc42f5b2955180f945598d6e7c 100644 (file)
 #ifndef V8_MACRO_ASSEMBLER_H_
 #define V8_MACRO_ASSEMBLER_H_
 
-#ifdef V8_ARCH_ARM
-#include "arm/constants-arm.h"
+#if V8_TARGET_ARCH_IA32
 #include "assembler.h"
-#include "arm/assembler-arm.h"
-#include "arm/assembler-arm-inl.h"
+#include "ia32/assembler-ia32.h"
+#include "ia32/assembler-ia32-inl.h"
 #include "code.h"  // must be after assembler_*.h
-#include "arm/macro-assembler-arm.h"
-#endif
-
-#ifdef V8_ARCH_X64
+#include "ia32/macro-assembler-ia32.h"
+#elif V8_TARGET_ARCH_X64
 #include "assembler.h"
 #include "x64/assembler-x64.h"
 #include "x64/assembler-x64-inl.h"
 #include "code.h"  // must be after assembler_*.h
 #include "x64/macro-assembler-x64.h"
-#endif
-
-#ifdef V8_ARCH_IA32
+#elif V8_TARGET_ARCH_ARM
+#include "arm/constants-arm.h"
 #include "assembler.h"
-#include "ia32/assembler-ia32.h"
-#include "ia32/assembler-ia32-inl.h"
+#include "arm/assembler-arm.h"
+#include "arm/assembler-arm-inl.h"
 #include "code.h"  // must be after assembler_*.h
-#include "ia32/macro-assembler-ia32.h"
+#include "arm/macro-assembler-arm.h"
 #endif
 
 #endif  // V8_MACRO_ASSEMBLER_H_
index 5f098339d959a3f521b13756ab2d89ef15030b4a..d9ffb693dc3bbba3777a205e6cf2a1c9dfde6b7f 100644 (file)
@@ -4089,7 +4089,7 @@ static inline bool CompareRawStringContents(Vector<Char> a, Vector<Char> b) {
   const Char* pa = a.start();
   const Char* pb = b.start();
   int i = 0;
-#ifndef CAN_READ_UNALIGNED
+#ifndef V8_HOST_CAN_READ_UNALIGNED
   // If this architecture isn't comfortable reading unaligned ints
   // then we have to check that the strings are aligned before
   // comparing them blockwise.
@@ -4108,7 +4108,7 @@ static inline bool CompareRawStringContents(Vector<Char> a, Vector<Char> b) {
         return false;
       }
     }
-#ifndef CAN_READ_UNALIGNED
+#ifndef V8_HOST_CAN_READ_UNALIGNED
   }
 #endif
   // Compare the remaining characters that didn't fit into a block.
index e008c85f59a7799db75e73b1d5adc15886fe8db8..0febe4a8d45e5156544b5efc11534e0d0947c55f 100644 (file)
@@ -527,7 +527,7 @@ class StringBuilder {
 template <typename sourcechar, typename sinkchar>
 static inline void CopyChars(sinkchar* dest, const sourcechar* src, int chars) {
   sinkchar* limit = dest + chars;
-#ifdef CAN_READ_UNALIGNED
+#ifdef V8_HOST_CAN_READ_UNALIGNED
   if (sizeof(*dest) == sizeof(*src)) {
     // Number of characters in a uint32_t.
     static const int kStepSize = sizeof(uint32_t) / sizeof(*dest);  // NOLINT
index 8c76f8a16b5f2ed5538fc7366de394ee07eaaea6..794f1567c3c991ec7f06d19f2386a751c687d19b 100644 (file)
@@ -202,16 +202,12 @@ class FrameElement BASE_EMBEDDED {
 
 } }  // namespace v8::internal
 
-#ifdef V8_ARCH_ARM
-#include "arm/virtual-frame-arm.h"
-#endif
-
-#ifdef V8_ARCH_X64
-#include "x64/virtual-frame-x64.h"
-#endif
-
-#ifdef V8_ARCH_IA32
+#if V8_TARGET_ARCH_IA32
 #include "ia32/virtual-frame-ia32.h"
+#elif V8_TARGET_ARCH_X64
+#include "x64/virtual-frame-x64.h"
+#elif V8_TARGET_ARCH_ARM
+#include "arm/virtual-frame-arm.h"
 #endif
 
 #endif  // V8_VIRTUAL_FRAME_H_
index ac75999d07f6290a3374ac11480f9547ec71b4f3..22bcdf3477e4fc9cdc42ae5f0c3d197095a04379 100644 (file)
 #include "jsregexp-inl.h"
 #include "regexp-macro-assembler.h"
 #include "regexp-macro-assembler-irregexp.h"
-#ifdef V8_ARCH_ARM
+#ifdef V8_TARGET_ARCH_ARM
 #include "arm/regexp-macro-assembler-arm.h"
 #endif
-#ifdef V8_ARCH_X64
+#ifdef V8_TARGET_ARCH_X64
 // No X64-implementation yet.
 #endif
-#ifdef V8_ARCH_IA32
+#ifdef V8_TARGET_ARCH_IA32
 #include "ia32/macro-assembler-ia32.h"
 #include "ia32/regexp-macro-assembler-ia32.h"
 #endif
@@ -661,7 +661,7 @@ TEST(MacroAssembler) {
 }
 
 
-#ifdef V8_ARCH_IA32  // IA32 only tests.
+#ifdef V8_TARGET_ARCH_IA32  // IA32 only tests.
 
 class ContextInitializer {
  public:
index f8d9043a4ac56bcfd4df059d09ac2efef2cef345..e980ff1671dacd6fc273a0ab7b42ce9a32bca383 100644 (file)
       'target_name': 'v8_base',
       'type': '<(library)',
       'defines': [
-        'V8_ARCH_IA32'
+        'V8_TARGET_ARCH_IA32'
       ],
       'include_dirs+': [
         '../../src',
       'target_name': 'v8_nosnapshot',
       'type': '<(library)',
       'defines': [
-        'V8_ARCH_IA32'
+        'V8_TARGET_ARCH_IA32'
       ],
       'dependencies': [
         'js2c',
       'target_name': 'v8',
       'type': '<(library)',
       'defines': [
-        'V8_ARCH_IA32'
+        'V8_TARGET_ARCH_IA32'
       ],
       'dependencies': [
         'js2c',
       'target_name': 'v8_shell',
       'type': 'executable',
       'defines': [
-        'V8_ARCH_IA32'
+        'V8_TARGET_ARCH_IA32'
       ],
       'dependencies': [
         'v8',
         'v8',
       ],
       'defines': [
-        'V8_ARCH_IA32'
+        'V8_TARGET_ARCH_IA32'
       ],
       'include_dirs': [
         '../../src',
         'js2c',
       ],
       'defines': [
-        'V8_ARCH_ARM',
+        'V8_TARGET_ARCH_ARM',
       ],
       'include_dirs+': [
         '../../src',
         'v8_arm',
       ],
       'defines': [
-        'V8_ARCH_ARM',
+        'V8_TARGET_ARCH_ARM',
       ],
       'sources': [
         '../../samples/shell.cc',
         'v8_arm',
       ],
       'defines': [
-        'V8_ARCH_ARM',
+        'V8_TARGET_ARCH_ARM',
       ],
       'include_dirs': [
         '../../src',
index c8684879b4a0a0a0d6fc27eeb0c3b336fe74b301..83212fb423d2776c27377bb50d09398be3477f38 100755 (executable)
                        buildSettings = {
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(GCC_PREPROCESSOR_DEFINITIONS)",
-                                       V8_ARCH_IA32,
+                                       V8_TARGET_ARCH_IA32,
                                        DEBUG,
                                );
                                HEADER_SEARCH_PATHS = ../src;
                        buildSettings = {
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(GCC_PREPROCESSOR_DEFINITIONS)",
-                                       V8_ARCH_IA32,
+                                       V8_TARGET_ARCH_IA32,
                                        NDEBUG,
                                );
                                HEADER_SEARCH_PATHS = ../src;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(GCC_PREPROCESSOR_DEFINITIONS)",
                                        ENABLE_DISASSEMBLER,
-                                       V8_ARCH_IA32,
+                                       V8_TARGET_ARCH_IA32,
                                        ENABLE_LOGGING_AND_PROFILING,
                                );
                                HEADER_SEARCH_PATHS = ../src;
                                DEPLOYMENT_POSTPROCESSING = NO;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(GCC_PREPROCESSOR_DEFINITIONS)",
-                                       V8_ARCH_IA32,
+                                       V8_TARGET_ARCH_IA32,
                                        NDEBUG,
                                );
                                HEADER_SEARCH_PATHS = ../src;
                                DEPLOYMENT_POSTPROCESSING = NO;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(GCC_PREPROCESSOR_DEFINITIONS)",
-                                       V8_ARCH_ARM,
+                                       V8_TARGET_ARCH_ARM,
                                        ENABLE_DISASSEMBLER,
                                        ENABLE_LOGGING_AND_PROFILING,
                                );
                                DEPLOYMENT_POSTPROCESSING = NO;
                                GCC_PREPROCESSOR_DEFINITIONS = (
                                        "$(GCC_PREPROCESSOR_DEFINITIONS)",
-                                       V8_ARCH_ARM,
+                                       V8_TARGET_ARCH_ARM,
                                );
                                HEADER_SEARCH_PATHS = ../src;
                                PRODUCT_NAME = "v8-arm";
index 4f0f4e343672f1d3db668727abf95b67161bcee2..3aa937448ec82bc43429ae45d015c47d6c2e263d 100644 (file)
@@ -6,7 +6,7 @@
        >
        <Tool
                Name="VCCLCompilerTool"
-               PreprocessorDefinitions="V8_ARCH_ARM"
+               PreprocessorDefinitions="V8_TARGET_ARCH_ARM"
                DisableSpecificWarnings="4996"
        />
 </VisualStudioPropertySheet>
index 8e02c9445b1334b59544c9b25058c7cb3d2781c0..fda6c32a8b9d93308f2e136f57bc43d251858cb6 100644 (file)
@@ -6,6 +6,6 @@
        >
        <Tool
                Name="VCCLCompilerTool"
-               PreprocessorDefinitions="V8_ARCH_IA32"
+               PreprocessorDefinitions="V8_TARGET_ARCH_IA32"
        />
 </VisualStudioPropertySheet>