Skip to content

Commit b0f6226

Browse files
committed
parser works
1 parent 5bed072 commit b0f6226

File tree

13 files changed

+522
-108
lines changed

13 files changed

+522
-108
lines changed

include/sql/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
add_mlir_dialect(SQLOps sql)
22
# add_mlir_doc(SQLDialect -gen-dialect-doc SQLDialect SQL/)
33
# add_mlir_doc(SQLOps -gen-op-doc SQLOps SQL/)
4-
54
add_subdirectory(Passes)

include/sql/Parser.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//===- Parser.h - SQL dialect -----------------*- C++ -*-===//
2+
//
3+
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
9+
10+
11+
12+
#ifndef SQLPARSER_H
13+
#define SQLPARSER_H
14+
15+
#include "mlir/IR/Dialect.h"
16+
17+
#include "mlir/IR/Value.h"
18+
#include "mlir/IR/Builders.h"
19+
#include "mlir/IR/Location.h"
20+
#include "mlir/IR/Attributes.h"
21+
#include "llvm/ADT/SmallVector.h"
22+
#include "mlir/IR/BuiltinTypes.h"
23+
24+
#include "sql/SQLDialect.h"
25+
#include "sql/SQLOps.h"
26+
#include "sql/SQLTypes.h"
27+
28+
mlir::Value parseSQL(mlir::Location loc, mlir::OpBuilder& builder, std::string str);
29+
30+
#endif // SQLPARSER_H

include/sql/SQLDialect.td

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@
1010
#define SQL_DIALECT
1111

1212

13-
include "mlir/IR/OpBase.td"
13+
1414
include "mlir/IR/FunctionInterfaces.td"
1515
include "mlir/IR/SymbolInterfaces.td"
1616
include "mlir/Interfaces/SideEffectInterfaces.td"
17-
1817
include "mlir/Interfaces/CallInterfaces.td"
1918
include "mlir/Interfaces/CastInterfaces.td"
2019

@@ -26,15 +25,13 @@ def SQL_Dialect : Dialect {
2625
}];
2726
let name = "sql";
2827
let cppNamespace = "::mlir::sql";
29-
}
30-
3128

32-
//===----------------------------------------------------------------------===//
33-
// SQL Operations
34-
//===----------------------------------------------------------------------===//
29+
let useDefaultTypePrinterParser = 1;
30+
let extraClassDeclaration = [{
31+
void registerTypes();
32+
}];
33+
}
3534

36-
class SQL_Op<string mnemonic, list<Trait> traits = []>
37-
: Op<SQL_Dialect, mnemonic, traits>;
3835

3936
#endif // SQL_DIALECT
4037

include/sql/SQLOps.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include "mlir/Interfaces/SideEffectInterfaces.h"
1717
#include "mlir/Interfaces/ViewLikeInterface.h"
1818
#include "llvm/Support/CommandLine.h"
19-
19+
#include "sql/SQLTypes.h"
2020
#define GET_OP_CLASSES
2121
#include "sql/SQLOps.h.inc"
2222

include/sql/SQLOps.td

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,17 @@
99
#ifndef SQL_OPS
1010
#define SQL_OPS
1111

12-
include "mlir/IR/AttrTypeBase.td"
12+
include "mlir/IR/OpBase.td"
1313
include "SQLDialect.td"
14+
include "SQLTypes.td"
15+
16+
17+
class SQL_Op<string mnemonic, list<Trait> traits = []>
18+
: Op<SQL_Dialect, mnemonic, traits>;
19+
1420

