Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce semantizer module for an operation tree verification #124

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

#include "compiler/optree/operation.hpp"
#include "compiler/optree/program.hpp"

namespace optree {
namespace semantizer {

class Semantizer {
public:
Semantizer() = delete;
Semantizer(const Semantizer &) = delete;
Semantizer(Semantizer &&) = delete;
~Semantizer() = delete;

static void process(const Program &program);
static void process(const Operation::Ptr &op);
};

} // namespace semantizer
} // namespace optree
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <string>

#include "compiler/optree/operation.hpp"
#include "compiler/utils/error_buffer.hpp"

#include "compiler/backend/optree/semantizer/semantizer_error.hpp"

namespace optree {
namespace semantizer {

struct SemantizerContext {
ErrorBuffer errors;

void pushError(const Operation::Ptr &op, const std::string &message) {
errors.push<SemantizerError>(op, message);
}
};

} // namespace semantizer
} // namespace optree
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <string>

#include "compiler/optree/operation.hpp"
#include "compiler/utils/base_error.hpp"

namespace optree {
namespace semantizer {

class SemantizerError : public BaseError {
public:
SemantizerError(const Operation::Ptr &op, const std::string &message) : BaseError(op->ref, message){};
~SemantizerError() override = default;
};

} // namespace semantizer
} // namespace optree
20 changes: 20 additions & 0 deletions compiler/lib/backend/optree/semantizer/semantizer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "semantizer/semantizer.hpp"

#include "compiler/optree/operation.hpp"
#include "compiler/optree/program.hpp"

#include "semantizer/semantizer_context.hpp"

using namespace optree;
using namespace optree::semantizer;

void Semantizer::process(const Program &program) {
return process(program.root);
}

void Semantizer::process(const Operation::Ptr &op) {
Fixed Show fixed Hide fixed
SemantizerContext ctx;

if (!ctx.errors.empty())
throw ctx.errors;
}
Loading