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 parser dialect #739

Merged
merged 4 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions include/vast/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_subdirectory(Core)
add_subdirectory(HighLevel)
add_subdirectory(LowLevel)
add_subdirectory(Meta)
add_subdirectory(Parser)
add_subdirectory(Unsupported)
3 changes: 3 additions & 0 deletions include/vast/Dialect/Parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright (c) 2024, Trail of Bits, Inc.

add_vast_dialect_with_doc(Parser pr)
15 changes: 15 additions & 0 deletions include/vast/Dialect/Parser/Dialect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#pragma once

#include "vast/Util/Warnings.hpp"

VAST_RELAX_WARNINGS
#include <mlir/IR/Dialect.h>
#include <mlir/IR/OperationSupport.h>
VAST_RELAX_WARNINGS

#include "vast/Dialect/Core/TypeTraits.hpp"

// Pull in the dialect definition.
#include "vast/Dialect/Parser/ParserDialect.h.inc"

Check failure on line 15 in include/vast/Dialect/Parser/Dialect.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

include/vast/Dialect/Parser/Dialect.hpp:15:10 [clang-diagnostic-error]

'vast/Dialect/Parser/ParserDialect.h.inc' file not found
16 changes: 16 additions & 0 deletions include/vast/Dialect/Parser/Ops.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#pragma once

#include "vast/Util/Warnings.hpp"

VAST_RELAX_WARNINGS
#include <mlir/Interfaces/CallInterfaces.h>
#include <mlir/Interfaces/InferTypeOpInterface.h>
VAST_UNRELAX_WARNINGS

#include "vast/Dialect/Parser/Dialect.hpp"
#include "vast/Util/Common.hpp"

#define GET_OP_CLASSES
#include "vast/Dialect/Parser/Parser.h.inc"
46 changes: 46 additions & 0 deletions include/vast/Dialect/Parser/Ops.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#ifndef VAST_DIALECT_PARSER_OPS
#define VAST_DIALECT_PARSER_OPS

include "mlir/IR/OpBase.td"

include "vast/Dialect/Core/Utils.td"
include "vast/Dialect/Parser/Types.td"

class Parser_Op< string mnemonic, list< Trait > traits = [] >
: Op< Parser_Dialect, mnemonic, traits >;

def Parser_Source
: Parser_Op< "source" >
, Arguments< (ins Variadic<AnyType>:$arguments) >
, Results< (outs Variadic<Parser_DataType>:$result) >
{
let summary = "Source of parsed data.";
}

def Paser_Sink
: Parser_Op< "sink" >
, Arguments< (ins Variadic<Parser_MaybeDataType>:$arguments) >
, Results< (outs Variadic<Parser_NoDataType>:$result) >
{
let summary = "Sink of parsed data.";
}

def Parser_Parse
: Parser_Op< "parse" >
, Arguments< (ins Variadic<Parser_MaybeDataType>:$arguments) >
, Results< (outs Variadic<AnyType>:$result) >
{
let summary = "Parsing operation data.";
}

def Parse_NoParse
: Parser_Op< "noparse" >
, Arguments< (ins Variadic<Parser_NoDataType>:$arguments) >
, Results< (outs Variadic<Parser_NoDataType>:$result) >
{
let summary = "Non-parsing operation data.";
}

#endif // VAST_DIALECT_PARSER_OPS
38 changes: 38 additions & 0 deletions include/vast/Dialect/Parser/Parser.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#ifndef VAST_DIALECT_PARSER
#define VAST_DIALECT_PARSER

include "mlir/IR/OpBase.td"
include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"

def Parser_Dialect : Dialect {
let name = "pr";
let cppNamespace = "::vast::pr";

let summary = "Dialect for abstracting parsering logic.";

let description = [{
Dialect for abstracting parsering logic.

The goal of the dialect is to abstract the parsering logic
for easier uniform parser recognition.
}];

let extraClassDeclaration = [{
void registerTypes();
}];

let useDefaultTypePrinterParser = 1;

let hasConstantMaterializer = 1;
}

include "vast/Dialect/Parser/Ops.td"
include "vast/Dialect/Parser/Types.td"

#endif // VAST_DIALECT_PARSER
8 changes: 8 additions & 0 deletions include/vast/Dialect/Parser/Types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#pragma once

#include "vast/Dialect/Parser/Dialect.hpp"

#define GET_TYPEDEF_CLASSES
#include "vast/Dialect/Parser/ParserTypes.h.inc"
31 changes: 31 additions & 0 deletions include/vast/Dialect/Parser/Types.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#ifndef VAST_DIALECT_PARSER_TYPES
#define VAST_DIALECT_PARSER_TYPES

class Parser_Type< string name, string _mnemonic, list<Trait> traits = [] >
: TypeDef< Parser_Dialect, name, traits >
{
let mnemonic = _mnemonic;
}

