Fix the readNamespace in the serenec
This commit is contained in:
parent
a00ba492e6
commit
ba77f9bc99
|
@ -240,7 +240,7 @@ int main(int argc, char *argv[]) {
|
|||
ctx->sourceManager.setLoadPaths(loadPaths);
|
||||
|
||||
auto runLoc = reader::LocationRange::UnknownLocation(inputNS);
|
||||
auto ns = ctx->sourceManager.readNamespace(*ctx, inputNS, runLoc, true);
|
||||
auto ns = ctx->sourceManager.readNamespace(*ctx, inputNS, runLoc);
|
||||
|
||||
if (!ns) {
|
||||
return (int)std::errc::no_such_file_or_directory;
|
||||
|
@ -328,6 +328,7 @@ int main(int argc, char *argv[]) {
|
|||
auto isSet = ns->setTree(afterAst.getValue());
|
||||
if (isSet.succeeded()) {
|
||||
ctx->insertNS(ns);
|
||||
|
||||
switch (emitAction) {
|
||||
case Action::DumpSLIR:
|
||||
case Action::DumpMLIR:
|
||||
|
|
|
@ -170,7 +170,8 @@ CLOSED: [2021-09-04 Sat 10:53]
|
|||
*** The owner of LLVM/MLIR contexts
|
||||
*** Holds the namespace table
|
||||
*** Probably will contain the primitive types as well
|
||||
* Episode 8 - MLIR Basics
|
||||
* DONE Episode 8 - MLIR Basics
|
||||
CLOSED: [2021-09-17 Fri 10:18]
|
||||
** Serene Changes
|
||||
- Introducing a SourceManager
|
||||
- Reader changes
|
||||
|
@ -376,3 +377,4 @@ define i64 @main1(i64 %0, i64 %1, i64 %2) !dbg !9 {
|
|||
- https://mlir.llvm.org/docs/LangRef
|
||||
- https://en.wikipedia.org/wiki/Basic_block
|
||||
|
||||
* Episode 9 - Code Generation
|
||||
|
|
|
@ -30,7 +30,6 @@
|
|||
#include "serene/traits.h"
|
||||
#include "serene/utils.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <llvm/ADT/SmallString.h>
|
||||
#include <llvm/ADT/StringRef.h>
|
||||
|
@ -98,6 +97,7 @@ public:
|
|||
|
||||
SereneContext &getContext();
|
||||
|
||||
// TODO: Fix the return type and use a `llvm::Optional` instead
|
||||
/// Generate and return a MLIR ModuleOp tha contains the IR of the namespace
|
||||
/// with respect to the compilation phase
|
||||
MaybeModuleOp generate();
|
||||
|
|
|
@ -10,7 +10,7 @@ function fix_includes(){
|
|||
|
||||
if [[ "$files" ]];
|
||||
then
|
||||
sed - i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $(files)
|
||||
sed -i -E '/^#include "(serene|\.)/!s/^.include \"(.*)\"/#include <\1>/g' $files
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ function git_add_changes() {
|
|||
|
||||
if [[ "$files" ]];
|
||||
then
|
||||
git add $(get_changed_files)
|
||||
git add $files
|
||||
fi
|
||||
|
||||
}
|
||||
|
|
|
@ -65,7 +65,6 @@ mlir::LogicalResult Namespace::setTree(exprs::Ast &t) {
|
|||
return mlir::success();
|
||||
}
|
||||
|
||||
|
||||
uint Namespace::nextFnCounter() { return fn_counter++; };
|
||||
|
||||
SereneContext &Namespace::getContext() { return this->ctx; };
|
||||
|
@ -73,16 +72,18 @@ SereneContext &Namespace::getContext() { return this->ctx; };
|
|||
MaybeModuleOp Namespace::generate() {
|
||||
mlir::OpBuilder builder(&ctx.mlirContext);
|
||||
// TODO: Fix the unknown location by pointing to the `ns` form
|
||||
// TODO: We need to call `erase` method of module somewhere to clean it up
|
||||
// maybe use a unique ptr?
|
||||
auto module = mlir::ModuleOp::create(builder.getUnknownLoc(), name);
|
||||
|
||||
// Walk the AST and call the `generateIR` function of each node.
|
||||
// Since nodes will have access to the a reference of the
|
||||
// namespace they can use the builder and keep adding more
|
||||
// operations to the module via the builder
|
||||
for (auto &x : getTree()) {
|
||||
x->generateIR(*this, module);
|
||||
}
|
||||
|
||||
if (mlir::failed(runPasses(module))) {
|
||||
// TODO: throw a proper errer
|
||||
// TODO: Report a proper error
|
||||
module.emitError("Failure in passes!");
|
||||
return MaybeModuleOp::error(true);
|
||||
}
|
||||
|
@ -99,7 +100,7 @@ void Namespace::dump() {
|
|||
auto maybeModuleOp = generate();
|
||||
|
||||
if (!maybeModuleOp) {
|
||||
llvm::outs() << "Failed to generate the IR.\n";
|
||||
llvm::errs() << "Failed to generate the IR.\n";
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue