Skip to content

Commit

Permalink
use correct loctr counter while evaluating dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
slavek-kucera committed Dec 14, 2021
1 parent 04063cf commit a44c9e0
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 43 deletions.
10 changes: 6 additions & 4 deletions parser_library/src/processing/instruction_sets/asm_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ void asm_processor::process_data_instruction(rebuilt_statement stmt)
const auto start = it;

const auto initial_alignment = (*it)->access_data_def()->value->get_alignment();
context::address op_loctr = hlasm_ctx.ord_ctx.align(initial_alignment);
data_def_dependency_solver op_solver(dep_solver, &op_loctr);

auto current_alignment = initial_alignment;

// has_length_dependencies specifies whether the length of the data instruction can be resolved right now or
Expand All @@ -302,17 +305,16 @@ void asm_processor::process_data_instruction(rebuilt_statement stmt)
break;
current_alignment = op_align;

has_dependencies |= data_op->has_dependencies(dep_solver);
has_dependencies |= data_op->has_dependencies(op_solver);

has_length_dependencies |= data_op->get_length_dependencies(dep_solver).contains_dependencies();
has_length_dependencies |= data_op->get_length_dependencies(op_solver).contains_dependencies();

// some types require operands that consist only of one symbol
(void)data_op->value->check_single_symbol_ok(diagnostic_collector(this));
}

const auto* b = &*start;
const auto* e = b + (it - start);
auto op_loctr = hlasm_ctx.ord_ctx.align(initial_alignment);

