Made the process actually output to the file

This commit is contained in:
Pasha Bibko
2025-04-21 15:56:10 +01:00
parent feea149cc1
commit c8001a3a58
5 changed files with 18 additions and 9 deletions

View File

@@ -46,6 +46,7 @@ int main(int argc, char** argv)
// Opens / Creates the output file //
std::ofstream outFile(outPath);
LX::ThrowIf<LX::InvalidOutputFilePath>(outFile.is_open() == false);
outFile.close(); // Opened just to check we can
// Opens the log file (if there is one specified //
if (argc == 4)
@@ -67,7 +68,7 @@ int main(int argc, char** argv)
LX::SafeFlush(log.get());
// Turns the AST into LLVM IR //
LX::GenerateIR(AST, inpPath.filename().string());
LX::GenerateIR(AST, inpPath.filename().string(), outPath);
LX::SafeFlush(log.get());
// Returns success

View File

@@ -24,7 +24,7 @@
<ProjectGuid>{cc37e36f-b3b3-41b0-a887-01e8efe84994}</ProjectGuid>
<RootNamespace>LXLLVM</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<ProjectName>LX-Compiler</ProjectName>
<ProjectName>Compiler-Frontend</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
@@ -137,7 +137,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Main.cpp" />
<ClCompile Include="Frontend-Main.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="Main.cpp" />
<ClCompile Include="Frontend-Main.cpp" />
</ItemGroup>
</Project>

View File

@@ -3,6 +3,7 @@
#include <Util.h>
#include <AST.h>
#include <filesystem>
#include <iostream>
namespace LX
@@ -38,12 +39,16 @@ namespace LX
}
// Verifies the function works //
ThrowIf<int>(llvm::verifyFunction(*func), &llvm::errs()); // <- TODO: Make error type
ThrowIf<int>(llvm::verifyFunction(*func)); // <- TODO: Make error type
}
// Turns an abstract binary tree into LLVM intermediate representation //
void GenerateIR(FileAST& ast, const std::string& name)
void GenerateIR(FileAST& ast, const std::string& name, const std::filesystem::path& IRPath)
{
// Opens the file to output the IR //
std::error_code EC;
llvm::raw_fd_ostream file(IRPath.string(), EC);
// Creates the LLVM variables needed for generating IR that are shared between functions //
InfoLLVM LLVM(name);
@@ -53,7 +58,7 @@ namespace LX
GenerateFunctionIR(func, LLVM);
}
// Outputs the IR to the console //
LLVM.module.print(llvm::outs(), nullptr);
// Outputs the IR to the output file //
LLVM.module.print(file, nullptr);
}
}

View File

@@ -5,6 +5,9 @@
#include <memory>
// Foward declares STD stuff that is passed around //
namespace std::filesystem { class path; }
// Foward declares all items of the llvm lib that we need //
// Done to avoid including LLVM.h to shorten compile times //
namespace llvm { class Value; }
@@ -85,5 +88,5 @@ namespace LX
FileAST TurnTokensIntoAbstractSyntaxTree(std::vector<Token>& tokens, std::ofstream* log);
// Turns an abstract binary tree into LLVM intermediate representation //
void GenerateIR(FileAST& ast, const std::string& name);
void GenerateIR(FileAST& ast, const std::string& name, const std::filesystem::path& IRPath);
}