Commit 88dc054f authored by jochen@chromium.org's avatar jochen@chromium.org

Extract common macros and start a base library

BUG=v8:3015
R=svenpanne@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/249183003

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20905 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 4b56570c
// Copyright 2014 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_BASE_MACROS_H_
#define V8_BASE_MACROS_H_
#include "../../include/v8stdint.h"
// The expression OFFSET_OF(type, field) computes the byte-offset
// of the specified field relative to the containing type. This
// corresponds to 'offsetof' (in stddef.h), except that it doesn't
// use 0 or NULL, which causes a problem with the compiler warnings
// we have enabled (which is also why 'offsetof' doesn't seem to work).
// Here we simply use the non-zero value 4, which seems to work.
#define OFFSET_OF(type, field) \
(reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
// The expression ARRAY_SIZE(a) is a compile-time constant of type
// size_t which represents the number of elements of the given
// array. You should only use ARRAY_SIZE on statically allocated
// arrays.
#define ARRAY_SIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) V8_DELETE; \
void operator=(const TypeName&) V8_DELETE
// A macro to disallow all the implicit constructors, namely the
// default constructor, copy constructor and operator= functions.
//
// This should be used in the private: declarations for a class
// that wants to prevent anyone from instantiating it. This is
// especially useful for classes containing only static methods.
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName() V8_DELETE; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// Newly written code should use V8_INLINE and V8_NOINLINE directly.
#define INLINE(declarator) V8_INLINE declarator
#define NO_INLINE(declarator) V8_NOINLINE declarator
// Newly written code should use V8_WARN_UNUSED_RESULT.
#define MUST_USE_RESULT V8_WARN_UNUSED_RESULT
// Define DISABLE_ASAN macros.
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define DISABLE_ASAN __attribute__((no_sanitize_address))
#endif
#endif
#ifndef DISABLE_ASAN
#define DISABLE_ASAN
#endif
#if V8_CC_GNU
#define V8_IMMEDIATE_CRASH() __builtin_trap()
#else
#define V8_IMMEDIATE_CRASH() ((void(*)())0)()
#endif
#endif // V8_BASE_MACROS_H_
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "../include/v8stdint.h" #include "../include/v8stdint.h"
#include "base/macros.h"
// Unfortunately, the INFINITY macro cannot be used with the '-pedantic' // Unfortunately, the INFINITY macro cannot be used with the '-pedantic'
// warning flag and certain versions of GCC due to a bug: // warning flag and certain versions of GCC due to a bug:
// http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931 // http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11931
...@@ -320,25 +322,6 @@ const int kUC16Size = sizeof(uc16); // NOLINT ...@@ -320,25 +322,6 @@ const int kUC16Size = sizeof(uc16); // NOLINT
#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1)) #define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
// The expression OFFSET_OF(type, field) computes the byte-offset
// of the specified field relative to the containing type. This
// corresponds to 'offsetof' (in stddef.h), except that it doesn't
// use 0 or NULL, which causes a problem with the compiler warnings
// we have enabled (which is also why 'offsetof' doesn't seem to work).
// Here we simply use the non-zero value 4, which seems to work.
#define OFFSET_OF(type, field) \
(reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
// The expression ARRAY_SIZE(a) is a compile-time constant of type
// size_t which represents the number of elements of the given
// array. You should only use ARRAY_SIZE on statically allocated
// arrays.
#define ARRAY_SIZE(a) \
((sizeof(a) / sizeof(*(a))) / \
static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
// The USE(x) template is used to silence C++ compiler warnings // The USE(x) template is used to silence C++ compiler warnings
// issued for (yet) unused variables (typically parameters). // issued for (yet) unused variables (typically parameters).
template <typename T> template <typename T>
...@@ -358,52 +341,6 @@ F FUNCTION_CAST(Address addr) { ...@@ -358,52 +341,6 @@ F FUNCTION_CAST(Address addr) {
} }
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
TypeName(const TypeName&) V8_DELETE; \
void operator=(const TypeName&) V8_DELETE
// A macro to disallow all the implicit constructors, namely the
// default constructor, copy constructor and operator= functions.
//
// This should be used in the private: declarations for a class
// that wants to prevent anyone from instantiating it. This is
// especially useful for classes containing only static methods.
#define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
TypeName() V8_DELETE; \
DISALLOW_COPY_AND_ASSIGN(TypeName)
// Newly written code should use V8_INLINE and V8_NOINLINE directly.
#define INLINE(declarator) V8_INLINE declarator
#define NO_INLINE(declarator) V8_NOINLINE declarator
// Newly written code should use V8_WARN_UNUSED_RESULT.
#define MUST_USE_RESULT V8_WARN_UNUSED_RESULT
// Define DISABLE_ASAN macros.
#if defined(__has_feature)
#if __has_feature(address_sanitizer)
#define DISABLE_ASAN __attribute__((no_sanitize_address))
#endif
#endif
#ifndef DISABLE_ASAN
#define DISABLE_ASAN
#endif
#if V8_CC_GNU
#define V8_IMMEDIATE_CRASH() __builtin_trap()
#else
#define V8_IMMEDIATE_CRASH() ((void(*)())0)()
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Forward declarations for frequently used classes // Forward declarations for frequently used classes
// (sorted alphabetically) // (sorted alphabetically)
......
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
#include <vector> #include <vector>
#include "../../include/v8-platform.h" #include "../../include/v8-platform.h"
// TODO(jochen): We should have our own version of globals.h. #include "../base/macros.h"
#include "../globals.h"
#include "../platform/mutex.h" #include "../platform/mutex.h"
#include "task-queue.h" #include "task-queue.h"
......
...@@ -30,8 +30,7 @@ ...@@ -30,8 +30,7 @@
#include <queue> #include <queue>
// TODO(jochen): We should have our own version of globals.h. #include "../base/macros.h"
#include "../globals.h"
#include "../platform/mutex.h" #include "../platform/mutex.h"
#include "../platform/semaphore.h" #include "../platform/semaphore.h"
......
...@@ -30,8 +30,7 @@ ...@@ -30,8 +30,7 @@
#include <queue> #include <queue>
// TODO(jochen): We should have our own version of globals.h. #include "../base/macros.h"
#include "../globals.h"
#include "../platform.h" #include "../platform.h"
namespace v8 { namespace v8 {
......
...@@ -237,6 +237,9 @@ ...@@ -237,6 +237,9 @@
{ {
'target_name': 'v8_base.<(v8_target_arch)', 'target_name': 'v8_base.<(v8_target_arch)',
'type': 'static_library', 'type': 'static_library',
'dependencies': [
'v8_libbase.<(v8_target_arch)',
],
'variables': { 'variables': {
'optimize': 'max', 'optimize': 'max',
}, },
...@@ -1030,6 +1033,33 @@ ...@@ -1030,6 +1033,33 @@
}], }],
], ],
}, },
{
'target_name': 'v8_libbase.<(v8_target_arch)',
# TODO(jochen): Should be a static library once it has sources in it.
'type': 'none',
'variables': {
'optimize': 'max',
},
'include_dirs+': [
'../../src',
],
'sources': [
'../../src/base/macros.h',
],
'conditions': [
['want_separate_host_toolset==1', {
'toolsets': ['host', 'target'],
}, {
'toolsets': ['target'],
}],
['component=="shared_library"', {
'defines': [
'BUILDING_V8_SHARED',
'V8_SHARED',
],
}],
],
},
{ {
'target_name': 'js2c', 'target_name': 'js2c',
'type': 'none', 'type': 'none',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment