Instruction.h 4.58 KB
Newer Older
1
/*
2
 * Copyright (C) 2008, 2012, 2013 Apple Inc. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  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.
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") 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 APPLE AND ITS 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 APPLE OR ITS 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.
 */
28

29 30 31
#ifndef Instruction_h
#define Instruction_h

32
#include "MacroAssembler.h"
33
#include "Opcode.h"
34
#include "PropertySlot.h"
35
#include "SpecialPointer.h"
36
#include "Structure.h"
37
#include "StructureChain.h"
38
#include <wtf/VectorTraits.h>
39

40
namespace JSC {
41

42 43 44 45 46
class ArrayAllocationProfile;
class ArrayProfile;
class ObjectAllocationProfile;
struct LLIntCallLinkInfo;
struct ValueProfile;
weinig@apple.com's avatar
weinig@apple.com committed
47

48 49 50 51 52
struct Instruction {
    Instruction()
    {
        u.jsCell.clear();
    }
53
        
54 55
    Instruction(Opcode opcode)
    {
56
#if !ENABLE(COMPUTED_GOTO_OPCODES)
57 58 59
        // We have to initialize one of the pointer members to ensure that
        // the entire struct is initialized, when opcode is not a pointer.
        u.jsCell.clear();
60
#endif
61 62 63 64 65 66 67 68 69 70 71
        u.opcode = opcode;
    }

    Instruction(int operand)
    {
        // We have to initialize one of the pointer members to ensure that
        // the entire struct is initialized in 64-bit.
        u.jsCell.clear();
        u.operand = operand;
    }

ggaren@apple.com's avatar
ggaren@apple.com committed
72
    Instruction(VM& vm, JSCell* owner, Structure* structure)
73 74
    {
        u.structure.clear();
ggaren@apple.com's avatar
ggaren@apple.com committed
75
        u.structure.set(vm, owner, structure);
76
    }
ggaren@apple.com's avatar
ggaren@apple.com committed
77
    Instruction(VM& vm, JSCell* owner, StructureChain* structureChain)
78 79
    {
        u.structureChain.clear();
ggaren@apple.com's avatar
ggaren@apple.com committed
80
        u.structureChain.set(vm, owner, structureChain);
81
    }
ggaren@apple.com's avatar
ggaren@apple.com committed
82
    Instruction(VM& vm, JSCell* owner, JSCell* jsCell)
83 84
    {
        u.jsCell.clear();
ggaren@apple.com's avatar
ggaren@apple.com committed
85
        u.jsCell.set(vm, owner, jsCell);
86 87 88
    }

    Instruction(PropertySlot::GetValueFunc getterFunc) { u.getterFunc = getterFunc; }
89
        
90
    Instruction(LLIntCallLinkInfo* callLinkInfo) { u.callLinkInfo = callLinkInfo; }
91
        
92 93 94 95
    Instruction(ValueProfile* profile) { u.profile = profile; }
    Instruction(ArrayProfile* profile) { u.arrayProfile = profile; }
    Instruction(ArrayAllocationProfile* profile) { u.arrayAllocationProfile = profile; }
    Instruction(ObjectAllocationProfile* profile) { u.objectAllocationProfile = profile; }
96
        
97
    Instruction(WriteBarrier<Unknown>* registerPointer) { u.registerPointer = registerPointer; }
98
        
99
    Instruction(Special::Pointer pointer) { u.specialPointer = pointer; }
100
        
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    Instruction(bool* predicatePointer) { u.predicatePointer = predicatePointer; }

    union {
        Opcode opcode;
        int operand;
        WriteBarrierBase<Structure> structure;
        WriteBarrierBase<StructureChain> structureChain;
        WriteBarrierBase<JSCell> jsCell;
        WriteBarrier<Unknown>* registerPointer;
        Special::Pointer specialPointer;
        PropertySlot::GetValueFunc getterFunc;
        LLIntCallLinkInfo* callLinkInfo;
        ValueProfile* profile;
        ArrayProfile* arrayProfile;
        ArrayAllocationProfile* arrayAllocationProfile;
        ObjectAllocationProfile* objectAllocationProfile;
        void* pointer;
        bool* predicatePointer;
    } u;
oliver@apple.com's avatar
oliver@apple.com committed
120
        
121 122 123 124
private:
    Instruction(StructureChain*);
    Instruction(Structure*);
};
125

126
} // namespace JSC
127

128 129
namespace WTF {

130
template<> struct VectorTraits<JSC::Instruction> : VectorTraitsBase<true, JSC::Instruction> { };
131 132 133

} // namespace WTF

134
#endif // Instruction_h