mirror of
https://github.com/PashaBibko/LX.git
synced 2026-04-03 17:39:02 +00:00
Made the process actually output to the file
This commit is contained in:
@@ -46,6 +46,7 @@ int main(int argc, char** argv)
|
|||||||
// Opens / Creates the output file //
|
// Opens / Creates the output file //
|
||||||
std::ofstream outFile(outPath);
|
std::ofstream outFile(outPath);
|
||||||
LX::ThrowIf<LX::InvalidOutputFilePath>(outFile.is_open() == false);
|
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 //
|
// Opens the log file (if there is one specified //
|
||||||
if (argc == 4)
|
if (argc == 4)
|
||||||
@@ -67,7 +68,7 @@ int main(int argc, char** argv)
|
|||||||
LX::SafeFlush(log.get());
|
LX::SafeFlush(log.get());
|
||||||
|
|
||||||
// Turns the AST into LLVM IR //
|
// Turns the AST into LLVM IR //
|
||||||
LX::GenerateIR(AST, inpPath.filename().string());
|
LX::GenerateIR(AST, inpPath.filename().string(), outPath);
|
||||||
LX::SafeFlush(log.get());
|
LX::SafeFlush(log.get());
|
||||||
|
|
||||||
// Returns success
|
// Returns success
|
||||||
@@ -24,7 +24,7 @@
|
|||||||
<ProjectGuid>{cc37e36f-b3b3-41b0-a887-01e8efe84994}</ProjectGuid>
|
<ProjectGuid>{cc37e36f-b3b3-41b0-a887-01e8efe84994}</ProjectGuid>
|
||||||
<RootNamespace>LXLLVM</RootNamespace>
|
<RootNamespace>LXLLVM</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
<ProjectName>LX-Compiler</ProjectName>
|
<ProjectName>Compiler-Frontend</ProjectName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
@@ -137,7 +137,7 @@
|
|||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Main.cpp" />
|
<ClCompile Include="Frontend-Main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||||
<ImportGroup Label="ExtensionTargets">
|
<ImportGroup Label="ExtensionTargets">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Main.cpp" />
|
<ClCompile Include="Frontend-Main.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <Util.h>
|
#include <Util.h>
|
||||||
#include <AST.h>
|
#include <AST.h>
|
||||||
|
|
||||||
|
#include <filesystem>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
namespace LX
|
namespace LX
|
||||||
@@ -38,12 +39,16 @@ namespace LX
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Verifies the function works //
|
// 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 //
|
// 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 //
|
// Creates the LLVM variables needed for generating IR that are shared between functions //
|
||||||
InfoLLVM LLVM(name);
|
InfoLLVM LLVM(name);
|
||||||
|
|
||||||
@@ -53,7 +58,7 @@ namespace LX
|
|||||||
GenerateFunctionIR(func, LLVM);
|
GenerateFunctionIR(func, LLVM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Outputs the IR to the console //
|
// Outputs the IR to the output file //
|
||||||
LLVM.module.print(llvm::outs(), nullptr);
|
LLVM.module.print(file, nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,9 @@
|
|||||||
|
|
||||||
#include <memory>
|
#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 //
|
// Foward declares all items of the llvm lib that we need //
|
||||||
// Done to avoid including LLVM.h to shorten compile times //
|
// Done to avoid including LLVM.h to shorten compile times //
|
||||||
namespace llvm { class Value; }
|
namespace llvm { class Value; }
|
||||||
@@ -85,5 +88,5 @@ namespace LX
|
|||||||
FileAST TurnTokensIntoAbstractSyntaxTree(std::vector<Token>& tokens, std::ofstream* log);
|
FileAST TurnTokensIntoAbstractSyntaxTree(std::vector<Token>& tokens, std::ofstream* log);
|
||||||
|
|
||||||
// Turns an abstract binary tree into LLVM intermediate representation //
|
// 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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user