1521
def IntOp : SQL_Op<"int", [Pure]> {
16-
let summary = "select";
22+
let summary = "int op";
1723

1824
let arguments = (ins StrAttr:$expr);
1925
let results = (outs SQLExprType:$result);
@@ -23,7 +29,7 @@ def IntOp : SQL_Op<"int", [Pure]> {
2329
}
2430

2531
def ColumnOp : SQL_Op<"column", [Pure]> {
26-
let summary = "select";
32+
let summary = "column op";
2733

2834
let arguments = (ins StrAttr:$expr);
2935
let results = (outs SQLExprType:$result);
@@ -33,7 +39,7 @@ def ColumnOp : SQL_Op<"column", [Pure]> {
3339
}
3440

3541
def TableOp : SQL_Op<"table", [Pure]> {
36-
let summary = "select";
42+
let summary = "table";
3743

3844
let arguments = (ins StrAttr:$expr);
3945
let results = (outs SQLExprType:$result);
@@ -42,10 +48,24 @@ def TableOp : SQL_Op<"table", [Pure]> {
4248
let hasCanonicalizer = 0;
4349
}
4450

51+
def EmptyTableOp : SQL_Op<"empty_table", [Pure]> {
52+
let summary = "empty_table";
53+
// i need to specify the size of a Variadic?
54+
let arguments = (ins StrAttr:$expr);
55+
let results = (outs SQLExprType:$result);
56+
57+
let hasFolder = 0;
58+
let hasCanonicalizer = 0;
59+
}
60+
61+
// def VectorNotEmpty : AttrConstraint<CPred<"$_self.size() > 0">,
62+
// "VectorNotEmpty">;
63+
64+
4565
def SelectOp : SQL_Op<"select", [Pure]> {
4666
let summary = "select";
47-
48-
let arguments = (ins Variadic<SQLExprType>:$columns, Optional<SQLExprType>:$table);
67+
// i need to specify the size of a Variadic?
68+
let arguments = (ins Variadic<SQLExprType>:$columns, SQLExprType:$table);
4969
let results = (outs SQLExprType:$result);
5070

5171
let hasFolder = 0;
@@ -69,7 +89,7 @@ def ExecuteOp : SQL_Op<"execute", []> {
6989
let results = (outs Index:$result);
7090

7191
let hasFolder = 0;
72-
let hasCanonicalizer = 1;
92+
let hasCanonicalizer = 0;
7393
}
7494

7595

include/sql/SQLTypes.h

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
//===- SQLOps.h - SQL dialect ops --------------------*- C++ -*-===//
1+
//===- SQLTypes.h - SQL dialect types --------------------*- C++ -*-===//
22
//
33
// This file is licensed under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef SQLTYPES_H
10-
#define SQLTYPES_H
9+
#ifndef SQL_SQLTYPES_H
10+
#define SQL_SQLTYPES_H
1111

1212
#include "mlir/IR/BuiltinTypes.h"
13-
#include "mlir/IR/Dialect.h"
14-
#include "mlir/IR/OpDefinition.h"
15-
#include "mlir/IR/PatternMatch.h"
16-
#include "mlir/Interfaces/SideEffectInterfaces.h"
17-
#include "mlir/Interfaces/ViewLikeInterface.h"
18-
#include "llvm/Support/CommandLine.h"
1913

20-
#define GET_TYPE_CLASSES
21-
#include "sql/SQLTypes.h.inc"
14+
#define GET_TYPEDEF_CLASSES
15+
#include "sql/SQLOpsTypes.h.inc"
2216

23-
#endif
17+
18+
#endif // SQL_SQLTYPES_H

include/sql/SQLTypes.td

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,20 @@
1212
include "mlir/IR/AttrTypeBase.td"
1313
include "SQLDialect.td"
1414

15+
class SQL_Type<string name, string typeMnemonic, list<Trait> traits = []>
16+
: TypeDef<SQL_Dialect, name, traits> {
17+
let mnemonic = typeMnemonic;
18+
}
19+
20+
21+
1522
def SQLExprType : SQL_Type<"Expr", "expr"> {
1623
let summary = "SQL expression type";
17-
}
24+
let description = "Custom attr or value type in sql dialect";
1825

26+
// placeholder params
27+
// let parameters = (ins StringRefParameter<"the custom value">:$value);
28+
// let assemblyFormat = "`<` $value `>`";
29+
}
1930

2031
#endif // SQL_TYPES

lib/sql/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
add_mlir_dialect_library(MLIRSQL
2+
Types.cpp
23
Dialect.cpp
34
Ops.cpp
5+
Parser.cpp
6+
47

58
ADDITIONAL_HEADER_DIRS
69
${PROJECT_SOURCE_DIR}/include/sql
710

811
DEPENDS
912
MLIRSQLOpsIncGen
13+
# MLIRSQLTypesIncGen
1014

1115
LINK_LIBS PUBLIC
1216
MLIRIR

lib/sql/Dialect.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "mlir/IR/DialectImplementation.h"
1010
#include "sql/SQLDialect.h"
1111
#include "sql/SQLOps.h"
12+
#include "sql/SQLTypes.h"
1213

1314
using namespace mlir;
1415
using namespace mlir::sql;
@@ -22,6 +23,8 @@ void SQLDialect::initialize() {
2223
#define GET_OP_LIST
2324
#include "sql/SQLOps.cpp.inc"
2425
>();
26+
registerTypes();
27+
2528
}
2629

2730
#include "sql/SQLOpsDialect.cpp.inc"

0 commit comments

Comments
 (0)