Mentions légales du service

Skip to content
Snippets Groups Projects
Commit fb6af307 authored by aymaen's avatar aymaen
Browse files

Start doing the parse of int, Problem with adt-exec in loading the dialect

parent 13f3901a
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ To build the project, follow the next commands:
```sh
mkdir build && cd build
cmake -G Ninja .. -DLLVM_DIR=/path/to/llvm-project/build/lib/cmake/llvm \
-DMLIR_DIR=/path/to/llvm-project/build/lib/cmake/mlir
-DMLIR_DIR=/path/to/llvm-project/build/lib/cmake/mlir
cmake --build . --target MLIRAdt
```
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
set(LIBS
${dialect_libs}
${conversion_libs}
MLIRAdt
MLIRAnalysis
MLIRCallInterfaces
MLIRCastInterfaces
MLIRExecutionEngine
MLIRIR
MLIRLLVMCommonConversion
MLIRLLVMToLLVMIRTranslation
MLIRMemRefDialect
MLIRLLVMDialect
MLIRParser
MLIRPass
MLIRSideEffectInterfaces
MLIRSupport
MLIRTargetLLVMIRExport
MLIRTransforms
MLIROptLib)
add_llvm_executable(adt-exec adt-exec.cpp)
llvm_update_compile_flags(adt-exec)
......
......@@ -13,6 +13,7 @@
#include "llvm/Support/SourceMgr.h"
#include "llvm/Support/ToolOutputFile.h"
namespace cl = llvm::cl;
// Variable globale qui est notre inputFilename
static cl::opt<std::string> inputFilename(cl::Positional,
......
......@@ -4,23 +4,26 @@
#include <mlir/IR/Types.h>
#include <mlir/IR/DialectImplementation.h>
namespace mlir{
namespace adt{
namespace mlir::adt{
struct TypeSourceStorage;
}
}
#define GET_OP_CLASSES
#include "../../build/include/Adt/AdtOpsDialect.h.inc"
/// This class defines the adt source types.
namespace mlir{
namespace adt{
namespace mlir::adt{
class TypeSource: public mlir::Type::TypeBase<TypeSource, mlir::Type,mlir::adt::TypeSourceStorage>{
public:
// Inherit some necessary constructors from 'TypeBase'.
using Base::Base;
// Creating an instance of a 'TypeSource' with the geven element types.
static TypeSource get(llvm::ArrayRef<mlir::Type> elementTypes);
};
}
}
#endif // ADT_DIALECT_H
\ No newline at end of file
#endif // ADT_DIALECT_H_
\ No newline at end of file
......@@ -8,7 +8,7 @@ include "mlir/IR/OpBase.td"
//==-----------------------------------------------------------------------------------------===//
def Adt_Dialect : Dialect{
let name = "adt";
let cppNamespace = "::mlir::adt";
let cppNamespace = "mlir::adt";
let summary = "A adt out-of-tree MLIR dialect";
let description = [{This dialect has a purpose to impement all what is relative
to algebric data types}];
......@@ -23,13 +23,5 @@ class Adt_Op<string mnemonic, list<Trait> traits = [] >:
//===----------------------------------------------------------------------------------------===//
// Adt operation definition.
//==-----------------------------------------------------------------------------------------===//
def SrcTypeDeclOp: Adt_Op<"srctypedecl">{
let summary = "srctypedecl";
let description = [{
The "adt.srctypedecl" operation handle declaration of a source type, and register it into a specific
environnement.
```mlir example:
```
}];
}
#endif // ADT_OPS
\ No newline at end of file
......@@ -6,16 +6,51 @@ using namespace mlir::adt;
namespace mlir::adt {
/// Cette classe represente le stockage interne des types sources
struct TypeSourceStorage : public mlir::TypeStorage {
using KeyTy = llvm::ArrayRef<mlir::Type>;
explicit TypeSourceStorage(llvm::ArrayRef<mlir::Type> elementTypes) : elementTypes(elementTypes) {}
llvm::ArrayRef<mlir::Type> elementTypes;
static llvm::hash_code hashKey(const KeyTy &key) {
return llvm::hash_value(key);
}
bool operator==(const KeyTy &key) const { return key == elementTypes; }
static KeyTy getKey(llvm::ArrayRef<mlir::Type> elementTypes) {
return KeyTy(elementTypes);
}
static TypeSourceStorage *construct(mlir::TypeStorageAllocator &allocator,
const KeyTy &key) {
llvm::ArrayRef<mlir::Type> elementTypes = allocator.copyInto(key);
return new (allocator.allocate<TypeSourceStorage>())
TypeSourceStorage(elementTypes);
}
};
/// On doit implémenter ici une instance du type type source (donc cette instance est un type aussi)
}
///
TypeSource TypeSource::get(llvm::ArrayRef<mlir::Type> elementTypes) {
assert(!elementTypes.empty() && "expected at least 1 element type");
mlir::MLIRContext *ctx = elementTypes.front().getContext();
return Base::get(ctx,elementTypes);
}
/// On parse ici une instance du type type source (donc cette instance est un type aussi)
mlir::Type AdtDialect::parseType(::mlir::DialectAsmParser &parser) const{
if (parser.parseKeyword("type") || parser.parseLess())
return Type();
SmallVector<mlir::Type, 1> elementTypes;
SMLoc typeLoc = parser.getCurrentLocation();
mlir::Type elementType;
if (parser.parseType(elementType))
return nullptr;
if (!elementType.isa<mlir::IntegerType>()){
parser.emitError(typeLoc, "element type must be an integer")
<< elementType;
return Type();
}
elementTypes.push_back(elementType);
if (parser.parseGreater())
return Type();
return TypeSource::get(elementTypes);
}
/// Cette fonction nous permet de print en format mlir une instance des types sources
......@@ -26,7 +61,7 @@ void AdtDialect::printType(::mlir::Type type, ::mlir::DialectAsmPrinter &os) con
class VarType : public TypeSource{
};
// type intlgt = bits<lgt> represented as ilgt
class IntType : public TypeSource{
};
......@@ -42,3 +77,12 @@ class ProType : public TypeSource{
class SumType : public TypeSource{
};
#define GET_OP_CLASSES
#include "../build/include/Adt/AdtOps.cpp.inc"
void AdtDialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "../build/include/Adt/AdtOps.cpp.inc"
>();
}
!adt.type<i63>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment