Improved compile times

Added A LOT of comments
This commit is contained in:
Pasha Bibko
2025-04-20 19:32:25 +01:00
parent 680a3d1323
commit 6ba9f8e596
15 changed files with 286 additions and 149 deletions

View File

@@ -2,51 +2,66 @@
#include <LLVM.h>
#include <Util.h>
#include <AST.h>
namespace LX::AST
{
llvm::Value* NumberLiteral::GenIR(llvm::LLVMContext& context, llvm::Module& module, llvm::IRBuilder<>& builder)
// Function for generating LLVN IR (Intermediate representation) //
llvm::Value* NumberLiteral::GenIR(InfoLLVM& LLVM)
{
// Converts the string to it's int equivalent
// Will eventually need to do floating point stuff here as well
// Converts the string to it's int equivalent //
// TODO: Support floating point values //
int number = std::stoi(m_Number);
// Returns it as a llvm value (if valid)
llvm::Value* out = llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), number, true);
// Returns it as a llvm value (if valid) //
// TODO: Support floating point values //
// TODO: Make the error actually output information //
llvm::Value* out = llvm::ConstantInt::get(llvm::Type::getInt32Ty(LLVM.context), number, true);
ThrowIf<IRGenerationError>(out == nullptr);
return out;
}
llvm::Value* Operation::GenIR(llvm::LLVMContext& context, llvm::Module& module, llvm::IRBuilder<>& builder)
// Function for generating LLVN IR (Intermediate representation) //
llvm::Value* Operation::GenIR(InfoLLVM& LLVM)
{
// Gets the IR for both sides of the operation
llvm::Value* lhs = m_Lhs->GenIR(context, module, builder);
llvm::Value* rhs = m_Rhs->GenIR(context, module, builder);
// Generates the IR for both sides of the operation //
llvm::Value* lhs = m_Lhs->GenIR(LLVM);
llvm::Value* rhs = m_Rhs->GenIR(LLVM);
// If either side is null then return null to prevent invalid IR //
// TODO: Make the error actually output information //
if (lhs == nullptr || rhs == nullptr)
{
ThrowIf<IRGenerationError>(true);
return nullptr;
}
// Will eventually get the correct operator but for now everything is add
llvm::Value* out = builder.CreateAdd(lhs, rhs);
// Generates the IR of the operation //
// TODO: Support other operators other than ADD //
// TODO: Make the error actually output information //
llvm::Value* out = LLVM.builder.CreateAdd(lhs, rhs);
ThrowIf<IRGenerationError>(out == nullptr);
return out;
}
llvm::Value* ReturnStatement::GenIR(llvm::LLVMContext& context, llvm::Module& module, llvm::IRBuilder<>& builder)
// Function for generating LLVN IR (Intermediate representation) //
llvm::Value* ReturnStatement::GenIR(InfoLLVM& LLVM)
{
// Checks if it is a void return //
if (m_Val == nullptr)
{
// Void returns are currently not implemented //
// TODO: Find out how to return nothing from a function //
ThrowIf<IRGenerationError>(true);
return nullptr;
}
// Else it will be returning a value //
else
{
llvm::Value* out = builder.CreateRet(m_Val->GenIR(context, module, builder));
// Generates the value and creates a return for it //
// TODO: Make the error actually output information //
llvm::Value* out = LLVM.builder.CreateRet(m_Val->GenIR(LLVM));
ThrowIf<IRGenerationError>(out == nullptr);
return out;
}