Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(394)

Side by Side Diff: runtime/vm/unit_test.h

Issue 1283733003: VM: Refactor assembler test that rely on the constant pool. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Added comments, fixed that pass in Thread Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/assembler_x64_test.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef VM_UNIT_TEST_H_ 5 #ifndef VM_UNIT_TEST_H_
6 #define VM_UNIT_TEST_H_ 6 #define VM_UNIT_TEST_H_
7 7
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 9
10 #include "platform/globals.h" 10 #include "platform/globals.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 } 316 }
317 Isolate* isolate() const { return isolate_; } 317 Isolate* isolate() const { return isolate_; }
318 318
319 private: 319 private:
320 Isolate* isolate_; 320 Isolate* isolate_;
321 321
322 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope); 322 DISALLOW_COPY_AND_ASSIGN(TestIsolateScope);
323 }; 323 };
324 324
325 325
326 template<typename T> struct is_void {
327 static const bool value = false;
328 };
329
330
331 template<> struct is_void<void> {
332 static const bool value = true;
333 };
334
335
336 template<typename T> struct is_double {
337 static const bool value = false;
338 };
339
340
341 template<> struct is_double<double> {
342 static const bool value = true;
343 };
344
345
326 class AssemblerTest { 346 class AssemblerTest {
327 public: 347 public:
328 AssemblerTest(const char* name, Assembler* assembler) 348 AssemblerTest(const char* name, Assembler* assembler)
329 : name_(name), 349 : name_(name),
330 assembler_(assembler), 350 assembler_(assembler),
331 code_(Code::ZoneHandle()) { 351 code_(Code::ZoneHandle()) {
332 ASSERT(name != NULL); 352 ASSERT(name != NULL);
333 ASSERT(assembler != NULL); 353 ASSERT(assembler != NULL);
334 } 354 }
335 ~AssemblerTest() { } 355 ~AssemblerTest() { }
336 356
337 Assembler* assembler() const { return assembler_; } 357 Assembler* assembler() const { return assembler_; }
338 358
339 const Code& code() const { return code_; } 359 const Code& code() const { return code_; }
340 360
341 uword entry() const { return entry_; } 361 uword entry() const { return code_.EntryPoint(); }
342 362
343 // Assemble test and set code_ and entry_. 363 // Invoke is used to call assembler test functions using the ABI calling
364 // convention.
365 // ResultType is the return type of the assembler test function.
366 // ArgNType is the type of the Nth argument.
367 #if defined(USING_SIMULATOR)
368
369 #if defined(ARCH_IS_64_BIT)
370 // TODO(fschneider): Make Invoke<> more general and work on 32-bit platforms.
371 // Since Simulator::Call always return a int64_t, bit_cast does not work
372 // on 32-bit platforms when returning an int32_t. Since template functions
373 // don't support partial specialization, we'd need to introduce a helper
374 // class to support 32-bit return types.
375 template<typename ResultType> ResultType Invoke() {
376 const bool fp_return = is_double<ResultType>::value;
377 const bool fp_args = false;
378 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call(
379 bit_cast<intptr_t, uword>(entry()), 0, 0, 0, 0, fp_return, fp_args));
380 }
381 template<typename ResultType, typename Arg1Type>
382 ResultType Invoke(Arg1Type arg1) {
383 const bool fp_return = is_double<ResultType>::value;
384 const bool fp_args = is_double<Arg1Type>::value;
385 // TODO(fschneider): Support double arguments for simulator calls.
386 COMPILE_ASSERT(!fp_args);
387 return bit_cast<ResultType, int64_t>(Simulator::Current()->Call(
388 bit_cast<intptr_t, uword>(entry()),
389 reinterpret_cast<intptr_t>(arg1),
390 0, 0, 0, fp_return, fp_args));
391 }
392 #endif // ARCH_IS_64_BIT
393
394 template<typename ResultType,
395 typename Arg1Type,
396 typename Arg2Type,
397 typename Arg3Type>
398 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) {
399 // TODO(fschneider): Support double arguments for simulator calls.
400 COMPILE_ASSERT(is_void<ResultType>::value);
401 COMPILE_ASSERT(!is_double<Arg1Type>::value);
402 COMPILE_ASSERT(!is_double<Arg2Type>::value);
403 COMPILE_ASSERT(!is_double<Arg3Type>::value);
404 const bool fp_args = false;
405 const bool fp_return = false;
406 Simulator::Current()->Call(
407 bit_cast<intptr_t, uword>(entry()),
408 reinterpret_cast<intptr_t>(arg1),
409 reinterpret_cast<intptr_t>(arg2),
410 reinterpret_cast<intptr_t>(arg3),
411 0, fp_return, fp_args);
412 }
413 #else
414 template<typename ResultType> ResultType Invoke() {
415 typedef ResultType (*FunctionType) ();
416 return reinterpret_cast<FunctionType>(entry())();
417 }
418
419 template<typename ResultType, typename Arg1Type>
420 ResultType Invoke(Arg1Type arg1) {
421 typedef ResultType (*FunctionType) (Arg1Type);
422 return reinterpret_cast<FunctionType>(entry())(arg1);
423 }
424
425 template<typename ResultType,
426 typename Arg1Type,
427 typename Arg2Type,
428 typename Arg3Type>
429 ResultType Invoke(Arg1Type arg1, Arg2Type arg2, Arg3Type arg3) {
430 typedef ResultType (*FunctionType) (Arg1Type, Arg2Type, Arg3Type);
431 return reinterpret_cast<FunctionType>(entry())(arg1, arg2, arg3);
432 }
433 #endif // USING_SIMULATOR
434
435 // Assemble test and set code_.
344 void Assemble(); 436 void Assemble();
345 437
346 private: 438 private:
347 const char* name_; 439 const char* name_;
348 Assembler* assembler_; 440 Assembler* assembler_;
349 Code& code_; 441 Code& code_;
350 uword entry_;
351 442
352 DISALLOW_COPY_AND_ASSIGN(AssemblerTest); 443 DISALLOW_COPY_AND_ASSIGN(AssemblerTest);
353 }; 444 };
354 445
355 446
356 class CodeGenTest { 447 class CodeGenTest {
357 public: 448 public:
358 explicit CodeGenTest(const char* name); 449 explicit CodeGenTest(const char* name);
359 ~CodeGenTest() { } 450 ~CodeGenTest() { }
360 451
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } \ 517 } \
427 } else { \ 518 } else { \
428 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \ 519 dart::Expect(__FILE__, __LINE__).Fail("expected True, but was '%s'\n", \
429 #handle); \ 520 #handle); \
430 } \ 521 } \
431 } while (0) 522 } while (0)
432 523
433 } // namespace dart 524 } // namespace dart
434 525
435 #endif // VM_UNIT_TEST_H_ 526 #endif // VM_UNIT_TEST_H_
OLDNEW
« no previous file with comments | « runtime/vm/assembler_x64_test.cc ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698