mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Removed LLVM
This commit is contained in:
@@ -132,8 +132,6 @@
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\AST-Constructors.cpp" />
|
||||
<ClCompile Include="src\AST-LLVM.cpp" />
|
||||
<ClCompile Include="src\GenIR.cpp" />
|
||||
<ClCompile Include="src\Parser.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
|
||||
@@ -14,14 +14,8 @@
|
||||
<ClCompile Include="src\Parser.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\AST-LLVM.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\AST-Constructors.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="src\GenIR.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,54 +0,0 @@
|
||||
#include <Parser.h>
|
||||
|
||||
#include <LLVM.h>
|
||||
#include <Util.h>
|
||||
|
||||
namespace LX::AST
|
||||
{
|
||||
llvm::Value* NumberLiteral::GenIR(llvm::LLVMContext& context, llvm::Module& module, llvm::IRBuilder<>& builder)
|
||||
{
|
||||
// Converts the string to it's int equivalent
|
||||
// Will eventually need to do floating point stuff here as well
|
||||
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);
|
||||
ThrowIf<IRGenerationError>(out == nullptr);
|
||||
return out;
|
||||
}
|
||||
|
||||
llvm::Value* Operation::GenIR(llvm::LLVMContext& context, llvm::Module& module, llvm::IRBuilder<>& builder)
|
||||
{
|
||||
// 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);
|
||||
|
||||
// If either side is null then return null to prevent invalid IR //
|
||||
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);
|
||||
ThrowIf<IRGenerationError>(out == nullptr);
|
||||
return out;
|
||||
}
|
||||
|
||||
llvm::Value* ReturnStatement::GenIR(llvm::LLVMContext& context, llvm::Module& module, llvm::IRBuilder<>& builder)
|
||||
{
|
||||
if (m_Val == nullptr)
|
||||
{
|
||||
ThrowIf<IRGenerationError>(true);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
llvm::Value* out = builder.CreateRet(m_Val->GenIR(context, module, builder));
|
||||
ThrowIf<IRGenerationError>(out == nullptr);
|
||||
return out;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
#include <Parser.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace LX
|
||||
{
|
||||
void GenerateIR(FileAST& ast)
|
||||
{
|
||||
// Generates stuff //
|
||||
|
||||
llvm::LLVMContext context;
|
||||
llvm::IRBuilder<> builder(context);
|
||||
|
||||
{
|
||||
std::unique_ptr<llvm::Module> module = std::make_unique<llvm::Module>("add_ints", context);
|
||||
|
||||
// Defines main function //
|
||||
|
||||
llvm::FunctionType* funcType = llvm::FunctionType::get(llvm::Type::getInt32Ty(context), false);
|
||||
llvm::Function* mainFunc = llvm::Function::Create(funcType, llvm::Function::ExternalLinkage, "main", module.get());
|
||||
llvm::BasicBlock* entry = llvm::BasicBlock::Create(context, "entry", mainFunc);
|
||||
builder.SetInsertPoint(entry);
|
||||
|
||||
// Loops over AST to generate IR //
|
||||
|
||||
for (auto& node : ast.functions[0].body)
|
||||
{
|
||||
switch (node->m_Type)
|
||||
{
|
||||
case AST::Node::RETURN_STATEMENT:
|
||||
{
|
||||
node->GenIR(context, *module, builder);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (entry->getTerminator() == nullptr)
|
||||
{
|
||||
builder.CreateRet(llvm::ConstantInt::get(llvm::Type::getInt32Ty(context), 0, true));
|
||||
}
|
||||
|
||||
// Verification of the IR //
|
||||
|
||||
if (llvm::verifyFunction(*mainFunc, &llvm::errs()) || llvm::verifyModule(*module, &llvm::errs()))
|
||||
{
|
||||
std::cerr << "Error: IR generation failed" << std::endl;
|
||||
return;
|
||||
}
|
||||
|
||||
// Outputs the IR to the console //
|
||||
|
||||
module->print(llvm::outs(), nullptr);
|
||||
|
||||
} // <- Crashes here
|
||||
|
||||
std::cout << "Finished generating IR" << std::endl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user