MCPcopy Create free account
hub / github.com/danoon2/Boxedwine / embed_label_delta

Method embed_label_delta

lib/asmjit/asmjit/core/assembler.cpp:324–393  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324Error BaseAssembler::embed_label_delta(const Label& label, const Label& base, size_t data_size) {
325 if (ASMJIT_UNLIKELY(!_code)) {
326 return report_error(make_error(Error::kNotInitialized));
327 }
328
329 if (ASMJIT_UNLIKELY(!Support::bool_and(_code->is_label_valid(label), _code->is_label_valid(base)))) {
330 return report_error(make_error(Error::kInvalidLabel));
331 }
332
333 LabelEntry& label_entry = _code->label_entry_of(label);
334 LabelEntry& base_entry = _code->label_entry_of(base);
335
336 if (data_size == 0) {
337 data_size = register_size();
338 }
339
340 if (ASMJIT_UNLIKELY(!Support::is_power_of_2_up_to(data_size, 8u))) {
341 return report_error(make_error(Error::kInvalidOperandSize));
342 }
343
344 CodeWriter writer(this);
345 ASMJIT_PROPAGATE(writer.ensure_space(this, data_size));
346
347#ifndef ASMJIT_NO_LOGGING
348 if (_logger) {
349 StringTmp<256> sb;
350 sb.append('.');
351 Formatter::format_data_type(sb, _logger->flags(), arch(), data_type_id_by_size_table[data_size]);
352 sb.append(" (");
353 Formatter::format_label(sb, FormatFlags::kNone, this, label.id());
354 sb.append(" - ");
355 Formatter::format_label(sb, FormatFlags::kNone, this, base.id());
356 sb.append(")\n");
357 _logger->log(sb);
358 }
359#endif
360
361 // If both labels are bound within the same section it means the delta can be calculated now.
362 if (label_entry.is_bound() && base_entry.is_bound() && label_entry.section_id() == base_entry.section_id()) {
363 uint64_t delta = label_entry.offset() - base_entry.offset();
364 writer.emit_value_le(delta, data_size);
365 }
366 else {
367 RelocEntry* re;
368 Error err = _code->new_reloc_entry(Out(re), RelocType::kExpression);
369 if (ASMJIT_UNLIKELY(err != Error::kOk)) {
370 return report_error(err);
371 }
372
373 Expression* exp = _code->_arena.new_oneshot<Expression>();
374 if (ASMJIT_UNLIKELY(!exp)) {
375 return report_error(make_error(Error::kOutOfMemory));
376 }
377
378 exp->reset();
379 exp->op_type = ExpressionOpType::kSub;
380 exp->set_value_as_label_id(0, label.id());
381 exp->set_value_as_label_id(1, base.id());

Callers

nothing calls this directly

Calls 15

report_errorFunction · 0.85
make_errorFunction · 0.85
bool_andFunction · 0.85
is_power_of_2_up_toFunction · 0.85
format_data_typeFunction · 0.85
format_labelFunction · 0.85
OutClass · 0.85
ensure_spaceMethod · 0.80
logMethod · 0.80
is_boundMethod · 0.80
emit_value_leMethod · 0.80
new_reloc_entryMethod · 0.80

Tested by

no test coverage detected