2020-07-25 15:49:19 +01:00
|
|
|
/**
|
|
|
|
* Serene programming language.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Sameer Rahmani <lxsameer@gnu.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef NAMESPACE_H
|
|
|
|
#define NAMESPACE_H
|
|
|
|
|
2021-03-28 10:53:32 +01:00
|
|
|
#include "mlir/IR/BuiltinOps.h"
|
|
|
|
#include "serene/expr.hpp"
|
2020-07-25 15:49:19 +01:00
|
|
|
#include "serene/llvm/IR/Value.h"
|
|
|
|
#include "serene/logger.hpp"
|
2021-03-28 10:53:32 +01:00
|
|
|
#include "llvm/ADT/ScopedHashTable.h"
|
2021-04-01 23:37:12 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2020-07-25 15:49:19 +01:00
|
|
|
#include <llvm/IR/Module.h>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#if defined(ENABLE_LOG) || defined(ENABLE_NAMESPACE_LOG)
|
|
|
|
#define NAMESPACE_LOG(...) __LOG("NAMESPACE", __VA_ARGS__);
|
|
|
|
#else
|
|
|
|
#define NAMESPACE_LOG(...) ;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
namespace serene {
|
2020-08-03 20:21:46 +01:00
|
|
|
class AExpr;
|
|
|
|
|
2020-07-25 15:49:19 +01:00
|
|
|
class Namespace {
|
2021-03-28 10:53:32 +01:00
|
|
|
private:
|
|
|
|
ast_tree tree{};
|
|
|
|
bool initialized = false;
|
|
|
|
llvm::ScopedHashTable<mlir::StringRef, mlir::Value> scope;
|
2020-07-25 15:49:19 +01:00
|
|
|
|
|
|
|
public:
|
2021-04-01 23:37:12 +01:00
|
|
|
llvm::Optional<llvm::StringRef> filename;
|
2021-03-28 10:53:32 +01:00
|
|
|
mlir::StringRef name;
|
2020-07-25 15:49:19 +01:00
|
|
|
|
2021-04-01 23:37:12 +01:00
|
|
|
Namespace(mlir::StringRef ns_name, llvm::Optional<llvm::StringRef> filename)
|
|
|
|
: filename(filename), name(ns_name){};
|
|
|
|
|
2021-03-28 10:53:32 +01:00
|
|
|
ast_tree &Tree();
|
|
|
|
mlir::LogicalResult setTree(ast_tree);
|
|
|
|
mlir::Value lookup(mlir::StringRef name);
|
|
|
|
mlir::LogicalResult insert_symbol(mlir::StringRef name, mlir::Value v);
|
2020-08-01 21:32:21 +01:00
|
|
|
|
|
|
|
void print_scope();
|
2020-07-25 15:49:19 +01:00
|
|
|
~Namespace();
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace serene
|
|
|
|
|
|
|
|
#endif
|