Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
dart::AssemblerTest Class Reference

#include <unit_test.h>

Public Member Functions

 AssemblerTest (const char *name, compiler::Assembler *assembler, Zone *zone)
 
 ~AssemblerTest ()
 
compiler::Assemblerassembler () const
 
const Codecode () const
 
uword payload_start () const
 
uword payload_size () const
 
uword entry () const
 
template<typename ResultType >
ResultType InvokeWithCodeAndThread ()
 
template<typename ResultType , typename Arg1Type >
ResultType InvokeWithCodeAndThread (Arg1Type arg1)
 
template<typename ResultType , typename Arg1Type >
ResultType Invoke (Arg1Type arg1)
 
template<typename ResultType , typename Arg1Type , typename Arg2Type , typename Arg3Type >
ResultType Invoke (Arg1Type arg1, Arg2Type arg2, Arg3Type arg3)
 
void Assemble ()
 
char * RelativeDisassembly ()
 

Static Public Member Functions

static const CodeGenerate (const char *name, const std::function< void(compiler::Assembler *assembler)> &generator)
 

Detailed Description

Definition at line 503 of file unit_test.h.

Constructor & Destructor Documentation

◆ AssemblerTest()

dart::AssemblerTest::AssemblerTest ( const char *  name,
compiler::Assembler assembler,
Zone zone 
)
inline

Definition at line 505 of file unit_test.h.

506 : name_(name),
507 assembler_(assembler),
508 code_(Code::ZoneHandle(zone)),
509 disassembly_(zone->Alloc<char>(DISASSEMBLY_SIZE)) {
510 ASSERT(name != nullptr);
511 ASSERT(assembler != nullptr);
512 }
compiler::Assembler * assembler() const
Definition: unit_test.h:515
static Object & ZoneHandle()
Definition: object.h:419
#define ASSERT(E)
const char *const name

◆ ~AssemblerTest()

dart::AssemblerTest::~AssemblerTest ( )
inline

Definition at line 513 of file unit_test.h.

513{}

Member Function Documentation

◆ Assemble()

void dart::AssemblerTest::Assemble ( )

Definition at line 703 of file unit_test.cc.

