src/Structures.cpp
author David Anderson <dvander@alliedmods.net>
Sat Jul 28 16:42:38 2012 -0700 (2012-07-28)
changeset 108 9dcf58a17d32
parent 92 e3974e7360e9
child 146 dc7d3b7a918c
permissions -rw-r--r--
Stop using ccache on OS X.
     1 /* vim: set ts=4 sw=4 tw=99 et
     2  *
     3  * Copyright (C) 2012 David Anderson
     4  *
     5  * This file is part of JITCraft.
     6  *
     7  * JITCraft is free software: you can redistribute it and/or modify it under
     8  * the terms of the GNU General Public License as published by the Free
     9  * Software Foundation, either version 3 of the License, or (at your option)
    10  * any later version.
    11  * 
    12  * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
    13  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
    15  *
    16  * You should have received a copy of the GNU General Public License along with
    17  * JITCraft. If not, see http://www.gnu.org/licenses/.
    18  */
    19 #include "Structures.h"
    20 #include "Types.h"
    21 #include "Spaces-inl.h"
    22 #include "Heap-inl.h"
    23 
    24 using namespace ke;
    25 
    26 StructureBufferBuilder::StructureBufferBuilder()
    27   : size_(0)
    28 {
    29 }
    30 
    31 bool
    32 StructureBufferBuilder::add(Handle<Type> type, unsigned *offset)
    33 {
    34     *offset = size_;
    35 
    36     if (!type->isTraceable()) {
    37         // For now, assume the size of primitives is 4-byte.
    38         assert(type->isInt32() || type->isFloat());
    39         size_ += 4;
    40         return true;
    41     }
    42 
    43     if (!offsets_.append(size_))
    44         return false;
    45 
    46     size_ += sizeof(Object *);
    47     return true;
    48 }