Home | History | Annotate | Download | only in simulator
      1 /*
      2  * Copyright (C) 2015 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include "simulator/code_simulator_arm64.h"
     18 
     19 namespace art {
     20 namespace arm64 {
     21 
     22 // VIXL has not been tested on 32bit architectures, so vixl::Simulator is not always
     23 // available. To avoid linker error on these architectures, we check if we can simulate
     24 // in the beginning of following methods, with compile time constant `kCanSimulate`.
     25 // TODO: when vixl::Simulator is always available, remove the these checks.
     26 
     27 CodeSimulatorArm64* CodeSimulatorArm64::CreateCodeSimulatorArm64() {
     28   if (kCanSimulate) {
     29     return new CodeSimulatorArm64();
     30   } else {
     31     return nullptr;
     32   }
     33 }
     34 
     35 CodeSimulatorArm64::CodeSimulatorArm64()
     36     : CodeSimulator(), decoder_(nullptr), simulator_(nullptr) {
     37   DCHECK(kCanSimulate);
     38   decoder_ = new vixl::Decoder();
     39   simulator_ = new vixl::Simulator(decoder_);
     40 }
     41 
     42 CodeSimulatorArm64::~CodeSimulatorArm64() {
     43   DCHECK(kCanSimulate);
     44   delete simulator_;
     45   delete decoder_;
     46 }
     47 
     48 void CodeSimulatorArm64::RunFrom(intptr_t code_buffer) {
     49   DCHECK(kCanSimulate);
     50   simulator_->RunFrom(reinterpret_cast<const vixl::Instruction*>(code_buffer));
     51 }
     52 
     53 bool CodeSimulatorArm64::GetCReturnBool() const {
     54   DCHECK(kCanSimulate);
     55   return simulator_->wreg(0);
     56 }
     57 
     58 int32_t CodeSimulatorArm64::GetCReturnInt32() const {
     59   DCHECK(kCanSimulate);
     60   return simulator_->wreg(0);
     61 }
     62 
     63 int64_t CodeSimulatorArm64::GetCReturnInt64() const {
     64   DCHECK(kCanSimulate);
     65   return simulator_->xreg(0);
     66 }
     67 
     68 }  // namespace arm64
     69 }  // namespace art
     70