Fix the type names and add PtrType to type_converter
This commit is contained in:
parent
4015fd6b7e
commit
57f71ec4f2
|
@ -16,8 +16,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SERENE_DIALECT_OPS
|
||||
#define SERENE_DIALECT_OPS
|
||||
#ifndef SERENE_DIALECT_OPS_TD
|
||||
#define SERENE_DIALECT_OPS_TD
|
||||
|
||||
include "mlir/IR/OpBase.td"
|
||||
include "mlir/Interfaces/CallInterfaces.td"
|
||||
|
@ -82,7 +82,7 @@ def ValueOp : Serene_Op<"value", [
|
|||
|
||||
// serene.symbol
|
||||
def SymbolOp : Serene_Op<"symbol", [
|
||||
NoSideEffect, //ConstantLike,
|
||||
NoSideEffect, ConstantLike,
|
||||
]> {
|
||||
|
||||
let summary = "This operation is the compile time contructor for symbol type";
|
||||
|
@ -102,7 +102,7 @@ def SymbolOp : Serene_Op<"symbol", [
|
|||
}];
|
||||
|
||||
let arguments = (ins StrAttr:$ns, StrAttr:$name);
|
||||
let results = (outs SereneSymbol:$result);
|
||||
let results = (outs SymbolType:$result);
|
||||
|
||||
let assemblyFormat = "attr-dict $ns $name";
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ def ConvertOp : Serene_Op<"convert", [
|
|||
|
||||
let arguments = (ins AnyType:$value);
|
||||
|
||||
let results = (outs AnyType:$result);
|
||||
let results = (outs Ptr<SymbolType>:$result);
|
||||
|
||||
let assemblyFormat = [{
|
||||
$value attr-dict `:` functional-type($value, results)
|
||||
|
@ -217,7 +217,7 @@ def FnOp: Serene_Op<"fn", [
|
|||
OptionalAttr<StrAttr>:$sym_visibility);
|
||||
|
||||
let regions = (region VariadicRegion<AnyRegion>:$bodies);
|
||||
let results = (outs SereneFn);
|
||||
let results = (outs FnType);
|
||||
}
|
||||
|
||||
|
||||
|
@ -267,7 +267,7 @@ def CallOp : Serene_Op<"call",
|
|||
```
|
||||
}];
|
||||
|
||||
let arguments = (ins SereneFn:$fn,
|
||||
let arguments = (ins FnType:$fn,
|
||||
Variadic<AnyType>:$args);
|
||||
let results = (outs Variadic<AnyType>);
|
||||
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#include "serene/context.h"
|
||||
#include "serene/export.h"
|
||||
#include "serene/slir/dialect.h"
|
||||
#include "serene/slir/ops.h"
|
||||
#include "serene/slir/types.h"
|
||||
#include "serene/utils.h"
|
||||
|
||||
#include <mlir/Dialect/LLVMIR/LLVMTypes.h>
|
||||
|
@ -31,6 +33,19 @@
|
|||
|
||||
namespace serene::slir {
|
||||
class SymbolType;
|
||||
class PtrType;
|
||||
|
||||
/// Returns the LLVM pointer type to the type `T` that is Serene pointer
|
||||
/// `p` is pointing to.
|
||||
mlir::Type getPtrTypeinLLVM(mlir::MLIRContext &ctx, PtrType p);
|
||||
|
||||
/// Returns the conversion result of converting Serene String type
|
||||
/// to LLVM dialect
|
||||
mlir::Type getStringTypeinLLVM(mlir::MLIRContext &ctx);
|
||||
|
||||
/// Returns the conversoin result of converting Serene Symbol type
|
||||
/// to LLVM dialect
|
||||
mlir::Type getSymbolTypeinLLVM(mlir::MLIRContext &ctx);
|
||||
|
||||
class TypeConverter : public mlir::TypeConverter {
|
||||
mlir::MLIRContext &ctx;
|
||||
|
@ -66,14 +81,6 @@ public:
|
|||
addTargetMaterialization(materializeSymbolFn());
|
||||
}
|
||||
};
|
||||
|
||||
/// Returns the conversion result of converting Serene String type
|
||||
/// to LLVM dialect
|
||||
mlir::Type getStringTypeinLLVM(mlir::MLIRContext &ctx);
|
||||
|
||||
/// Returns the conversoin result of converting Serene Symbol type
|
||||
/// to LLVM dialect
|
||||
mlir::Type getSymbolTypeinLLVM(mlir::MLIRContext &ctx);
|
||||
} // namespace serene::slir
|
||||
|
||||
#endif
|
||||
|
|
|
@ -56,13 +56,14 @@ add_library(serene
|
|||
reader/reader.cpp
|
||||
|
||||
# IR
|
||||
slir/types.cpp
|
||||
slir/slir.cpp
|
||||
slir/dialect.cpp
|
||||
slir/value_op.cpp
|
||||
slir/generatable.cpp
|
||||
slir/utils.cpp
|
||||
slir/ops.cpp
|
||||
slir/type_converter.cpp
|
||||
slir/dialect.cpp
|
||||
passes/slir_lowering.cpp
|
||||
passes/to_llvm_dialect.cpp
|
||||
)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "serene/exprs/list.h"
|
||||
#include "serene/exprs/symbol.h"
|
||||
#include "serene/slir/dialect.h"
|
||||
#include "serene/slir/ops.h"
|
||||
#include "serene/slir/utils.h"
|
||||
|
||||
#include <llvm/Support/Casting.h>
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "serene/exprs/expression.h"
|
||||
#include "serene/slir/dialect.h"
|
||||
#include "serene/slir/ops.h"
|
||||
#include "serene/slir/utils.h"
|
||||
|
||||
namespace serene {
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
#include "serene/slir/type_converter.h"
|
||||
|
||||
#include "serene/slir/dialect.h"
|
||||
|
||||
#include <llvm/Support/Casting.h>
|
||||
#include <mlir/Dialect/LLVMIR/LLVMTypes.h>
|
||||
|
||||
namespace ll = mlir::LLVM;
|
||||
|
@ -55,6 +58,13 @@ mlir::Type getSymbolTypeinLLVM(mlir::MLIRContext &ctx) {
|
|||
return symbolStruct;
|
||||
};
|
||||
|
||||
mlir::Type getPtrTypeinLLVM(mlir::MLIRContext &ctx, PtrType p) {
|
||||
UNUSED(ctx);
|
||||
auto T = p.getPointeeType();
|
||||
auto llvmPtr = ll::LLVMPointerType::get(T);
|
||||
return llvmPtr;
|
||||
}
|
||||
|
||||
TypeConverter::ConverterFn TypeConverter::convertSereneTypes() {
|
||||
return [&](mlir::Type type) -> MaybeType {
|
||||
if (type.isa<StringType>()) {
|
||||
|
@ -65,6 +75,10 @@ TypeConverter::ConverterFn TypeConverter::convertSereneTypes() {
|
|||
return getSymbolTypeinLLVM(ctx);
|
||||
}
|
||||
|
||||
if (type.isa<PtrType>()) {
|
||||
return getPtrTypeinLLVM(ctx, type.cast<PtrType>());
|
||||
}
|
||||
|
||||
return llvm::None;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue