Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 510 of file unit_test.h.

Constructor & Destructor Documentation

◆ AssemblerTest()

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

Definition at line 512 of file unit_test.h.

513 : name_(name),
514 assembler_(assembler),
515 code_(Code::ZoneHandle(zone)),
516 disassembly_(zone->Alloc<char>(DISASSEMBLY_SIZE)) {
517 ASSERT(name != nullptr);
518 ASSERT(assembler != nullptr);
519 }
compiler::Assembler * assembler() const
Definition unit_test.h:522
static Object & ZoneHandle()
Definition object.h:419
#define ASSERT(E)
const char *const name

◆ ~AssemblerTest()

dart::AssemblerTest::~AssemblerTest ( )
inline

Definition at line 520 of file unit_test.h.

520{}

Member Function Documentation

◆ Assemble()

void dart::AssemblerTest::Assemble ( )

Definition at line 689 of file unit_test.cc.

689 {
690 auto thread = Thread::Current();
691 const String& function_name = String::ZoneHandle(Symbols::New(thread, name_));
692
693 // We make a dummy script so that exception objects can be composed for
694 // assembler instructions that do runtime calls.
695 const char* kDummyScript = "assembler_test_dummy_function() {}";
696 const Script& script = Script::Handle(
698 const Library& lib = Library::Handle(Library::CoreLibrary());
699 const Class& cls = Class::ZoneHandle(
701 const FunctionType& signature = FunctionType::ZoneHandle(FunctionType::New());
703 signature, function_name, UntaggedFunction::kRegularFunction, true, false,
704 false, false, false, cls, TokenPosition::kMinSource));
705 SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
706 code_ = Code::FinalizeCodeAndNotify(function, nullptr, assembler_,
708 code_.set_owner(function);
709 code_.set_exception_handlers(Object::empty_exception_handlers());
710#ifndef PRODUCT
711 // Disassemble relative since code addresses are not stable from run to run.
712 SetFlagScope<bool> sfs(&FLAG_disassemble_relative, true);
713 uword start = code_.PayloadStart();
714 if (FLAG_disassemble) {
715 OS::PrintErr("Code for test '%s' {\n", name_);
717 OS::PrintErr("}\n");
718 }
719 Disassembler::Disassemble(start, start + assembler_->CodeSize(), disassembly_,
720 DISASSEMBLY_SIZE);
721#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
722 // Blank out absolute addressing constants on ia32, since they are not stable
723 // from run to run.
724 // Blank out thread-relative offsets on x64 since they change when new fields
725 // are added to thread object.
726 bool in_hex_constant = false;
727 for (char* p = disassembly_; *p != '\0'; p++) {
728 if (in_hex_constant) {
729 if (IsHex(*p)) {
730 *p = '.';
731 } else {
732 in_hex_constant = false;
733 }
734 } else {
735#if defined(TARGET_ARCH_IA32)
736 if (*p == '[' && *(p + 1) == '0' && *(p + 2) == 'x' && IsHex(*(p + 3)) &&
737 IsHex(*(p + 4))) {
738 p += 2;
739 in_hex_constant = true;
740 }
741#endif // defined(TARGET_ARCH_IA32)
742#if defined(TARGET_ARCH_X64)
743 if (*p == '[' && *(p + 1) == 't' && *(p + 2) == 'h' && *(p + 3) == 'r' &&
744 *(p + 4) == '+' && *(p + 5) == '0' && *(p + 6) == 'x' &&
745 IsHex(*(p + 7)) && IsHex(*(p + 8))) {
746 p += 6;
747 in_hex_constant = true;
748 }
749#endif // defined(TARGET_ARCH_X64)
750 }
751 }
752#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64)
753#endif // !PRODUCT
754}
static ClassPtr New(IsolateGroup *isolate_group, bool register_class=true)
Definition object.cc:3114
void set_exception_handlers(const ExceptionHandlers &handlers) const
Definition object.h:7090
static CodePtr FinalizeCodeAndNotify(const Function &function, FlowGraphCompiler *compiler, compiler::Assembler *assembler, PoolAttachment pool_attachment, bool optimized=false, CodeStatistics *stats=nullptr)
Definition object.cc:18033
uword PayloadStart() const
Definition object.h:6823
void set_owner(const Object &owner) const
Definition object.cc:17686
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::kLegacy, Heap::Space space=Heap::kOld)
Definition object.cc:11682
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:10301
static LibraryPtr CoreLibrary()
Definition object.cc:14834
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:13498
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition object.cc:23777
static StringPtr New(Thread *thread, const char *cstr)
Definition symbols.h:722
static Thread * Current()
Definition thread.h:361
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 522 of file unit_test.h.

522{ return assembler_; }

◆ code()

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

Definition at line 524 of file unit_test.h.

524{ return code_; }

◆ entry()

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

Definition at line 528 of file unit_test.h.

528{ return code_.EntryPoint(); }
uword EntryPoint() const
Definition object.h:6837

◆ Generate()

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

Definition at line 756 of file unit_test.cc.

758 {
759 compiler::ObjectPoolBuilder object_pool_builder;
760 compiler::Assembler assembler(&object_pool_builder, /*far_branch_level=*/0);
762 assembler.Ret();
763 test.Assemble();
764 return test.code();
765}
AssemblerTest(const char *name, compiler::Assembler *assembler, Zone *zone)
Definition unit_test.h:512
void Ret(Condition cond=AL)

◆ Invoke() [1/2]

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

Definition at line 608 of file unit_test.h.

608 {
609 typedef ResultType (*FunctionType)(Arg1Type);
610 return reinterpret_cast<FunctionType>(entry())(arg1);
611 }
uword entry() const
Definition unit_test.h:528
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 617 of file unit_test.h.

617 {
618 typedef ResultType (*FunctionType)(Arg1Type, Arg2Type, Arg3Type);
619 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3);
620 }

◆ InvokeWithCodeAndThread() [1/2]

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

Definition at line 592 of file unit_test.h.

592 {
593 Thread* thread = Thread::Current();
594 ASSERT(thread != nullptr);
595 typedef ResultType (*FunctionType)(CodePtr, Thread*);
596 return reinterpret_cast<FunctionType>(entry())(code_.ptr(), thread);
597 }
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 600 of file unit_test.h.

600 {
601 Thread* thread = Thread::Current();
602 ASSERT(thread != nullptr);
603 typedef ResultType (*FunctionType)(CodePtr, Thread*, Arg1Type);
604 return reinterpret_cast<FunctionType>(entry())(code_.ptr(), thread, arg1);
605 }

◆ payload_size()

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

Definition at line 527 of file unit_test.h.

527{ return assembler_->CodeSize(); }

◆ payload_start()

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

Definition at line 526 of file unit_test.h.

526{ return code_.PayloadStart(); }

◆ RelativeDisassembly()

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

Definition at line 627 of file unit_test.h.

627{ return disassembly_; }

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