Skip to content

Commit

Permalink
Add support for hierarchical configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
MikePopoloski committed Feb 27, 2024
1 parent 70c602e commit fa8850e
Show file tree
Hide file tree
Showing 7 changed files with 290 additions and 158 deletions.
16 changes: 9 additions & 7 deletions include/slang/ast/Compilation.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class Symbol;
class SystemSubroutine;
class ValueDriver;
struct AssertionInstanceDetails;
struct ConfigCellId;
struct ConfigRule;
struct ResolvedConfig;

using DriverIntervalMap = IntervalMap<uint64_t, const ValueDriver*>;
using UnrollIntervalMap = IntervalMap<uint64_t, std::monostate>;
Expand Down Expand Up @@ -211,12 +213,6 @@ struct HierarchyOverrideNode {

/// A list of bind directives to apply in this scope.
std::vector<const syntax::BindDirectiveSyntax*> binds;

/// A config rule that should be applied to this hierarchy instance.
const ConfigRule* configRule = nullptr;

/// Set to true if any direct child nodes have config rules supplied.
bool anyChildConfigRules = false;
};

/// A centralized location for creating and caching symbols. This includes
Expand Down Expand Up @@ -336,6 +332,11 @@ class SLANG_EXPORT Compilation : public BumpAllocator {
const ConfigRule& configRule, SourceRange sourceRange,
DiagCode code) const;

/// Gets the definition indicated by the given config and cell ID, or nullptr
/// if it does not exist. If no definition is found an appropriate diagnostic will be issued.
const DefinitionSymbol* getDefinition(const ConfigBlockSymbol& config,
const ConfigCellId& cell) const;

/// Gets a list of all definitions (including primitives) in the design.
std::vector<const Symbol*> getDefinitions() const;

Expand Down Expand Up @@ -683,7 +684,8 @@ class SLANG_EXPORT Compilation : public BumpAllocator {
std::span<const Symbol* const> instTargets,
const DefinitionSymbol* defTarget);
std::pair<const Symbol*, bool> resolveConfigRules(std::string_view name, const Scope& scope,
const ConfigRule& configRule,
const ResolvedConfig* parentConfig,
const ConfigRule* configRule,
const std::vector<Symbol*>& defList) const;
Diagnostic* errorMissingDef(std::string_view name, const Scope& scope, SourceRange sourceRange,
DiagCode code) const;
Expand Down
24 changes: 21 additions & 3 deletions include/slang/ast/symbols/CompilationUnitSymbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ struct ConfigCellId {
/// The source range where this cell id was declared.
SourceRange sourceRange;

/// If true, this ID targets a config block specifically.
bool targetConfig = false;

ConfigCellId() = default;
ConfigCellId(std::string_view lib, std::string_view name, SourceRange sourceRange) :
lib(lib), name(name), sourceRange(sourceRange) {}
Expand All @@ -242,13 +245,28 @@ struct ConfigRule {
/// A specific cell to use for this instance or definition lookup.
ConfigCellId useCell;

/// A specific config block to use for this instance and child instances.
const ConfigBlockSymbol* useConfig = nullptr;

/// The source range where this rule was declared.
SourceRange sourceRange;
};

/// Contains information about a resolved configuration rule
/// that affects an instance and the hierarchy underneath it.
struct ResolvedConfig {
/// A specific configuration to use for this hierarchy.
const ConfigBlockSymbol& useConfig;

/// The root instance of this particular configuration hierarchy.
const InstanceSymbol& rootInstance;

/// A list of libraries to use to look up definitions.
std::span<const SourceLibrary* const> liblist;

/// The original rule that was resolved.
const ConfigRule* configRule = nullptr;

ResolvedConfig(const ConfigBlockSymbol& useConfig, const InstanceSymbol& rootInstance);
};

/// Represents a config block declaration.
class SLANG_EXPORT ConfigBlockSymbol : public Symbol, public Scope {
public:
Expand Down
6 changes: 4 additions & 2 deletions include/slang/ast/symbols/InstanceSymbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class AssertionExpr;
class AttributeSymbol;
class CheckerSymbol;
class CheckerInstanceBodySymbol;
class ConfigBlockSymbol;
class DefinitionSymbol;
class Expression;
class InstanceBodySymbol;
Expand All @@ -30,7 +31,7 @@ class PortConnection;
class PortSymbol;
class PrimitiveSymbol;
class TimingControl;
struct ConfigRule;
struct ResolvedConfig;
struct HierarchyOverrideNode;
enum class DriveStrength : int;

Expand All @@ -56,13 +57,14 @@ class SLANG_EXPORT InstanceSymbolBase : public Symbol {
using Symbol::Symbol;
};

/// Represents an instance of a module, interface, or program.
class SLANG_EXPORT InstanceSymbol : public InstanceSymbolBase {
public:
const InstanceBodySymbol& body;

/// A config rule that applies to this instance, or a pointer to
/// the parent instance's config rule if there is one up the stack.
const ConfigRule* configRule = nullptr;
const ResolvedConfig* resolvedConfig = nullptr;

InstanceSymbol(std::string_view name, SourceLocation loc, InstanceBodySymbol& body);

Expand Down
Loading

0 comments on commit fa8850e

Please sign in to comment.