Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error lex/parsing-ing formatted output. #2346

Open
Sladkoeshechka opened this issue Jan 31, 2025 · 3 comments
Open

Error lex/parsing-ing formatted output. #2346

Sladkoeshechka opened this issue Jan 31, 2025 · 3 comments
Labels
formatter Verilog code formatter issues

Comments

@Sladkoeshechka
Copy link

Test case

class unit_calculator extends unit_base;
  `uvm_component_utils(test::unit_calculator)

  local axi4stream::cfg cfg;
  local axi4stream::item in;
  local axi4stream::item golden;
  local tb_util::calculator sut;

  function new(string name = get_type_name(), uvm_component parent = null);
    super.new(name, parent);
  endfunction

  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    build_cfg();
    sut = new();
  endfunction

  local function void build_cfg();
    cfg = axi4stream::cfg::type_id::create("cfg");
    assert (cfg.randomize() with {
      bus.omit.id == 1;
      bus.omit.dest == 1;
      bus.omit.user == 1;
      bus.omit.ready == 0;
      bus.omit.keep == 0;
      bus.omit.strobe == 0;
      bus.omit.last == 0;

      bus.width.data == axi4stream::MAX_DATA_WIDTH;
    });
  endfunction

  function void run_tests();
    test_one_mixed_transfer();
    test_two_mixed_transfers();
    test_only_data();
    test_only_position();
    test_only_null();
    test_two_null_transfers();
    test_two_not_full_transfers();
  endfunction

  local function void test_one_mixed_transfer();
    setup_test("one_mixed_transfer");

    initialize_data(in, 1);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::RESERVED, 'h4),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::DATA, 'h6),
      get_byte(axi4stream::byte_qualifier::DATA, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8)
    });

    initialize_data(golden, 1);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::DATA, 'h6),
      get_byte(axi4stream::byte_qualifier::DATA, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4)
    });

    assert_sut();
  endfunction

  local function void setup_test(string name);
    `uvm_info(get_type_name(), $sformatf("Running test %s", name), UVM_LOW)
    setup_fields();
  endfunction

  local function void setup_fields();
    setup_in();
    setup_golden();
  endfunction

  local function void setup_in();
    in = axi4stream::item::type_id::create("in");
    in.set_cfg(cfg);
    assert(in.randomize());
  endfunction

  local function void setup_golden();
    golden = axi4stream::item::type_id::create("golden");
    golden.set_cfg(cfg);
    assert(golden.randomize());
  endfunction

  local function void initialize_data(axi4stream::item item, util::uint32_t count);
    axi4stream::transfer_data_q data = {};
    repeat(count) begin
      data.push_back(get_tranfser_data());
    end
    item.set_data_q(data);
  endfunction

  local function axi4stream::transfer_data get_tranfser_data();
    axi4stream::transfer_data result = axi4stream::transfer_data::type_id::create("result");
    result.set_cfg(cfg);
    assert(result.randomize());
    return result;
  endfunction

  local function axi4stream::data_byte get_byte(axi4stream::byte_qualifier::t qualifier, util::uint8_t data);
    return axi4stream::data_byte::get_inst(.cfg(cfg), .qualifier(qualifier), .data(data));
  endfunction

  local function void assert_sut();
    assert(golden.compare(sut.calculate(in))) else begin
      golden.print();
      sut.calculate(in).print();
    end
  endfunction

  local function void test_two_mixed_transfers();
    setup_test("two_mixed_transfers");

    initialize_data(in, 2);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::RESERVED, 'h4),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::DATA, 'h6),
      get_byte(axi4stream::byte_qualifier::DATA, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });
    in.get_data(1).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::RESERVED, 'h4),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8)
    });

    initialize_data(golden, 2);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::DATA, 'h6),
      get_byte(axi4stream::byte_qualifier::DATA, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h3),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5)
    });
    golden.get_data(1).set_bytes({
      get_byte(axi4stream::byte_qualifier::POSITION, 'h1),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4)
    });

    assert_sut();
  endfunction

  local function void test_only_data();
    setup_test("only_data");

    initialize_data(in, 1);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::DATA, 'h2),
      get_byte(axi4stream::byte_qualifier::DATA, 'h3),
      get_byte(axi4stream::byte_qualifier::DATA, 'h4),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::DATA, 'h6),
      get_byte(axi4stream::byte_qualifier::DATA, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8)
    });

    initialize_data(golden, 1);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::DATA, 'h2),
      get_byte(axi4stream::byte_qualifier::DATA, 'h3),
      get_byte(axi4stream::byte_qualifier::DATA, 'h4),
      get_byte(axi4stream::byte_qualifier::DATA, 'h5),
      get_byte(axi4stream::byte_qualifier::DATA, 'h6),
      get_byte(axi4stream::byte_qualifier::DATA, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8)
    });

    assert_sut();
  endfunction

  local function void test_only_position();
    setup_test("only_position");

    initialize_data(in, 1);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::POSITION, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h3),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h4),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h5),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h6),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h7),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h8)
    });

    initialize_data(golden, 1);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::POSITION, 'h1),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h2),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h3),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h4),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h5),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h6),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h7),
      get_byte(axi4stream::byte_qualifier::POSITION, 'h8)
    });

    assert_sut();
  endfunction

  local function void test_only_null();
    setup_test("only_null");

    initialize_data(in, 1);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::NULL, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });

    initialize_data(golden, 1);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::NULL, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });

    assert_sut();
  endfunction

  local function void test_two_null_transfers();
    setup_test("two_null_transfers");

    initialize_data(in, 2);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::NULL, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });
    in.get_data(1).set_bytes({
      get_byte(axi4stream::byte_qualifier::NULL, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });

    initialize_data(golden, 1);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::NULL, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });

    assert_sut();
  endfunction

  local function void test_two_not_full_transfers();
    setup_test("two_not_full_transfers");

    initialize_data(in, 2);
    in.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::DATA, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });
    in.get_data(1).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::NULL, 'h2),
      get_byte(axi4stream::byte_qualifier::NULL, 'h3),
      get_byte(axi4stream::byte_qualifier::NULL, 'h4),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8)
    });

    initialize_data(golden, 1);
    golden.get_data(0).set_bytes({
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::DATA, 'h3),
      get_byte(axi4stream::byte_qualifier::DATA, 'h1),
      get_byte(axi4stream::byte_qualifier::DATA, 'h8),
      get_byte(axi4stream::byte_qualifier::NULL, 'h5),
      get_byte(axi4stream::byte_qualifier::NULL, 'h6),
      get_byte(axi4stream::byte_qualifier::NULL, 'h7),
      get_byte(axi4stream::byte_qualifier::NULL, 'h8)
    });

    assert_sut();
  endfunction
endclass

Include any options or configuration used.

--column_limit=120
--indentation_spaces=2
--assignment_statement_alignment=infer
--case_items_alignment=infer
--compact_indexing_and_selections=true
--distribution_items_alignment=infer
--enum_assignment_statement_alignment=infer
--expand_coverpoints=true
--formal_parameters_alignment=infer
--formal_parameters_indentation=indent
--module_net_variable_alignment=infer
--named_parameter_alignment=infer
--named_parameter_indentation=indent
--named_port_alignment=infer
--named_port_indentation=indent
--port_declarations_alignment=infer
--port_declarations_indentation=indent
--port_declarations_right_align_packed_dimensions=true
--port_declarations_right_align_unpacked_dimensions=true
--struct_union_members_alignment=infer
--wrap_end_else_clauses=true

Actual output

class unit_calculator extends unit_base;
  `uvm_component_utils(test::unit_calculator)

  local axi4stream::cfg cfg;
  local axi4stream::item in;
  local axi4stream::item golden;
  local tb_util::calculator sut;

  function new(string name = get_type_name(), uvm_component parent = null);
    super.new(name, parent);
  endfunction

  virtual function void build_phase(uvm_phase phase);
    super.build_phase(phase);
    build_cfg();
    sut = new();
  endfunction

  local function void build_cfg();
    cfg = axi4stream::cfg::type_id::create("cfg");
    assert (cfg.randomize() with {
      bus.omit.id == 1;
      bus.omit.dest == 1;
      bus.omit.user == 1;
      bus.omit.ready == 0;
      bus.omit.keep == 0;
      bus.omit.strobe == 0;
      bus.omit.last == 0;

      bus.width.data == axi4stream::MAX_DATA_WIDTH;
    });
  endfunction

  function void run_tests();
    test_one_mixed_transfer();
    test_two_mixed_transfers();
    test_only_data();
    test_only_position();
    test_only_null();
    test_two_null_transfers();
    test_two_not_full_transfers();
  endfunction

  local function void test_one_mixed_transfer();
    setup_test("one_mixed_transfer");

    initialize_data(in, 1);
    in.get_data(0).set_bytes(










    initialize_data(golden, 1);
    golden.get_data(0).set_bytes(










    assert_sut();
  endfunction

  local function void setup_test(string name);
    `uvm_info(get_type_name(), $sformatf("Running test %s", name), UVM_LOW)
    setup_fields();
  endfunction

  local function void setup_fields();
    setup_in();
    setup_golden();
  endfunction

  local function void setup_in();
    in = axi4stream::item::type_id::create("in");
    in.set_cfg(cfg);
    assert (in.randomize());
  endfunction

  local function void setup_golden();
    golden = axi4stream::item::type_id::create("golden");
    golden.set_cfg(cfg);
    assert (golden.randomize());
  endfunction

  local function void initialize_data(axi4stream::item item, util::uint32_t count);
    axi4stream::transfer_data_q data = {};
    repeat (count) begin
      data.push_back(get_tranfser_data());
    end
    item.set_data_q(data);
  endfunction

  local function axi4stream::transfer_data get_tranfser_data();
    axi4stream::transfer_data result = axi4stream::transfer_data::type_id::create("result");
    result.set_cfg(cfg);
    assert (result.randomize());
    return result;
  endfunction

  local function axi4stream::data_byte get_byte(axi4stream::byte_qualifier::t qualifier, util::uint8_t data);
    return axi4stream::data_byte::get_inst(.cfg(cfg), .qualifier(qualifier), .data(data));
  endfunction

  local function void assert_sut();
    assert (golden.compare(sut.calculate(in)))
    else begin
      golden.print();
      sut.calculate(in).print();
    end
  endfunction

  local function void test_two_mixed_transfers();
    setup_test("two_mixed_transfers");

    initialize_data(in, 2);
    in.get_data(0).set_bytes(









    in.get_data(1).set_bytes(










    initialize_data(golden, 2);
    golden.get_data(0).set_bytes(









    golden.get_data(1).set_bytes(










    assert_sut();
  endfunction

  local function void test_only_data();
    setup_test("only_data");

    initialize_data(in, 1);
    in.get_data(0).set_bytes(










    initialize_data(golden, 1);
    golden.get_data(0).set_bytes(










    assert_sut();
  endfunction

  local function void test_only_position();
    setup_test("only_position");

    initialize_data(in, 1);
    in.get_data(0).set_bytes(










    initialize_data(golden, 1);
    golden.get_data(0).set_bytes(










    assert_sut();
  endfunction

  local function void test_only_null();
    setup_test("only_null");

    initialize_data(in, 1);
    in.get_data(0).set_bytes(










    initialize_data(golden, 1);
    golden.get_data(0).set_bytes(










    assert_sut();
  endfunction

  local function void test_two_null_transfers();
    setup_test("two_null_transfers");

    initialize_data(in, 2);
    in.get_data(0).set_bytes(









    in.get_data(1).set_bytes(










    initialize_data(golden, 1);
    golden.get_data(0).set_bytes(










    assert_sut();
  endfunction

  local function void test_two_not_full_transfers();
    setup_test("two_not_full_transfers");

    initialize_data(in, 2);
    in.get_data(0).set_bytes(









    in.get_data(1).set_bytes(










    initialize_data(golden, 1);
    golden.get_data(0).set_bytes(










    assert_sut();
  endfunction
endclass

Include any possible diagnostic messages from the formatter.

/home/tsymbalenko-dn/test_verible/unit_calculator.svh: Error lex/parsing-ing formatted output. Please file a bug.
First error: token: ";" at 59:31:; problematic formatter output is

Expected or suggested output

// This result would look better from the formatter.

Citations to published style guides would help.

@Sladkoeshechka Sladkoeshechka added the formatter Verilog code formatter issues label Jan 31, 2025
@hzeller
Copy link
Collaborator

hzeller commented Jan 31, 2025

Uh, thanks for the report.

Current formatter is indeed broken for this input. I tried with a very old one and that seems to work fine. Will bisect to see where this got wrong.

@hzeller
Copy link
Collaborator

hzeller commented Feb 2, 2025

Alright bi-sected. Looks like this is broken for a while since 3c9419c (@mglb FYI).

I currently don't have much time to look into it in detail, but the change looks fairly small, so possibly not too hard to find the issue.

@hzeller
Copy link
Collaborator

hzeller commented Feb 2, 2025

This was the corresponding pull request for more context #834

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Verilog code formatter issues
Projects
None yet
Development

No branches or pull requests

2 participants