Ejemplo n.º 1
0
void Builder::EmitI(Instruction& inst) {
  if (!curr_block_) {
    DEBUG_FORMAT("discard %s", inst);
    return;
  }

  ++num_insts_;
  inst.SetSourceInfo(&source_info_);
  inst.SetIndex(num_insts_);
  curr_block_->AppendI(inst);
  DEBUG_FORMAT("%s", inst);
}
Ejemplo n.º 2
0
// [R]
void CompileSession::RecordErrorInfo(const ErrorInfo& templ) {
  DEBUG_FORMAT("%s", templ);

  static bool fContinue = false;
  if (!fContinue && ::IsDebuggerPresent()) {
    __debugbreak();
    fContinue = true;
  }

  if (error_set_.Contains(&templ)) {
    return;
  }

  auto& error_info = templ.Clone();

  error_set_.Add(&error_info);

  auto ref = errors_.GetLast();
  while (ref) {
    if (error_info.source_info() > ref->source_info()) {
      break;
    }
    ref = ref->GetPrev();
  }
  if (ref) {
    errors_.InsertAfter(&error_info, ref);
  } else {
    errors_.Prepend(&error_info);
  }
}
Ejemplo n.º 3
0
BBlock& Builder::NewBBlock() {
  auto& bblock = const_cast<BBlock&>(module_.NewBBlock());
  const_cast<Function&>(function_).InsertBefore(
      bblock, 
      *function_.GetExitBB());
  DEBUG_FORMAT("BB%d", bblock.name());
  return bblock;
}
Ejemplo n.º 4
0
void Builder::EmitJumpI(BBlock& bblock) {
  if (!curr_block_) {
    return;
  }

  DEBUG_FORMAT("jump from %s to %s", *curr_block_, bblock);
  EmitI(*new(zone()) JumpI(&bblock));
}
Ejemplo n.º 5
0
/// <summary>
///   <list type="number">
///     <item>Set output type of PrologueI.</item>
///     <item>Load parameters</item>
///   </list>
/// </summary>
void Builder::SetUpMethodBody(Function& fun, MethodDef& method_def) {
  auto const pPrologueI = fun.GetStartBB()->GetFirstI();
  auto const pRefI = pPrologueI->GetNext();
  auto const pBB = pPrologueI->GetBBlock();
  auto& v1 = *pPrologueI->GetVd();

  ValuesTypeBuilder tybuilder(
      method_def.IsStatic()
          ? method_def.CountParams()
          : method_def.CountParams() + 1);

  auto nth = 0;

  // "this" parameter.
  if (!method_def.IsStatic()) {
    tybuilder.Append(method_def.owner_class_def().GetClass());
    nth++;
  }

  foreach (MethodDef::EnumParam, oEnum, method_def) {
    auto const pParamDef = oEnum.Get();
    auto& var = pParamDef->GetVariable();
    auto& varty = var.GetTy();
    tybuilder.Append(varty);
    DEBUG_FORMAT("%s %s", varty, var);

    auto& cell_class = Ty_ClosedCell->Construct(varty);
    //auto& r2 = *NewOutput(varty).StaticCast<Register>();
    auto& r2 = *NewOutput(varty).StaticCast<Register>();
    r2.SetVariable(var);

    auto const pSelectI = new(zone()) SelectI(varty, r2, v1, nth);
    pSelectI->SetSourceInfo(pParamDef->GetSourceInfo());
    pBB->InsertBeforeI(*pSelectI, pRefI);

    auto& r3 = NewRegister();
    auto& vardef_inst = *new(zone()) VarDefI(cell_class, r3, var, r2);
    vardef_inst.set_source_info(pParamDef->source_info());
    pBB->InsertBeforeI(vardef_inst, pRefI);

    ++nth;
  }
Ejemplo n.º 6
0
// [A]
const Type& TypeVar::And(const Type& type) {
  Type::Set tyset;
  if (auto const tyvar = type.DynamicCast<TypeVar>()) {
    for (auto const a: types_) {
      ASSERT(!a->Is<TypeVar>());
      for (auto& b: tyvar->types_) {
        ASSERT(!b->Is<TypeVar>());
        auto& c = TypeAnd(*a, *b);
        if (c == *Ty_Object) {
          tyset.Add(a);
          tyset.Add(b);
        } else if (c != *Ty_Void) {
          tyset.Add(&c);
        }
      }
    }
  } else {
    for (auto const a: types_) {
      ASSERT(!a->Is<TypeVar>());
      auto const b = &type;
      ASSERT(!b->Is<TypeVar>());
      auto const c = &TypeAnd(*a, *b);
        if (c == Ty_Object) {
          tyset.Add(a);
          tyset.Add(b);
        } else if (c != Ty_Void) {
          tyset.Add(c);
        }
    }
  }

  types_.Clear();
  types_.AddAll(tyset);

  #ifdef _DEBUG
    if (!types_.Count()) {
      DEBUG_FORMAT("%s is now empty!", *this);
    }
  #endif

  return *this;
}
Ejemplo n.º 7
0
Archivo: archive.c Proyecto: devyn/kit
bool archive_verify(archive_entry_t *entry, uint8_t *buffer) {
  uint64_t checksum = 0;

  uint64_t word = 0;
  int count = 0;

  for (size_t i = 0; i < entry->length; i++) {
    word |= ((uint64_t) buffer[i]) << (count * 8);

    if (++count == 8) {
      checksum ^= word;
      word = 0;
      count = 0;
    }
  }

  if (entry->checksum != checksum) {
    DEBUG_FORMAT("entry checksum %lx != calculated checksum %lx",
        entry->checksum, checksum);
  }

  return entry->checksum == checksum;
}
Ejemplo n.º 8
0
TokenBox::~TokenBox() {
  DEBUG_FORMAT("[%s] %s %s", token_->ref_count(), token_->GetKind(), *token_);
}