if (has_length_dependencies)
{
Expand All @@ -321,7 +323,7 @@ void asm_processor::process_data_instruction(rebuilt_statement stmt)
}
else
{
auto length = data_def_dependency<instr_type>::get_operands_length(b, e, dep_solver, std::move(op_loctr));
auto length = data_def_dependency<instr_type>::get_operands_length(b, e, op_solver);
hlasm_ctx.ord_ctx.reserve_storage_area(length, context::no_align);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,43 +28,12 @@ data_def_postponed_statement<instr_type>::data_def_postponed_statement(rebuilt_s
, m_dependencies(std::move(dependencies))
{}

namespace {
struct data_def_dependency_solver final : public context::dependency_solver
{
explicit data_def_dependency_solver(context::dependency_solver& base, const std::optional<context::address>& loctr)
: base(base)
, loctr(loctr)
{}
context::dependency_solver& base;
const std::optional<context::address>& loctr;
uint64_t operands_bit_length = 0;

const context::symbol* get_symbol(context::id_index name) const override { return base.get_symbol(name); }
std::optional<context::address> get_loctr() const override
{
if (loctr.has_value())
return loctr.value() + (int)(operands_bit_length / 8);
if (auto l = base.get_loctr(); l.has_value())
return l.value() + (int)(operands_bit_length / 8);

return std::nullopt;
}
context::id_index get_literal_id(const std::string& text,
const std::shared_ptr<const expressions::data_definition>& dd,
const range& r,
bool align_on_halfword) override
{
return base.get_literal_id(text, dd, r, align_on_halfword);
}
};
} // namespace

// Inherited via resolvable
template<checking::data_instr_type instr_type>
context::dependency_collector data_def_dependency<instr_type>::get_dependencies(
context::dependency_solver& _solver) const
{
data_def_dependency_solver solver(_solver, m_loctr);
data_def_dependency_solver solver(_solver, &m_loctr);
context::dependency_collector conjunction;
for (auto it = m_begin; it != m_end; ++it)
{
Expand All @@ -73,15 +42,14 @@ context::dependency_collector data_def_dependency<instr_type>::get_dependencies(
continue;
conjunction = conjunction + op->access_data_def()->get_length_dependencies(solver);
}
conjunction = conjunction + m_loctr;
return conjunction;
}

template<checking::data_instr_type instr_type>
int32_t data_def_dependency<instr_type>::get_operands_length(const semantics::operand_ptr* b,
const semantics::operand_ptr* e,
context::dependency_solver& _solver,
std::optional<context::address> loctr)
const context::address* loctr)
{
data_def_dependency_solver solver(_solver, loctr);

Expand Down Expand Up @@ -127,12 +95,35 @@ int32_t data_def_dependency<instr_type>::get_operands_length(const semantics::op
template<checking::data_instr_type instr_type>
context::symbol_value data_def_dependency<instr_type>::resolve(context::dependency_solver& solver) const
{
return get_operands_length(m_begin, m_end, solver, m_loctr);
return get_operands_length(m_begin, m_end, solver, &m_loctr);
}

template class data_def_postponed_statement<checking::data_instr_type::DC>;
template class data_def_postponed_statement<checking::data_instr_type::DS>;
template class data_def_dependency<checking::data_instr_type::DC>;
template class data_def_dependency<checking::data_instr_type::DS>;

const context::symbol* data_def_dependency_solver::get_symbol(context::id_index name) const
{
return base.get_symbol(name);
}

std::optional<context::address> data_def_dependency_solver::get_loctr() const
{
if (loctr)
return *loctr + (int)(operands_bit_length / 8);
if (auto l = base.get_loctr(); l.has_value())
return l.value() + (int)(operands_bit_length / 8);

return std::nullopt;
}

context::id_index data_def_dependency_solver::get_literal_id(const std::string& text,
const std::shared_ptr<const expressions::data_definition>& dd,
const range& r,
bool align_on_halfword)
{
return base.get_literal_id(text, dd, r, align_on_halfword);
}

} // namespace hlasm_plugin::parser_library::processing
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class data_def_dependency final : public context::resolvable
static int32_t get_operands_length(const semantics::operand_ptr* b,
const semantics::operand_ptr* e,
context::dependency_solver& _solver,
std::optional<context::address> loctr);
const context::address* loctr = nullptr);

// Inherited via resolvable
context::dependency_collector get_dependencies(context::dependency_solver& solver) const override;
Expand All @@ -59,5 +59,24 @@ class data_def_postponed_statement final : public postponed_statement_impl
const std::vector<data_def_dependency<instr_type>>& get_dependencies() const { return m_dependencies; }
};

struct data_def_dependency_solver final : public context::dependency_solver
{
data_def_dependency_solver(context::dependency_solver& base, const context::address* loctr)
: base(base)
, loctr(loctr)
{}

context::dependency_solver& base;
const context::address* loctr;
uint64_t operands_bit_length = 0;

const context::symbol* get_symbol(context::id_index name) const override;
std::optional<context::address> get_loctr() const override;
context::id_index get_literal_id(const std::string& text,
const std::shared_ptr<const expressions::data_definition>& dd,
const range& r,
bool align_on_halfword) override;
};

} // namespace hlasm_plugin::parser_library::processing
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ TEST(data_def_operands_length, all_bit_len)
context::ordinary_assembly_dependency_solver dep_solver(ctx.ord_ctx);

EXPECT_EQ(processing::data_def_dependency<data_instr_type::DC>::get_operands_length(
list.data(), list.data() + list.size(), dep_solver, std::nullopt),
list.data(), list.data() + list.size(), dep_solver),
2);
}

Expand All @@ -53,7 +53,7 @@ TEST(data_def_operands_length, byte_in_middle_len)
context::ordinary_assembly_dependency_solver dep_solver(ctx.ord_ctx);

EXPECT_EQ(processing::data_def_dependency<data_instr_type::DC>::get_operands_length(
list.data(), list.data() + list.size(), dep_solver, std::nullopt),
list.data(), list.data() + list.size(), dep_solver),
9);
}

Expand All @@ -67,7 +67,7 @@ TEST(data_def_operands_length, explicit_byte)
context::ordinary_assembly_dependency_solver dep_solver(ctx.ord_ctx);

EXPECT_EQ(processing::data_def_dependency<data_instr_type::DC>::get_operands_length(
list.data(), list.data() + list.size(), dep_solver, std::nullopt),
list.data(), list.data() + list.size(), dep_solver),
12);
}

Expand Down

0 comments on commit a44c9e0

Please sign in to comment.