Added clang support. A lot of the motion here is introducing a new offsetof because clang's seems broken?
authorDavid Anderson <danderson@mozilla.com>
Wed Jul 25 00:48:08 2012 -0700 (2012-07-25)
changeset 915f4402180204
parent 90 3da12b433b00
child 92 e3974e7360e9
Added clang support. A lot of the motion here is introducing a new offsetof because clang's seems broken?
AMBuildScript
include/keima.h
src/AMBuild.shell
src/Array.cpp
src/Array.h
src/BytecodeCompiler.cpp
src/BytecodeEmitter.h
src/Code.h
src/Environments.h
src/FixedArray.cpp
src/Functions.h
src/Heap.cpp
src/Interpreter.cpp
src/Modules.h
src/Objects.h
src/Platform-Posix.cpp
src/PoolAllocator.h
src/Spaces-inl.h
src/Spaces.cpp
src/Spaces.h
src/Stack.cpp
src/StringPool.h
src/Strings.cpp
src/TypeManager.cpp
src/Types.cpp
src/Types.h
src/Utility.h
     1.1 --- a/AMBuildScript	Wed Jul 25 00:16:52 2012 -0700
     1.2 +++ b/AMBuildScript	Wed Jul 25 00:48:08 2012 -0700
     1.3 @@ -46,9 +46,16 @@
     1.4  				self.compiler.AddToListVar('CXXFLAGS', '-fno-rtti')
     1.5  				self.compiler.AddToListVar('CXXFLAGS', '-fno-threadsafe-statics')
     1.6  
     1.7 +				# We don't really care about these.
     1.8  				self.compiler.AddToListVar('CXXFLAGS', '-Wno-non-virtual-dtor')
     1.9  				self.compiler.AddToListVar('CXXFLAGS', '-Wno-overloaded-virtual')
    1.10  
    1.11 +				# The compiler is too aggressive about what what should be a valid offsetof.
    1.12 +				self.compiler.AddToListVar('CXXFLAGS', '-Wno-invalid-offsetof')
    1.13 +
    1.14 +				# This would otherwise forbid ((x = y) == NULL) in clang apparently.
    1.15 +				self.compiler.AddToListVar('CXXFLAGS', '-Wno-null-arithmetic')
    1.16 +
    1.17  				if (self.vendor == 'gcc' and cxx.majorVersion >= 4 and cxx.minorVersion >= 7) or \
    1.18  						(self.vendor == 'clang' and cxx.majorVersion >= 3):
    1.19  					self.compiler.AddToListVar('CXXFLAGS', '-Wno-delete-non-virtual-dtor')
     2.1 --- a/include/keima.h	Wed Jul 25 00:16:52 2012 -0700
     2.2 +++ b/include/keima.h	Wed Jul 25 00:48:08 2012 -0700
     2.3 @@ -1,4 +1,5 @@
     2.4 -/*
     2.5 +/* vim: set ts=4 sw=4 tw=99 et:
     2.6 + *
     2.7   * Copyright (C) 2004-2012 David Anderson
     2.8   *
     2.9   * This file is part of SourcePawn.
    2.10 @@ -100,7 +101,7 @@
    2.11      template <typename S> Local(Local<S> other)
    2.12        : Handle<T>(reinterpret_cast<T *>(*other))
    2.13      {
    2.14 -        typeCheck<S>();
    2.15 +        this->template typeCheck<S>();
    2.16      }
    2.17  
    2.18      template <typename S> Local(S *other)
    2.19 @@ -131,7 +132,7 @@
    2.20      explicit Root(ke::HeapRoot *obj)
    2.21        : Handle<T>(reinterpret_cast<T *>(obj))
    2.22      {
    2.23 -		incref();
    2.24 +incref();
    2.25      }
    2.26  
    2.27      static inline Root<T> New(Handle<T> other);
    2.28 @@ -142,8 +143,8 @@
    2.29  
    2.30      Root<T> &operator =(const Root<T> &other) {
    2.31          decref();
    2.32 -        obj_ = other.obj_;
    2.33 -		incref();
    2.34 +        this->obj_ = other.obj_;
    2.35 +        incref();
    2.36          return *this;
    2.37      }
    2.38  
     3.1 --- a/src/AMBuild.shell	Wed Jul 25 00:16:52 2012 -0700
     3.2 +++ b/src/AMBuild.shell	Wed Jul 25 00:48:08 2012 -0700
     3.3 @@ -6,9 +6,11 @@
     3.4  compiler.AddToListVar('CXXINCLUDES', os.path.join(AMBuild.sourceFolder, 'include'))
     3.5  
     3.6  library = osutil.StaticLibPrefix() + 'keima' + osutil.StaticLibSuffix()
     3.7 -compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:CONSOLE')
     3.8  compiler.AddToListVar('POSTLINKFLAGS', os.path.join(AMBuild.outputFolder, 'keima', library))
     3.9  
    3.10 +if compiler.cc.name == 'msvc':
    3.11 +	compiler.AddToListVar('POSTLINKFLAGS', '/SUBSYSTEM:CONSOLE')
    3.12 +
    3.13  job = AMBuild.AddJob('spshell')
    3.14  binary = Cpp.ExecutableBuilder('spshell', AMBuild, job, compiler)
    3.15  files = [
     4.1 --- a/src/Array.cpp	Wed Jul 25 00:16:52 2012 -0700
     4.2 +++ b/src/Array.cpp	Wed Jul 25 00:48:08 2012 -0700
     4.3 @@ -15,6 +15,7 @@
     4.4   * You should have received a copy of the GNU General Public License along with
     4.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
     4.6   */
     4.7 +#include <string.h>
     4.8  #include "Array.h"
     4.9  #include "Heap.h"
    4.10  #include "Zone.h"
     5.1 --- a/src/Array.h	Wed Jul 25 00:16:52 2012 -0700
     5.2 +++ b/src/Array.h	Wed Jul 25 00:48:08 2012 -0700
     5.3 @@ -123,10 +123,10 @@
     5.4  
     5.5      // GC Descriptor.
     5.6      static inline size_t offsetOfType() {
     5.7 -        return offsetof(ArrayMap, type_);
     5.8 +        return OFFSETOF(ArrayMap, type_);
     5.9      }
    5.10      static inline size_t offsetOfContained() {
    5.11 -        return offsetof(ArrayMap, contained_);
    5.12 +        return OFFSETOF(ArrayMap, contained_);
    5.13      }
    5.14      // End GC Descriptor.
    5.15      
     6.1 --- a/src/BytecodeCompiler.cpp	Wed Jul 25 00:16:52 2012 -0700
     6.2 +++ b/src/BytecodeCompiler.cpp	Wed Jul 25 00:48:08 2012 -0700
     6.3 @@ -36,9 +36,9 @@
     6.4    : zone_(zone),
     6.5      tree_(tree),
     6.6      emitter_(zone->pool()),
     6.7 -    moduleData_(module),
     6.8      locals_(NULL),
     6.9      scope_(NULL),
    6.10 +    moduleData_(module),
    6.11      loop_(NULL)
    6.12  {
    6.13  }
     7.1 --- a/src/BytecodeEmitter.h	Wed Jul 25 00:16:52 2012 -0700
     7.2 +++ b/src/BytecodeEmitter.h	Wed Jul 25 00:48:08 2012 -0700
     7.3 @@ -31,7 +31,7 @@
     7.4  class Type;
     7.5  class Map;
     7.6  
     7.7 -typedef PoolList<ScopedRoot<Object>> ObjectList;
     7.8 +typedef PoolList<ScopedRoot<Object> > ObjectList;
     7.9  
    7.10  struct OopRecord : public PoolObject
    7.11  {
     8.1 --- a/src/Code.h	Wed Jul 25 00:16:52 2012 -0700
     8.2 +++ b/src/Code.h	Wed Jul 25 00:48:08 2012 -0700
     8.3 @@ -97,22 +97,22 @@
     8.4  
     8.5      // GC Descriptor.
     8.6      static inline size_t offsetOfModule() {
     8.7 -        return offsetof(Code, module_);
     8.8 +        return OFFSETOF(Code, module_);
     8.9      }
    8.10      static inline size_t offsetOfBytecode() {
    8.11 -        return offsetof(Code, bytecode_);
    8.12 +        return OFFSETOF(Code, bytecode_);
    8.13      }
    8.14      static inline size_t offsetOfLocals() {
    8.15 -        return offsetof(Code, locals_);
    8.16 +        return OFFSETOF(Code, locals_);
    8.17      }
    8.18      static inline size_t offsetOfObjects() {
    8.19 -        return offsetof(Code, objects_);
    8.20 +        return OFFSETOF(Code, objects_);
    8.21      }
    8.22      static inline size_t offsetOfSafepoints() {
    8.23 -        return offsetof(Code, safepoints_);
    8.24 +        return OFFSETOF(Code, safepoints_);
    8.25      }
    8.26      static inline size_t offsetOfSourceMap() {
    8.27 -        return offsetof(Code, sourcemap_);
    8.28 +        return OFFSETOF(Code, sourcemap_);
    8.29      }
    8.30      // End GC Descriptor.
    8.31  
     9.1 --- a/src/Environments.h	Wed Jul 25 00:16:52 2012 -0700
     9.2 +++ b/src/Environments.h	Wed Jul 25 00:48:08 2012 -0700
     9.3 @@ -136,7 +136,7 @@
     9.4      }
     9.5  
     9.6      static inline size_t offsetOfSlots() {
     9.7 -        return offsetof(EnvironmentMap, slots_);
     9.8 +        return OFFSETOF(EnvironmentMap, slots_);
     9.9      }
    9.10  
    9.11      static inline EnvironmentMap *cast(Object *obj) {
    10.1 --- a/src/FixedArray.cpp	Wed Jul 25 00:16:52 2012 -0700
    10.2 +++ b/src/FixedArray.cpp	Wed Jul 25 00:48:08 2012 -0700
    10.3 @@ -16,6 +16,7 @@
    10.4   * JITCraft. If not, see http://www.gnu.org/licenses/.
    10.5   */
    10.6  #include <limits.h>
    10.7 +#include <string.h>
    10.8  #include "FixedArray.h"
    10.9  #include "Zone.h"
   10.10  #include "Heap-inl.h"
    11.1 --- a/src/Functions.h	Wed Jul 25 00:16:52 2012 -0700
    11.2 +++ b/src/Functions.h	Wed Jul 25 00:48:08 2012 -0700
    11.3 @@ -62,13 +62,13 @@
    11.4  
    11.5      // Begin GC Descriptor.
    11.6      static inline size_t offsetOfCode() {
    11.7 -        return offsetof(Function, code_);
    11.8 +        return OFFSETOF(Function, code_);
    11.9      }
   11.10      static inline size_t offsetOfType() {
   11.11 -        return offsetof(Function, type_);
   11.12 +        return OFFSETOF(Function, type_);
   11.13      }
   11.14      static inline size_t offsetOfName() {
   11.15 -        return offsetof(Function, name_);
   11.16 +        return OFFSETOF(Function, name_);
   11.17      }
   11.18      // End GC Descriptor.
   11.19  
   11.20 @@ -104,10 +104,10 @@
   11.21  
   11.22      // Begin GC Descriptor.
   11.23      static inline size_t offsetOfType() {
   11.24 -        return offsetof(Native, type_);
   11.25 +        return OFFSETOF(Native, type_);
   11.26      }
   11.27      static inline size_t offsetOfName() {
   11.28 -        return offsetof(Native, name_);
   11.29 +        return OFFSETOF(Native, name_);
   11.30      }
   11.31      // End GC Descriptor.
   11.32  
    12.1 --- a/src/Heap.cpp	Wed Jul 25 00:16:52 2012 -0700
    12.2 +++ b/src/Heap.cpp	Wed Jul 25 00:48:08 2012 -0700
    12.3 @@ -30,9 +30,9 @@
    12.4  
    12.5  Heap::Heap(Zone *zone)
    12.6    : zone_(zone),
    12.7 -    markStack_(NULL),
    12.8 +    mapSpace_(zone),
    12.9      oldSpace_(zone),
   12.10 -    mapSpace_(zone)
   12.11 +    markStack_(NULL)
   12.12  {
   12.13  }
   12.14  
    13.1 --- a/src/Interpreter.cpp	Wed Jul 25 00:16:52 2012 -0700
    13.2 +++ b/src/Interpreter.cpp	Wed Jul 25 00:48:08 2012 -0700
    13.3 @@ -16,6 +16,7 @@
    13.4   * You should have received a copy of the GNU General Public License along with
    13.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
    13.6   */
    13.7 +#include <string.h>
    13.8  #include "Interpreter.h"
    13.9  #include "Modules.h"
   13.10  #include "Zone.h"
    14.1 --- a/src/Modules.h	Wed Jul 25 00:16:52 2012 -0700
    14.2 +++ b/src/Modules.h	Wed Jul 25 00:48:08 2012 -0700
    14.3 @@ -89,22 +89,22 @@
    14.4  
    14.5      // Begin GC Descriptor.
    14.6      static inline size_t offsetOfFunctions() {
    14.7 -        return offsetof(Module, functions_);
    14.8 +        return OFFSETOF(Module, functions_);
    14.9      }
   14.10      static inline size_t offsetOfPublics() {
   14.11 -        return offsetof(Module, publics_);
   14.12 +        return OFFSETOF(Module, publics_);
   14.13      }
   14.14      static inline size_t offsetOfNatives() {
   14.15 -        return offsetof(Module, natives_);
   14.16 +        return OFFSETOF(Module, natives_);
   14.17      }
   14.18      static inline size_t offsetOfFile() {
   14.19 -        return offsetof(Module, file_);
   14.20 +        return OFFSETOF(Module, file_);
   14.21      }
   14.22      static inline size_t offsetOfEnvironment() {
   14.23 -        return offsetof(Module, environment_);
   14.24 +        return OFFSETOF(Module, environment_);
   14.25      }
   14.26      static inline size_t offsetOfCode() {
   14.27 -        return offsetof(Module, code_);
   14.28 +        return OFFSETOF(Module, code_);
   14.29      }
   14.30      // End GC Descriptor.
   14.31  
    15.1 --- a/src/Objects.h	Wed Jul 25 00:16:52 2012 -0700
    15.2 +++ b/src/Objects.h	Wed Jul 25 00:48:08 2012 -0700
    15.3 @@ -83,7 +83,8 @@
    15.4      inline void write(Zone *zone, Object **ptr, Object *value);
    15.5  
    15.6      static inline size_t offsetOfMap() {
    15.7 -        return offsetof(Object, map_);
    15.8 +        // Clang doesn't accept offsetof here and it's not clear why...
    15.9 +        return reinterpret_cast<size_t>(&((Object *)NULL)->map_);
   15.10      }
   15.11  };
   15.12  
    16.1 --- a/src/Platform-Posix.cpp	Wed Jul 25 00:16:52 2012 -0700
    16.2 +++ b/src/Platform-Posix.cpp	Wed Jul 25 00:48:08 2012 -0700
    16.3 @@ -19,7 +19,7 @@
    16.4  #include <sys/mman.h>
    16.5  #include "Platform.h"
    16.6  
    16.7 -using namespace jc;
    16.8 +using namespace ke;
    16.9  
   16.10  static inline int
   16.11  ToProtBits(OS::Protection prot)
    17.1 --- a/src/PoolAllocator.h	Wed Jul 25 00:16:52 2012 -0700
    17.2 +++ b/src/PoolAllocator.h	Wed Jul 25 00:48:08 2012 -0700
    17.3 @@ -126,7 +126,7 @@
    17.4  {
    17.5    public:
    17.6      PoolList()
    17.7 -      : Vector(PoolAllocationPolicy())
    17.8 +      : Vector<T, PoolAllocationPolicy>(PoolAllocationPolicy())
    17.9      {
   17.10      }
   17.11  };
    18.1 --- a/src/Spaces-inl.h	Wed Jul 25 00:16:52 2012 -0700
    18.2 +++ b/src/Spaces-inl.h	Wed Jul 25 00:48:08 2012 -0700
    18.3 @@ -19,6 +19,8 @@
    18.4  #ifndef _include_jitcraft_spaces_inl_h_
    18.5  #define _include_jitcraft_spaces_inl_h_
    18.6  
    18.7 +#include "Objects.h"
    18.8 +
    18.9  namespace ke {
   18.10  
   18.11  inline Address
   18.12 @@ -54,6 +56,23 @@
   18.13      return addr;
   18.14  }
   18.15  
   18.16 +template <typename SizeEvaluator> inline Object *
   18.17 +ChunkObjectIteratorBase<SizeEvaluator>::next()
   18.18 +{
   18.19 +    while (current_ && current_ != top_) {
   18.20 +        Object *obj = reinterpret_cast<Object *>(current_);
   18.21 +        size_t size = evaluator_(obj, obj->map());
   18.22 +        current_ += size;
   18.23 +        if (current_ == chunk_->end()) {
   18.24 +            chunk_ = chunk_->next();
   18.25 +            current_ = chunk_ ? chunk_->first() : NULL;
   18.26 +        }
   18.27 +        if (obj->is(MapKind_FreeRegion))
   18.28 +            continue;
   18.29 +    }
   18.30 +    return NULL;
   18.31 +}
   18.32 +
   18.33  }
   18.34  
   18.35  #endif // _include_jitcraft_spaces_inl_h_
    19.1 --- a/src/Spaces.cpp	Wed Jul 25 00:16:52 2012 -0700
    19.2 +++ b/src/Spaces.cpp	Wed Jul 25 00:48:08 2012 -0700
    19.3 @@ -16,6 +16,7 @@
    19.4   * You should have received a copy of the GNU General Public License along with
    19.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
    19.6   */
    19.7 +#include <string.h>
    19.8  #include "Zone.h"
    19.9  #include "Spaces.h"
   19.10  #include "Platform.h"
    20.1 --- a/src/Spaces.h	Wed Jul 25 00:16:52 2012 -0700
    20.2 +++ b/src/Spaces.h	Wed Jul 25 00:48:08 2012 -0700
    20.3 @@ -272,20 +272,7 @@
    20.4      {
    20.5      }
    20.6  
    20.7 -    Object *next() {
    20.8 -        while (current_ && current_ != top_) {
    20.9 -            Object *obj = reinterpret_cast<Object *>(current_);
   20.10 -            size_t size = evaluator_(obj, obj->map());
   20.11 -            current_ += size;
   20.12 -            if (current_ == chunk_->end()) {
   20.13 -                chunk_ = chunk_->next();
   20.14 -                current_ = chunk_ ? chunk_->first() : NULL;
   20.15 -            }
   20.16 -            if (obj->is(MapKind_FreeRegion))
   20.17 -                continue;
   20.18 -        }
   20.19 -        return NULL;
   20.20 -    }
   20.21 +    Object *next();
   20.22  };
   20.23  
   20.24  class FreedObject
    21.1 --- a/src/Stack.cpp	Wed Jul 25 00:16:52 2012 -0700
    21.2 +++ b/src/Stack.cpp	Wed Jul 25 00:48:08 2012 -0700
    21.3 @@ -18,6 +18,7 @@
    21.4   */
    21.5  #include <new>
    21.6  #include <stdlib.h>
    21.7 +#include <string.h>
    21.8  #include "Stack.h"
    21.9  #include "Zone.h"
   21.10  #include "Strings.h"
    22.1 --- a/src/StringPool.h	Wed Jul 25 00:16:52 2012 -0700
    22.2 +++ b/src/StringPool.h	Wed Jul 25 00:48:08 2012 -0700
    22.3 @@ -18,6 +18,7 @@
    22.4  #ifndef _include_jitcraft_string_pool_h_
    22.5  #define _include_jitcraft_string_pool_h_
    22.6  
    22.7 +#include <string.h>
    22.8  #include "AllocatorPolicies.h"
    22.9  #include "HashTable.h"
   22.10  #include "Strings.h"
    23.1 --- a/src/Strings.cpp	Wed Jul 25 00:16:52 2012 -0700
    23.2 +++ b/src/Strings.cpp	Wed Jul 25 00:48:08 2012 -0700
    23.3 @@ -16,6 +16,7 @@
    23.4   * You should have received a copy of the GNU General Public License along with
    23.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
    23.6   */
    23.7 +#include <string.h>
    23.8  #include "Strings.h"
    23.9  #include "Zone.h"
   23.10  #include "Heap-inl.h"
    24.1 --- a/src/TypeManager.cpp	Wed Jul 25 00:16:52 2012 -0700
    24.2 +++ b/src/TypeManager.cpp	Wed Jul 25 00:48:08 2012 -0700
    24.3 @@ -16,6 +16,7 @@
    24.4   * You should have received a copy of the GNU General Public License along with
    24.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
    24.6   */
    24.7 +#include <strings.h>
    24.8  #include "Types.h"
    24.9  #include "TypeManager.h"
   24.10  #include "Zone.h"
    25.1 --- a/src/Types.cpp	Wed Jul 25 00:16:52 2012 -0700
    25.2 +++ b/src/Types.cpp	Wed Jul 25 00:48:08 2012 -0700
    25.3 @@ -15,6 +15,7 @@
    25.4   * You should have received a copy of the GNU General Public License along with
    25.5   * JITCraft. If not, see http://www.gnu.org/licenses/.
    25.6   */
    25.7 +#include <strings.h>
    25.8  #include "Types.h"
    25.9  #include "Zone.h"
   25.10  #include "Strings.h"
    26.1 --- a/src/Types.h	Wed Jul 25 00:16:52 2012 -0700
    26.2 +++ b/src/Types.h	Wed Jul 25 00:48:08 2012 -0700
    26.3 @@ -152,16 +152,16 @@
    26.4  
    26.5      // GC Descriptor.
    26.6      static inline size_t offsetOfContained() {
    26.7 -        return offsetof(Type, contained_);
    26.8 +        return OFFSETOF(Type, contained_);
    26.9      }
   26.10      static inline size_t offsetOfReturnType() {
   26.11 -        return offsetof(Type, returnType_);
   26.12 +        return OFFSETOF(Type, returnType_);
   26.13      }
   26.14      static inline size_t offsetOfParameters() {
   26.15 -        return offsetof(Type, parameters_);
   26.16 +        return OFFSETOF(Type, parameters_);
   26.17      }
   26.18      static inline size_t offsetOfTag() {
   26.19 -        return offsetof(Type, tag_);
   26.20 +        return OFFSETOF(Type, tag_);
   26.21      }
   26.22      // End GC Descriptor.
   26.23  
    27.1 --- a/src/Utility.h	Wed Jul 25 00:16:52 2012 -0700
    27.2 +++ b/src/Utility.h	Wed Jul 25 00:48:08 2012 -0700
    27.3 @@ -238,6 +238,8 @@
    27.4      return t1 < t2 ? t1 : t2;
    27.5  }
    27.6  
    27.7 +#define OFFSETOF(Class, Member) reinterpret_cast<size_t>(&((Class *)NULL)->Member)
    27.8 +
    27.9  }
   27.10  
   27.11  #endif // _include_jitcraft_utility_h_