Skip to content

Commit

Permalink
treewide: Move symbol interfaces to core dialect.
Browse files Browse the repository at this point in the history
  • Loading branch information
xlauko committed Aug 30, 2024
1 parent 7996f60 commit 1c234f8
Show file tree
Hide file tree
Showing 39 changed files with 115 additions and 80 deletions.
14 changes: 7 additions & 7 deletions include/vast/CodeGen/ScopeContext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ VAST_UNRELAX_WARNINGS
#include "vast/Util/TypeList.hpp"
#include "vast/Util/Symbols.hpp"

#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"

#include <functional>
#include <queue>
Expand Down Expand Up @@ -56,22 +56,22 @@ namespace vast::cg

operation declare(operation op) {
llvm::TypeSwitch< operation >(op)
.Case< VarSymbolOpInterface >([&] (auto &op) {
.Case< core::VarSymbolOpInterface >([&] (auto &op) {
symbols.vars.insert(op.getSymbolName(), op->getResult(0));
})
.Case< TypeSymbolOpInterface >([&] (auto &op) {
.Case< core::TypeSymbolOpInterface >([&] (auto &op) {
symbols.types.insert(op.getSymbolName(), op);
})
.Case< FuncSymbolOpInterface >([&] (auto &op) {
.Case< core::FuncSymbolOpInterface >([&] (auto &op) {
symbols.funs.insert(op.getSymbolName(), op);
})
.Case< MemberVarSymbolOpInterface >([&] (auto &op) {
.Case< core::MemberVarSymbolOpInterface >([&] (auto &op) {
symbols.members.insert(op.getSymbolName(), op);
})
.Case< LabelSymbolOpInterface >([&] (auto &op) {
.Case< core::LabelSymbolOpInterface >([&] (auto &op) {
symbols.labels.insert(op.getSymbolName(), op);
})
.Case< EnumConstantSymbolOpInterface >([&] (auto &op) {
.Case< core::EnumConstantSymbolOpInterface >([&] (auto &op) {
symbols.enum_constants.insert(op.getSymbolName(), op);
})
.Default([] (auto &op){
Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/ABI/ABI.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"

include "vast/Interfaces/SymbolInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

def ABI_Dialect : Dialect {
let name = "abi";
Expand Down
3 changes: 1 addition & 2 deletions include/vast/Dialect/ABI/ABIOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ VAST_RELAX_WARNINGS
#include <mlir/Interfaces/SideEffectInterfaces.h>
VAST_RELAX_WARNINGS

#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Util/Common.hpp"

#include "vast/Dialect/Core/CoreDialect.hpp"
#include "vast/Dialect/Core/CoreTypes.hpp"
#include "vast/Dialect/Core/CoreAttributes.hpp"
#include "vast/Dialect/Core/Func.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"

#define GET_OP_CLASSES
#include "vast/Dialect/ABI/ABI.h.inc"

2 changes: 2 additions & 0 deletions include/vast/Dialect/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) 2022-present, Trail of Bits, Inc.

add_vast_dialect_with_doc(Core core)

add_subdirectory(Interfaces)
2 changes: 1 addition & 1 deletion include/vast/Dialect/Core/Core.td
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#ifndef VAST_DIALECT_CORE
#define VAST_DIALECT_CORE

include "vast/Interfaces/SymbolInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

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

Expand Down
4 changes: 2 additions & 2 deletions include/vast/Dialect/Core/CoreAttributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ VAST_UNRELAX_WARNINGS
#include "vast/Dialect/Core/CoreDialect.hpp"
#include "vast/Dialect/Core/CoreTraits.hpp"

#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Interfaces/SymbolRefInterface.hpp"
#include "vast/Interfaces/TypeQualifiersInterfaces.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolRefInterface.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/TypeList.hpp"
Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/Core/CoreAttributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

include "mlir/IR/AttrTypeBase.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"
include "vast/Interfaces/SymbolRefInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolRefInterface.td"

include "mlir/IR/EnumAttr.td"

Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/Core/CoreLazy.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include "mlir/IR/OpBase.td"
include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/CastInterfaces.td"
include "mlir/Interfaces/FunctionInterfaces.td"
include "vast/Interfaces/SymbolInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

class Core_LazyEval< string mnemonic, list < Trait > traits = [] >
: Core_Op< mnemonic, !listconcat(traits, []) >, Results<(outs AnyType:$result)>
Expand Down
4 changes: 2 additions & 2 deletions include/vast/Dialect/Core/CoreOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "vast/Dialect/Core/CoreDialect.hpp"
#include "vast/Dialect/Core/CoreTraits.hpp"
#include "vast/Dialect/Core/SymbolTable.hpp"
#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Interfaces/SymbolTableInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolTableInterface.hpp"

#include "vast/Util/Common.hpp"
#include "vast/Util/TypeList.hpp"
Expand Down
12 changes: 8 additions & 4 deletions include/vast/Dialect/Core/CoreOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ include "mlir/Interfaces/DataLayoutInterfaces.td"
include "mlir/IR/RegionKindInterface.td"

include "vast/Dialect/Core/CoreTraits.td"
include "vast/Interfaces/SymbolTableInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolTableInterface.td"

def Core_ModuleOp : Core_Op< "module", [
IsolatedFromAbove,
DataLayoutOpInterface,
HasDefaultDLTIDataLayout,
NoTerminator, NoRegionArguments, SingleBlock, VastSymbol,
ShadowingSymbolTable< [[FuncSymbol, VarSymbol, TypeSymbol], [ElaboratedTypeSymbol]] >,
NoTerminator, NoRegionArguments, SingleBlock, Core_Symbol,
ShadowingSymbolTable< [
[Core_FuncSymbol, Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol]
] >,
] > {
let summary = "VAST top level container operation";
let description = [{
Expand Down Expand Up @@ -73,7 +75,9 @@ def Core_ModuleOp : Core_Op< "module", [

def Core_ScopeOp : Core_Op< "scope", [
NoTerminator,
ShadowingSymbolTable< [[VarSymbol, TypeSymbol], [ElaboratedTypeSymbol]] >,
ShadowingSymbolTable< [
[Core_VarSymbol, Core_TypeSymbol], [Core_ElaboratedTypeSymbol]
] >,
DeclareOpInterfaceMethods<RegionKindInterface>
] > {
let summary = "VAST scope declaration";
Expand Down
4 changes: 2 additions & 2 deletions include/vast/Dialect/Core/Func.td
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ include "mlir/IR/RegionKindInterface.td"

include "mlir/Interfaces/CallInterfaces.td"
include "mlir/Interfaces/FunctionInterfaces.td"
include "vast/Interfaces/SymbolInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

include "vast/Dialect/Core/CoreTraits.td"

Expand Down Expand Up @@ -37,7 +37,7 @@ class Core_FuncBaseOp< Dialect dialect, string mnemonic, list< Trait > traits =
CallableOpInterface,
FunctionOpInterface,
IsolatedFromAbove,
FuncSymbol,
Core_FuncSymbol,
NoTerminator,
DeclareOpInterfaceMethods< RegionKindInterface >
])
Expand Down
4 changes: 4 additions & 0 deletions include/vast/Dialect/Core/Interfaces/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

add_vast_op_interface(SymbolInterface)
add_vast_op_interface(SymbolTableInterface)
add_vast_attr_interface(SymbolRefInterface)
26 changes: 26 additions & 0 deletions include/vast/Dialect/Core/Interfaces/Common.td
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) 2024, Trail of Bits, Inc.

#ifndef VAST_DIALECT_CORE_INTERFACES_COMMON
#define VAST_DIALECT_CORE_INTERFACES_COMMON

include "mlir/IR/OpBase.td"

class Core_OpInterface<string name, list<Interface> baseInterfaces = []>
: OpInterface<name, baseInterfaces>
{
let cppNamespace = "::vast::core";
}

class Core_TypeInterface<string name, list<Interface> baseInterfaces = []>
: TypeInterface<name, baseInterfaces>
{
let cppNamespace = "::vast::core";
}

class Core_AttrInterface<string name, list<Interface> baseInterfaces = []>
: AttrInterface<name, baseInterfaces>
{
let cppNamespace = "::vast::core";
}

#endif // VAST_DIALECT_CORE_INTERFACES_COMMON
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace vast::core {
} // namespace vast::core

/// Include the generated interface declarations.
#include "vast/Interfaces/SymbolInterface.h.inc"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.h.inc"

namespace vast::core {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
include "mlir/IR/OpBase.td"
include "vast/Interfaces/Common.td"
include "vast/Dialect/Core/CoreTraits.td"
include "vast/Dialect/Core/Interfaces/Common.td"

def VastSymbol : VastOpInterface< "VastSymbolOpInterface" > {
def Core_Symbol : Core_OpInterface< "VastSymbolOpInterface" > {
let description = [{
This interface describes an operation that may define a `VastSymbol`.
This interface describes an operation that may define a `Symbol`.
}];

let methods = [
Expand Down Expand Up @@ -40,12 +41,12 @@ def VastSymbol : VastOpInterface< "VastSymbolOpInterface" > {
];
}

def VarSymbol : VastOpInterface< "VarSymbolOpInterface", [VastSymbol] >;
def MemberVarSymbol : VastOpInterface< "MemberVarSymbolOpInterface", [VastSymbol] >;
def FuncSymbol : VastOpInterface< "FuncSymbolOpInterface", [VastSymbol] >;
def TypeSymbol : VastOpInterface< "TypeSymbolOpInterface", [VastSymbol] >;
def ElaboratedTypeSymbol : VastOpInterface< "ElaboratedTypeSymbolOpInterface", [VastSymbol] >;
def LabelSymbol : VastOpInterface< "LabelSymbolOpInterface", [VastSymbol] >;
def EnumConstantSymbol : VastOpInterface< "EnumConstantSymbolOpInterface", [VastSymbol] >;
def Core_VarSymbol : Core_OpInterface< "VarSymbolOpInterface", [Core_Symbol] >;
def Core_MemberVarSymbol : Core_OpInterface< "MemberVarSymbolOpInterface", [Core_Symbol] >;
def Core_FuncSymbol : Core_OpInterface< "FuncSymbolOpInterface", [Core_Symbol] >;
def Core_TypeSymbol : Core_OpInterface< "TypeSymbolOpInterface", [Core_Symbol] >;
def Core_ElaboratedTypeSymbol : Core_OpInterface< "ElaboratedTypeSymbolOpInterface", [Core_Symbol] >;
def Core_LabelSymbol : Core_OpInterface< "LabelSymbolOpInterface", [Core_Symbol] >;
def Core_EnumConstantSymbol : Core_OpInterface< "EnumConstantSymbolOpInterface", [Core_Symbol] >;

#endif // VAST_INTERFACES_SYMBOL_INTERFACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ VAST_RELAX_WARNINGS
VAST_RELAX_WARNINGS

/// Include the generated interface declarations.
#include "vast/Interfaces/SymbolRefInterface.h.inc"
#include "vast/Dialect/Core/Interfaces/SymbolRefInterface.h.inc"
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#pragma once

#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"

#include "vast/Dialect/Core/CoreTraits.hpp"
#include "vast/Dialect/Core/SymbolTable.hpp"
Expand All @@ -15,7 +15,7 @@ namespace vast::core {
} // namespace vast::core

/// Include the generated interface declarations.
#include "vast/Interfaces/SymbolTableInterface.h.inc"
#include "vast/Dialect/Core/Interfaces/SymbolTableInterface.h.inc"

namespace vast::core {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def SymbolTableOpInterface : VastOpInterface< "SymbolTableOpInterface" > {

class GetCppTraitName< list<Interface> interfaces >
{
defvar cppInterfaceNames = !foreach(interface, interfaces, interface.cppInterfaceName);
defvar cppInterfaceNames = !foreach(interface, interfaces, interface.cppNamespace # "::" # interface.cppInterfaceName);
string result = [{ util::type_list< }] # !interleave(cppInterfaceNames, ", ") # [{ > }];
}

Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/Core/SymbolTable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ VAST_UNRELAX_WARNINGS
#include "vast/Util/Common.hpp"
#include "vast/Util/TypeList.hpp"

#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"

#include <gap/coro/generator.hpp>
#include <gap/coro/recursive_generator.hpp>
Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/HighLevel/HighLevel.td
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/IR/RegionKindInterface.td"
include "mlir/IR/BuiltinAttributeInterfaces.td"

include "vast/Interfaces/SymbolInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

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

Expand Down
4 changes: 2 additions & 2 deletions include/vast/Dialect/HighLevel/HighLevelCF.td
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
include "mlir/Interfaces/ControlFlowInterfaces.td"

include "vast/Dialect/Core/CoreTraits.td"
include "vast/Interfaces/SymbolInterface.td"
include "vast/Dialect/Core/Interfaces/SymbolInterface.td"

class HighLevel_ControlFlowOp< string mnemonic, list< Trait > traits = [] >
: HighLevel_Op< mnemonic, !listconcat(traits,
Expand Down Expand Up @@ -430,7 +430,7 @@ def HighLevel_DefaultOp
}

def HighLevel_LabelDeclOp
: HighLevel_Op< "label.decl", [LabelSymbol] >
: HighLevel_Op< "label.decl", [Core_LabelSymbol] >
, Arguments<(ins StrAttr:$name)>
, Results<(outs HighLevel_LabelType:$result)>
{
Expand Down
2 changes: 1 addition & 1 deletion include/vast/Dialect/HighLevel/HighLevelOps.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ VAST_UNRELAX_WARNINGS

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

#include "vast/Interfaces/SymbolInterface.hpp"
#include "vast/Dialect/Core/Interfaces/SymbolInterface.hpp"
#include "vast/Interfaces/AggregateTypeDefinitionInterface.hpp"
#include "vast/Interfaces/AST/DeclInterface.hpp"

Expand Down
Loading

0 comments on commit 1c234f8

Please sign in to comment.