1// Copyright 2014 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "src/ic/access-compiler.h"
6#include "src/objects-inl.h"
7
8namespace v8 {
9namespace internal {
10
11
12Handle<Code> PropertyAccessCompiler::GetCodeWithFlags(Code::Flags flags,
13                                                      const char* name) {
14  // Create code object in the heap.
15  CodeDesc desc;
16  masm()->GetCode(&desc);
17  Handle<Code> code = factory()->NewCode(desc, flags, masm()->CodeObject());
18  if (code->IsCodeStubOrIC()) code->set_stub_key(CodeStub::NoCacheKey());
19#ifdef ENABLE_DISASSEMBLER
20  if (FLAG_print_code_stubs) {
21    CodeTracer::Scope trace_scope(isolate()->GetCodeTracer());
22    OFStream os(trace_scope.file());
23    code->Disassemble(name, os);
24  }
25#endif
26  return code;
27}
28
29
30Handle<Code> PropertyAccessCompiler::GetCodeWithFlags(Code::Flags flags,
31                                                      Handle<Name> name) {
32  return (FLAG_print_code_stubs && !name.is_null() && name->IsString())
33             ? GetCodeWithFlags(flags,
34                                Handle<String>::cast(name)->ToCString().get())
35             : GetCodeWithFlags(flags, NULL);
36}
37
38
39void PropertyAccessCompiler::TailCallBuiltin(MacroAssembler* masm,
40                                             Builtins::Name name) {
41  Handle<Code> code(masm->isolate()->builtins()->builtin(name));
42  GenerateTailCall(masm, code);
43}
44
45Register* PropertyAccessCompiler::GetCallingConvention(Isolate* isolate,
46                                                       Code::Kind kind) {
47  AccessCompilerData* data = isolate->access_compiler_data();
48  if (!data->IsInitialized()) {
49    InitializePlatformSpecific(data);
50  }
51  if (kind == Code::LOAD_IC || kind == Code::KEYED_LOAD_IC) {
52    return data->load_calling_convention();
53  }
54  DCHECK(kind == Code::STORE_IC || kind == Code::KEYED_STORE_IC);
55  return data->store_calling_convention();
56}
57
58
59Register PropertyAccessCompiler::slot() const {
60  if (kind() == Code::LOAD_IC || kind() == Code::KEYED_LOAD_IC) {
61    return LoadDescriptor::SlotRegister();
62  }
63  DCHECK(kind() == Code::STORE_IC || kind() == Code::KEYED_STORE_IC);
64  return StoreWithVectorDescriptor::SlotRegister();
65}
66
67
68Register PropertyAccessCompiler::vector() const {
69  if (kind() == Code::LOAD_IC || kind() == Code::KEYED_LOAD_IC) {
70    return LoadWithVectorDescriptor::VectorRegister();
71  }
72  DCHECK(kind() == Code::STORE_IC || kind() == Code::KEYED_STORE_IC);
73  return StoreWithVectorDescriptor::VectorRegister();
74}
75}  // namespace internal
76}  // namespace v8
77