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

Updated nyxstone.cpp #72

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Updated nyxstone.cpp #72

wants to merge 3 commits into from

Conversation

sad-c0der
Copy link

Added for loop for readability, changed a couple of things and confirmed that it builds successfully and works as intended, minor update

Added for loop for readability, changed a couple of things and confirmed that it builds successfully and works as intended, minor update
Copy link
Collaborator

@stuxnot stuxnot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for the PR. Before merging it, I would need you to rebase it on master, incorporate the requested changes, and improve the commit message to make it clear what the actual changes are. Also, your current changes introduce a bug. You can reproduce it by running the example binary after building, or running make/ninja test in the build directory (depending on the build tool you are using).

src/nyxstone.cpp Outdated Show resolved Hide resolved
src/nyxstone.cpp Outdated Show resolved Hide resolved
src/nyxstone.cpp Outdated Show resolved Hide resolved
src/nyxstone.cpp Outdated Show resolved Hide resolved
I've added the loop you suggested and refactored some of the code for efficiency and readability.
@sad-c0der sad-c0der closed this Nov 16, 2024
@sad-c0der sad-c0der reopened this Nov 16, 2024
@sad-c0der
Copy link
Author

I have tested this change in build/ directory using make test and it returns success, I've also used tool/format.sh to fix any formatting issues.

Copy link
Collaborator

@stuxnot stuxnot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for making the changes I requested. I've reviewed the new changes and still have some small nitpicks.

Also regarding the commit history: We are trying to keep the commit history of the main branch relatively clean and clear. When I asked you to improve the commit description and rebase on main, I meant to use git rebase to rewrite the branch history to use the current main as the basis and to actually rewrite the commits so that the messages are descriptive. This would allow us to merge your changes without squashing the commit history.

One last thing, please do not write something like "improves efficiency" into the commit messages if you have no metric to back up this claim. If you want to keep such a message, please show some evidence that the changes had a measurable and reproducible impact on the performance of Nyxstone.

This is all minor stuff, just wanted to let you know. If you are not sure how to rewrite the commit history - don't worry. I'll just squash your commits and add a short merge commit description of my own, since your changes should fit a single commit. If you have any questions, feel free to ask :)

Comment on lines +455 to +457
Instruction new_insn{address + pos, insn_str, {}};
new_insn.bytes.assign(data.begin() + pos, data.begin() + pos + insn_size);
instructions->push_back(std::move(new_insn));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are touching this code anyway, in my opinion doing

            auto insn_bytes = data.slice(pos, insn_size);
            Instruction new_insn { address + pos, insn_str, std::move(insn_bytes) };
            instructions->push_back(std::move(new_insn));

is a bit clearer.

if (!error_msg.empty()) {
error_stream << "(= " << error_msg.c_str() << " )";
error_stream << " (= " << error_msg.c_str() << ")";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a reason to touch the whitespaces in the error string (at least in this PR), especially since we are planning to rewrite the error handling anyway. Please revert this change.


// We exit either if we reached the end of the provided bytes, or if we have disassembled as many instructions
// as the user has requested
while (pos < data.size() && (disassemble_all || insn_count < count)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You re-added the conditions that you removed earlier from the end of this loop, i.e. lines 462-464 and 467-469. These conditions are redundant because of the conditions in the while loop. Please remove them.

Comment on lines -422 to -423
uint64_t pos = 0;
uint64_t insn_count = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please leave these two in seperate lines. We try to use this style of variable initialization as the single line initialization can easily lead to forgetting to assign a value to a variable.

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

Successfully merging this pull request may close these issues.

2 participants