Skip to content

Commit

Permalink
Refactor index logic
Browse files Browse the repository at this point in the history
  • Loading branch information
leewei05 authored and Lai-YT committed Aug 9, 2024
1 parent 1702799 commit 8d0e0e9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/llvm_ir_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,15 @@ void LLVMIRGenerator::Visit(const RecordVarDeclNode& record_var_decl) {
auto init_val = val_recorder.ValOfPrevExpr();

llvm::Value* res_addr = nullptr;
if (record_des_vals.empty()) {
res_addr = builder_.CreateStructGEP(type, base_addr, i);
} else {
auto init_index = i;
if (!record_des_vals.empty()) {
// TODO: consider array index designators.
// NOTE: Only consider identifer designators for now.
assert(record_des_vals.size() == 1);
auto mem_index =
init_index =
record_type.MemberIndex(std::get<std::string>(record_des_vals.at(0)));
res_addr = builder_.CreateStructGEP(type, base_addr, mem_index);
}
res_addr = builder_.CreateStructGEP(type, base_addr, init_index);
builder_.CreateStore(init_val, res_addr);
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/qbe_ir_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,8 @@ void QbeIrGenerator::Visit(const RecordVarDeclNode& record_var_decl) {
init->Accept(*this);
const auto init_num = num_recorder.NumOfPrevExpr();

std::size_t offset = 0;
if (record_des_vals.empty()) {
offset = record_type.OffsetOf(i);
} else {
std::size_t offset = record_type.OffsetOf(i);
if (!record_des_vals.empty()) {
// TODO: consider array index designators.
// NOTE: Only consider identifer designators for now.
assert(record_des_vals.size() == 1);
Expand Down

0 comments on commit 8d0e0e9

Please sign in to comment.