703 {
704 auto thread = Thread::Current();
705 const String& function_name = String::ZoneHandle(Symbols::New(thread, name_));
706
707 // We make a dummy script so that exception objects can be composed for
708 // assembler instructions that do runtime calls.
709 const char* kDummyScript = "assembler_test_dummy_function() {}";
710 const Script& script = Script::Handle(
712 const Library& lib = Library::Handle(Library::CoreLibrary());
713 const Class& cls = Class::ZoneHandle(
715 const FunctionType& signature = FunctionType::ZoneHandle(FunctionType::New());
717 signature, function_name, UntaggedFunction::kRegularFunction, true, false,
718 false, false, false, cls, TokenPosition::kMinSource));
719 SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
720 code_ = Code::FinalizeCodeAndNotify(function, nullptr, assembler_,
722 code_.set_owner(function);
723 code_.set_exception_handlers(Object::empty_exception_handlers());
724#ifndef PRODUCT
725 // Disassemble relative since code addresses are not stable from run to run.
726 SetFlagScope<bool> sfs(&FLAG_disassemble_relative, true);
727 uword start = code_.PayloadStart();
728 if (FLAG_disassemble) {
729 OS::PrintErr("Code for test '%s' {\n", name_);
730 Disassembler::Disassemble(start, start + assembler_->CodeSize());
731 OS::PrintErr("}\n");
732 }
733 Disassembler::Disassemble(start, start + assembler_->CodeSize(), disassembly_,
734 DISASSEMBLY_SIZE);
735#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
736 // Blank out absolute addressing constants on ia32, since they are not stable
737 // from run to run.
738 // Blank out thread-relative offsets on x64 since they change when new fields
739 // are added to thread object.
740 bool in_hex_constant = false;
741 for (char* p = disassembly_; *p != '\0'; p++) {
742 if (in_hex_constant) {
743 if (IsHex(*p)) {
744 *p = '.';
745 } else {
746 in_hex_constant = false;
747 }
748 } else {
749#if defined(TARGET_ARCH_IA32)
750 if (*p == '[' && *(p + 1) == '0' && *(p + 2) == 'x' && IsHex(*(p + 3)) &&
751 IsHex(*(p + 4))) {
752 p += 2;
753 in_hex_constant = true;
754 }
755#endif // defined(TARGET_ARCH_IA32)
756#if defined(TARGET_ARCH_X64)
757 if (*p == '[' && *(p + 1) == 't' && *(p + 2) == 'h' && *(p + 3) == 'r' &&
758 *(p + 4) == '+' && *(p + 5) == '0' && *(p + 6) == 'x' &&
759 IsHex(*(p + 7)) && IsHex(*(p + 8))) {
760 p += 6;
761 in_hex_constant = true;
762 }
763#endif // defined(TARGET_ARCH_X64)
764 }
765 }
766#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
767#endif // !PRODUCT
768}
static ClassPtr New(IsolateGroup *isolate_group, bool register_class=true)
Definition: object.cc:3053
void set_exception_handlers(const ExceptionHandlers &handlers) const
Definition: object.h:7119
static CodePtr FinalizeCodeAndNotify(const Function &function, FlowGraphCompiler *compiler, compiler::Assembler *assembler, PoolAttachment pool_attachment, bool optimized=false, CodeStatistics *stats=nullptr)
Definition: object.cc:17983
uword PayloadStart() const
Definition: object.h:6850
void set_owner(const Object &owner) const
Definition: object.cc:17636
static void Disassemble(uword start, uword end, DisassemblyFormatter *formatter, const Code &code, const CodeComments *comments=nullptr)
static FunctionTypePtr New(intptr_t num_parent_type_arguments=0, Nullability nullability=Nullability::kNonNullable, Heap::Space space=Heap::kOld)
Definition: object.cc:11631
static FunctionPtr New(const FunctionType &signature, const String &name, UntaggedFunction::Kind kind, bool is_static, bool is_const, bool is_abstract, bool is_external, bool is_native, const Object &owner, TokenPosition token_pos, Heap::Space space=Heap::kOld)
Definition: object.cc:10243
static LibraryPtr CoreLibrary()
Definition: object.cc:14787
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static Object & Handle()
Definition: object.h:407
static ScriptPtr New(const String &url, const String &source)
Definition: object.cc:13451
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static StringPtr New(Thread *thread, const char *cstr)
Definition: symbols.h:723
static Thread * Current()
Definition: thread.h:362
static const TokenPosition kMinSource
Dart_NativeFunction function
Definition: fuchsia.cc:51
uintptr_t uword
Definition: globals.h:501
const char *const function_name

◆ assembler()

compiler::Assembler * dart::AssemblerTest::assembler ( ) const
inline

Definition at line 515 of file unit_test.h.

515{ return assembler_; }

◆ code()

const Code & dart::AssemblerTest::code ( ) const
inline

Definition at line 517 of file unit_test.h.

517{ return code_; }

◆ entry()

uword dart::AssemblerTest::entry ( ) const
inline

Definition at line 521 of file unit_test.h.

521{ return code_.EntryPoint(); }
uword EntryPoint() const
Definition: object.h:6864

◆ Generate()

const Code & dart::AssemblerTest::Generate ( const char *  name,
const std::function< void(compiler::Assembler *assembler)> &  generator 
)
static

Definition at line 770 of file unit_test.cc.

772 {
773 compiler::ObjectPoolBuilder object_pool_builder;
774 compiler::Assembler assembler(&object_pool_builder, /*far_branch_level=*/0);
776 assembler.Ret();
777 test.Assemble();
778 return test.code();
779}
#define test(name)
AssemblerTest(const char *name, compiler::Assembler *assembler, Zone *zone)
Definition: unit_test.h:505
void Ret(Condition cond=AL)

◆ Invoke() [1/2]

template<typename ResultType , typename Arg1Type >
ResultType dart::AssemblerTest::Invoke ( Arg1Type  arg1)
inline

Definition at line 601 of file unit_test.h.

601 {
602 typedef ResultType (*FunctionType)(Arg1Type);
603 return reinterpret_cast<FunctionType>(entry())(arg1);
604 }
uword entry() const
Definition: unit_test.h:521
static CompileType * ResultType(Definition *call)

◆ Invoke() [2/2]

template<typename ResultType , typename Arg1Type , typename Arg2Type , typename Arg3Type >
ResultType dart::AssemblerTest::Invoke ( Arg1Type  arg1,
Arg2Type  arg2,
Arg3Type  arg3 
)
inline

Definition at line 610 of file unit_test.h.

610 {
611 typedef ResultType (*FunctionType)(Arg1Type, Arg2Type, Arg3Type);
612 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3);
613 }

◆ InvokeWithCodeAndThread() [1/2]

template<typename ResultType >
ResultType dart::AssemblerTest::InvokeWithCodeAndThread ( )
inline

Definition at line 585 of file unit_test.h.

585 {
586 Thread* thread = Thread::Current();
587 ASSERT(thread != nullptr);
588 typedef ResultType (*FunctionType)(CodePtr, Thread*);
589 return reinterpret_cast<FunctionType>(entry())(code_.ptr(), thread);
590 }
ObjectPtr ptr() const
Definition: object.h:332

◆ InvokeWithCodeAndThread() [2/2]

template<typename ResultType , typename Arg1Type >
ResultType dart::AssemblerTest::InvokeWithCodeAndThread ( Arg1Type  arg1)
inline

Definition at line 593 of file unit_test.h.

593 {
594 Thread* thread = Thread::Current();
595 ASSERT(thread != nullptr);
596 typedef ResultType (*FunctionType)(CodePtr, Thread*, Arg1Type);
597 return reinterpret_cast<FunctionType>(entry())(code_.ptr(), thread, arg1);
598 }

◆ payload_size()

uword dart::AssemblerTest::payload_size ( ) const
inline

Definition at line 520 of file unit_test.h.

520{ return assembler_->CodeSize(); }

◆ payload_start()

uword dart::AssemblerTest::payload_start ( ) const
inline

Definition at line 519 of file unit_test.h.

519{ return code_.PayloadStart(); }

◆ RelativeDisassembly()

char * dart::AssemblerTest::RelativeDisassembly ( )
inline

Definition at line 620 of file unit_test.h.

620{ return disassembly_; }

The documentation for this class was generated from the following files: