src/Structures.cpp
author David Anderson <dvander@alliedmods.net>
Wed Jul 25 00:13:02 2012 -0700 (2012-07-25)
changeset 88 fc3f34f928dd
parent 86 32ad0523b309
child 92 e3974e7360e9
permissions -rw-r--r--
Added AMBuild support.
     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 
    22 using namespace ke;
    23 
    24 StructureBufferBuilder::StructureBufferBuilder()
    25   : size_(0)
    26 {
    27 }
    28 
    29 bool
    30 StructureBufferBuilder::add(Handle<Type> type, unsigned *offset)
    31 {
    32     *offset = size_;
    33 
    34     if (!type->isTraceable()) {
    35         // For now, assume the size of primitives is 4-byte.
    36         assert(type->isInt32() || type->isFloat());
    37         size_ += 4;
    38         return true;
    39     }
    40 
    41     if (!offsets_.append(size_))
    42         return false;
    43 
    44     size_ += sizeof(Object *);
    45     return true;
    46 }