Skip to content

Commit

Permalink
Code cleanup (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcauberer committed Jun 15, 2024
1 parent 5e7c92e commit 4317330
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/irgenerator/DebugInfoGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void DebugInfoGenerator::initialize(const std::string &sourceFileName, std::file
voidTy = diBuilder->createBasicType("void", 0, llvm::dwarf::DW_ATE_unsigned);

// Initialize fat ptr type
llvm::Type *ptrTy = llvm::PointerType::get(context, 0);
llvm::PointerType *ptrTy = irGenerator->builder.getPtrTy();
if (!irGenerator->llvmTypes.fatPtrType)
irGenerator->llvmTypes.fatPtrType = llvm::StructType::get(context, {ptrTy, ptrTy});

Expand Down
6 changes: 2 additions & 4 deletions src/irgenerator/GenExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,6 @@ std::any IRGenerator::visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) {
case PostfixUnaryExprNode::OP_SUBSCRIPT: {
lhsSTy = lhsSTy.removeReferenceWrapper();

// Get the LLVM type of the operand
llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);

// Get the index value
AssignExprNode *indexExpr = node->assignExpr();
llvm::Value *indexValue = resolveValue(indexExpr);
Expand All @@ -671,6 +668,7 @@ std::any IRGenerator::visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) {
resolveAddress(lhs);

// Calculate address of array item
llvm::Type *lhsTy = lhsSTy.toLLVMType(sourceFile);
llvm::Value *indices[2] = {builder.getInt32(0), indexValue};
lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indices);
} else { // Pointer
Expand All @@ -681,7 +679,7 @@ std::any IRGenerator::visitPostfixUnaryExpr(const PostfixUnaryExprNode *node) {
// Now the pointer is the value
lhs.ptr = lhs.value;

lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
llvm::Type *lhsTy = lhsSTy.getContained().toLLVMType(sourceFile);
// Calculate address of pointer item
lhs.ptr = insertInBoundsGEP(lhsTy, lhs.ptr, indexValue);
}
Expand Down
4 changes: 2 additions & 2 deletions src/irgenerator/GenTopLevelDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ std::any IRGenerator::visitMainFctDef(const MainFctDefNode *node) {
assert(resultEntry != nullptr);
resultEntry->updateAddress(resultAddress);
// Generate debug info
diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddress, SIZE_MAX);
diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddress);
// Store the default result value
insertStore(builder.getInt32(0), resultAddress);

Expand Down Expand Up @@ -240,7 +240,7 @@ std::any IRGenerator::visitFctDef(const FctDefNode *node) {
assert(resultEntry != nullptr);
resultEntry->updateAddress(resultAddr);
// Generate debug info
diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr, SIZE_MAX);
diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr);

// Store function argument values
for (auto &arg : func->args()) {
Expand Down
5 changes: 2 additions & 3 deletions src/irgenerator/GenVTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ llvm::Constant *IRGenerator::generateVTable(StructBase *spiceStruct) {
generateTypeInfo(spiceStruct);

// Generate VTable type
llvm::PointerType *ptrTy = llvm::PointerType::get(context, 0);
llvm::ArrayType *vtableArrayTy = llvm::ArrayType::get(ptrTy, arrayElementCount);
llvm::ArrayType *vtableArrayTy = llvm::ArrayType::get(builder.getPtrTy(), arrayElementCount);
spiceStruct->vTableData.vtableType = llvm::StructType::get(context, vtableArrayTy, false);

const std::string mangledName = NameMangling::mangleVTable(spiceStruct);
Expand All @@ -119,7 +118,7 @@ void IRGenerator::generateVTableInitializer(StructBase *spiceStruct) {
const size_t arrayElementCount = virtualMethodCount + 2; // +2 for nullptr and TypeInfo

// Generate VTable type
llvm::PointerType *ptrTy = llvm::PointerType::get(context, 0);
llvm::PointerType *ptrTy = builder.getPtrTy();
llvm::ArrayType *vtableArrayTy = llvm::ArrayType::get(ptrTy, arrayElementCount);
assert(spiceStruct->vTableData.vtableType);

Expand Down
2 changes: 1 addition & 1 deletion src/irgenerator/GenValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ std::any IRGenerator::visitLambdaFunc(const LambdaFuncNode *node) {
llvm::Value *resultAddr = insertAlloca(returnType, RETURN_VARIABLE_NAME);
resultEntry->updateAddress(resultAddr);
// Generate debug info
diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr, SIZE_MAX);
diGenerator.generateLocalVarDebugInfo(RETURN_VARIABLE_NAME, resultAddr);

// Store function argument values
llvm::Value *captureStructPtrPtr = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/symboltablebuilder/SymbolTableBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ std::any SymbolTableBuilder::visitMainFctDef(MainFctDefNode *node) {
mainFctEntry->used = true;

// Create scope for main function body
const std::string scopeId = MainFctDefNode::getScopeId();
const std::string &scopeId = MainFctDefNode::getScopeId();
node->bodyScope = currentScope = rootScope->createChildScope(scopeId, ScopeType::FUNC_PROC_BODY, &node->codeLoc);
currentScope->isGenericScope = false;

Expand Down

0 comments on commit 4317330

Please sign in to comment.