def Parser_DataType : Parser_Type< "Data", "data" > {
let summary = "Data type.";
}

def Parser_NoDataType : Parser_Type< "NoData", "nodata" > {
let summary = "No data type.";
}

def Parser_AnyDataType : Parser_Type< "AnyData", "anydata" > {
let summary = "Any data type.";
}

def Parser_MaybeDataType : Type<
Or< [
Parser_DataType.predicate,
Parser_AnyDataType.predicate
]>
>;

#endif // VAST_DIALECT_PARSER_TYPES
1 change: 1 addition & 0 deletions lib/vast/Dialect/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_subdirectory(Core)
add_subdirectory(HighLevel)
add_subdirectory(LowLevel)
add_subdirectory(Meta)
add_subdirectory(Parser)
add_subdirectory(Unsupported)
7 changes: 7 additions & 0 deletions lib/vast/Dialect/Parser/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2024, Trail of Bits, Inc.

add_vast_dialect_library(Parser
Dialect.cpp
Ops.cpp
Types.cpp
)
30 changes: 30 additions & 0 deletions lib/vast/Dialect/Parser/Dialect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) 2024-present, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Dialect/Parser/Dialect.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on lib/vast/Dialect/Parser/Dialect.cpp

File lib/vast/Dialect/Parser/Dialect.cpp does not conform to Custom style guidelines. (lines 16, 17, 18)
//
#include "vast/Dialect/Parser/Dialect.hpp"
#include "vast/Dialect/Parser/Ops.hpp"

#include <mlir/IR/Builders.h>
#include <mlir/IR/DialectImplementation.h>
#include <mlir/IR/DialectInterface.h>
#include <mlir/IR/OpImplementation.h>
#include <mlir/IR/TypeSupport.h>

namespace vast::pr {
using OpBuilder = mlir::OpBuilder;

void ParserDialect::initialize() {
addOperations<
#define GET_OP_LIST
#include "vast/Dialect/Parser/Parser.cpp.inc"
>();
}

Operation *ParserDialect::materializeConstant(
OpBuilder &builder, Attribute value, Type type, Location loc
) {
VAST_UNIMPLEMENTED;
}

} // namespace vast::pr

#include "vast/Dialect/Parser/ParserDialect.cpp.inc"
27 changes: 27 additions & 0 deletions lib/vast/Dialect/Parser/Ops.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) 2024, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Dialect/Parser/Ops.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on lib/vast/Dialect/Parser/Ops.cpp

File lib/vast/Dialect/Parser/Ops.cpp does not conform to Custom style guidelines. (lines 11)

#include "vast/Util/Warnings.hpp"

VAST_RELAX_WARNINGS
#include <mlir/IR/Builders.h>
#include <mlir/IR/OpImplementation.h>
#include <mlir/IR/OperationSupport.h>
#include <mlir/IR/SymbolTable.h>

#include <mlir/Interfaces/FunctionImplementation.h>
#include <mlir/Interfaces/CallInterfaces.h>

#include <mlir/Support/LLVM.h>
#include <mlir/Support/LogicalResult.h>

#include <llvm/Support/ErrorHandling.h>
VAST_UNRELAX_WARNINGS

#include "vast/Dialect/Parser/Dialect.hpp"
#include "vast/Dialect/Parser/Ops.hpp"
#include "vast/Dialect/Parser/Types.hpp"

using namespace vast::pr;

#define GET_OP_CLASSES
#include "vast/Dialect/Parser/Parser.cpp.inc"
28 changes: 28 additions & 0 deletions lib/vast/Dialect/Parser/Types.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2024, Trail of Bits, Inc.

Check notice on line 1 in lib/vast/Dialect/Parser/Types.cpp

View workflow job for this annotation

GitHub Actions / cpp-linter (19, 22.04)

Run clang-format on lib/vast/Dialect/Parser/Types.cpp

File lib/vast/Dialect/Parser/Types.cpp does not conform to Custom style guidelines. (lines 6, 19, 20, 21, 27)

#include "vast/Util/Warnings.hpp"

VAST_RELAX_WARNINGS
#include <llvm/ADT/TypeSwitch.h>
#include <mlir/IR/OpImplementation.h>
#include <mlir/IR/DialectImplementation.h>
VAST_RELAX_WARNINGS

#include "vast/Dialect/Parser/Dialect.hpp"
#include "vast/Dialect/Parser/Types.hpp"

#include "vast/Util/Common.hpp"

namespace vast::pr {

void ParserDialect::registerTypes() {
addTypes<
#define GET_TYPEDEF_LIST
#include "vast/Dialect/Parser/ParserTypes.cpp.inc"
>();
}

} // namespace vast::pr

#define GET_TYPEDEF_CLASSES
#include "vast/Dialect/Parser/ParserTypes.cpp.inc"