Skip to content

Commit

Permalink
format code
Browse files Browse the repository at this point in the history
  • Loading branch information
bbrk24 committed Oct 7, 2024
1 parent c8d1963 commit 4d72d79
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/assembly_scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ const std::vector<instruction>& assembly_scanner::get_fragments() {
// We need to do two passes: one to resolve labels, and one to assign targets to jumps. During the first pass, the
// fragments are actually constructed. However, jumps may not have valid targets yet, so we need some way to store
// the label's name inside an IP. This code relies on the following assumption:
static_assert(
sizeof(NONNULL_PTR(const string)) <= sizeof(IP), "Cannot fit string pointer inside IP"
);
static_assert(sizeof(NONNULL_PTR(const string)) <= sizeof(IP), "Cannot fit string pointer inside IP");
// Using an ordered set over any other container so that references are not invalidated after insertion
std::set<string> label_names;

Expand All @@ -41,7 +39,7 @@ const std::vector<instruction>& assembly_scanner::get_fragments() {
iter = p.first;
}
NONNULL_PTR(const string) ptr = &*iter;
return reinterpret_cast<uintptr_t>(ptr) ;
return reinterpret_cast<uintptr_t>(ptr);
};

// First pass
Expand Down
2 changes: 1 addition & 1 deletion src/assembly_scanner.hh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public:
[[maybe_unused]] auto _ = get_fragments();
return std::string(m_slices[ip]);
}
inline std::pair<size_t, size_t> get_coords(const IP& ip) const { return {SIZE_C(0), ip}; }
inline std::pair<size_t, size_t> get_coords(const IP& ip) const { return { SIZE_C(0), ip }; }
inline instruction at(const IP& ip) { return get_fragments()[ip]; }
private:
void fake_location_to_real(std::pair<size_t, size_t>& p) const;
Expand Down
8 changes: 4 additions & 4 deletions src/disassembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,17 @@ void disassembler::to_str(const instruction& i, std::ostream& os) {
return;
}
case operation::JMP: {
pair<size_t, size_t> target = i.get_arg().next;
const pair<size_t, size_t>& target = i.get_arg().next;
os << "JMP " << target.first << "." << target.second;
return;
}
case operation::BNG: {
pair<size_t, size_t> target = i.get_arg().choice.second;
const pair<size_t, size_t>& target = i.get_arg().choice.second;
os << "BNG " << target.first << "." << target.second;
return;
}
case operation::TSP: {
pair<size_t, size_t> target = i.get_arg().choice.second;
const pair<size_t, size_t>& target = i.get_arg().choice.second;
os << "TSP " << target.first << "." << target.second;
return;
}
Expand Down Expand Up @@ -104,7 +104,7 @@ void disassembler::write_state(std::ostream& os) {
to_str(ins, os);

// if it's a branch followed by a jump, write that
const std::pair<size_t, size_t>* next = ins.first_if_branch();
const pair<size_t, size_t>* next = ins.first_if_branch();
if (next != nullptr && (next->first != i + 1 || next->second != 0)) {
os << "\n\tJMP " << next->first << '.' << next->second;
}
Expand Down

0 comments on commit 4d72d79

Please sign in to comment.