X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/14957cd040308e3eeec43d26bae5d76da13fcd85..refs/heads/master:/bytecompiler/BytecodeGenerator.h diff --git a/bytecompiler/BytecodeGenerator.h b/bytecompiler/BytecodeGenerator.h index bc297ee..1a9771e 100644 --- a/bytecompiler/BytecodeGenerator.h +++ b/bytecompiler/BytecodeGenerator.h @@ -1,6 +1,7 @@ /* - * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009, 2012-2015 Apple Inc. All rights reserved. * Copyright (C) 2008 Cameron Zwarich + * Copyright (C) 2012 Igalia, S.L. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -11,7 +12,7 @@ * 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 + * 3. Neither the name of Apple 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. * @@ -31,44 +32,67 @@ #define BytecodeGenerator_h #include "CodeBlock.h" -#include "HashTraits.h" +#include #include "Instruction.h" #include "Label.h" #include "LabelScope.h" #include "Interpreter.h" +#include "ParserError.h" #include "RegisterID.h" #include "SymbolTable.h" #include "Debugger.h" #include "Nodes.h" +#include "StaticPropertyAnalyzer.h" +#include "TemplateRegistryKey.h" +#include "UnlinkedCodeBlock.h" + +#include + #include #include #include + namespace JSC { class Identifier; - class ScopeChainNode; + class JSTemplateRegistryKey; + + enum ExpectedFunction { + NoExpectedFunction, + ExpectObjectConstructor, + ExpectArrayConstructor + }; class CallArguments { public: - CallArguments(BytecodeGenerator& generator, ArgumentsNode* argumentsNode); + CallArguments(BytecodeGenerator&, ArgumentsNode*, unsigned additionalArguments = 0); RegisterID* thisRegister() { return m_argv[0].get(); } RegisterID* argumentRegister(unsigned i) { return m_argv[i + 1].get(); } - unsigned callFrame() { return thisRegister()->index() + count() + RegisterFile::CallFrameHeaderSize; } - unsigned count() { return m_argv.size(); } + unsigned stackOffset() { return -m_argv[0]->index() + JSStack::CallFrameHeaderSize; } + unsigned argumentCountIncludingThis() { return m_argv.size() - m_padding; } RegisterID* profileHookRegister() { return m_profileHookRegister.get(); } ArgumentsNode* argumentsNode() { return m_argumentsNode; } private: RefPtr m_profileHookRegister; ArgumentsNode* m_argumentsNode; - Vector, 16> m_argv; + Vector, 8, UnsafeVectorOverflow> m_argv; + unsigned m_padding; }; struct FinallyContext { - Label* finallyAddr; - RegisterID* retAddrDst; + StatementNode* finallyBlock; + RegisterID* iterator; + ThrowableExpressionData* enumerationNode; + unsigned scopeContextStackSize; + unsigned switchContextStackSize; + unsigned forInContextStackSize; + unsigned tryContextStackSize; + unsigned labelScopesSize; + int finallyDepth; + int dynamicScopeDepth; }; struct ControlFlowContext { @@ -76,63 +100,199 @@ namespace JSC { FinallyContext finallyContext; }; - struct ForInContext { - RefPtr expectedSubscriptRegister; - RefPtr iterRegister; - RefPtr indexRegister; - RefPtr propertyRegister; + class ForInContext { + public: + ForInContext(RegisterID* localRegister) + : m_localRegister(localRegister) + , m_isValid(true) + { + } + + virtual ~ForInContext() + { + } + + bool isValid() const { return m_isValid; } + void invalidate() { m_isValid = false; } + + enum ForInContextType { + StructureForInContextType, + IndexedForInContextType + }; + virtual ForInContextType type() const = 0; + + RegisterID* local() const { return m_localRegister.get(); } + + private: + RefPtr m_localRegister; + bool m_isValid; }; - class BytecodeGenerator { - WTF_MAKE_FAST_ALLOCATED; + class StructureForInContext : public ForInContext { public: - typedef DeclarationStacks::VarStack VarStack; - typedef DeclarationStacks::FunctionStack FunctionStack; + StructureForInContext(RegisterID* localRegister, RegisterID* indexRegister, RegisterID* propertyRegister, RegisterID* enumeratorRegister) + : ForInContext(localRegister) + , m_indexRegister(indexRegister) + , m_propertyRegister(propertyRegister) + , m_enumeratorRegister(enumeratorRegister) + { + } - static void setDumpsGeneratedCode(bool dumpsGeneratedCode); - static bool dumpsGeneratedCode(); + virtual ForInContextType type() const + { + return StructureForInContextType; + } - BytecodeGenerator(ProgramNode*, ScopeChainNode*, SymbolTable*, ProgramCodeBlock*); - BytecodeGenerator(FunctionBodyNode*, ScopeChainNode*, SymbolTable*, CodeBlock*); - BytecodeGenerator(EvalNode*, ScopeChainNode*, SymbolTable*, EvalCodeBlock*); + RegisterID* index() const { return m_indexRegister.get(); } + RegisterID* property() const { return m_propertyRegister.get(); } + RegisterID* enumerator() const { return m_enumeratorRegister.get(); } - JSGlobalData* globalData() const { return m_globalData; } - const CommonIdentifiers& propertyNames() const { return *m_globalData->propertyNames; } + private: + RefPtr m_indexRegister; + RefPtr m_propertyRegister; + RefPtr m_enumeratorRegister; + }; - bool isConstructor() { return m_codeBlock->m_isConstructor; } + class IndexedForInContext : public ForInContext { + public: + IndexedForInContext(RegisterID* localRegister, RegisterID* indexRegister) + : ForInContext(localRegister) + , m_indexRegister(indexRegister) + { + } - JSObject* generate(); + virtual ForInContextType type() const + { + return IndexedForInContextType; + } - // Returns the register corresponding to a local variable, or 0 if no - // such register exists. Registers returned by registerFor do not - // require explicit reference counting. - RegisterID* registerFor(const Identifier&); + RegisterID* index() const { return m_indexRegister.get(); } - // Returns the agument number if this is an argument, or 0 if not. - int argumentNumberFor(const Identifier&); + private: + RefPtr m_indexRegister; + }; - void setIsNumericCompareFunction(bool isNumericCompareFunction); + struct TryData { + RefPtr