-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "codegen.hpp" | ||
#include "diag.hpp" | ||
#include "llvm/IR/Intrinsics.h" | ||
#include "llvm/IR/LLVMContext.h" | ||
|
||
#include "llvm/ADT/APInt.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/IR/IRBuilder.h" | ||
#include "llvm/IR/Instructions.h" | ||
#include "llvm/IR/LegacyPassManager.h" | ||
#include "llvm/IR/Value.h" | ||
#include "llvm/IR/Verifier.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/Target/TargetMachine.h" | ||
#include "llvm/Target/TargetOptions.h" | ||
#include "llvm/TargetParser/Host.h" | ||
#include "llvm/MC/TargetRegistry.h" | ||
|
||
namespace code | ||
{ | ||
std::string output::dump_ir() const | ||
{ | ||
if(this->codegen_handle == nullptr) | ||
{ | ||
return "<no output>"; | ||
} | ||
std::string ir_string; | ||
llvm::raw_string_ostream os{ir_string}; | ||
reinterpret_cast<llvm::Module*>(this->codegen_handle)->print(os, nullptr); | ||
return ir_string; | ||
} | ||
|
||
std::string output::get_output_filename() const | ||
{ | ||
return this->module_name + ".o"; | ||
} | ||
|
||
void output::write_to_object_file(std::filesystem::path output_dir) | ||
{ | ||
std::string object_filename = (output_dir / this->get_output_filename()).string(); | ||
|
||
diag::error(error_code::nyi, "writing to object file is not yet implemented. i was told to write to \"{}\"", object_filename); | ||
} | ||
|
||
output generate(const semal::output& input, std::string module_name) | ||
{ | ||
return | ||
{ | ||
.codegen_handle = nullptr, | ||
.module_name = module_name | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef PSYC_CODEGEN_HPP | ||
#define PSYC_CODEGEN_HPP | ||
#include "semal.hpp" | ||
|
||
namespace code | ||
{ | ||
struct output | ||
{ | ||
void* codegen_handle = nullptr; | ||
std::string module_name; | ||
std::string dump_ir() const; | ||
std::string get_output_filename() const; | ||
void write_to_object_file(std::filesystem::path output_dir); | ||
}; | ||
|
||
output generate(const semal::output& input, std::string module_name = "<unnamed_module>"); | ||
|
||
struct state | ||
{ | ||
std::unordered_map<std::filesystem::path, output> codegend_input_files = {}; | ||
}; | ||
} | ||
|
||
#endif // PSYC_CODEGEN_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters