Skip to content
Draft
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
5 changes: 5 additions & 0 deletions xls/dslx/fmt/ast_fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3125,6 +3125,11 @@ absl::StatusOr<DocRef> Formatter::Format(const Module& n) {
pieces.push_back(arena_.MakeText("#![feature(channel_attributes)]"));
pieces.push_back(arena_.hard_line());
break;
case ModuleAttribute::kExplicitStateAccess:
pieces.push_back(
arena_.MakeText("#![feature(explicit_state_access)]"));
pieces.push_back(arena_.hard_line());
break;
case ModuleAttribute::kGenerics:
pieces.push_back(arena_.MakeText("#![feature(generics)]"));
pieces.push_back(arena_.hard_line());
Expand Down
3 changes: 3 additions & 0 deletions xls/dslx/frontend/module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ std::string Module::ToString() const {
case ModuleAttribute::kChannelAttributes:
absl::StrAppend(out, "#![feature(channel_attributes)]");
break;
case ModuleAttribute::kExplicitStateAccess:
absl::StrAppend(out, "#![feature(explicit_state_access)]");
break;
case ModuleAttribute::kGenerics:
absl::StrAppend(out, "#![feature(generics)]");
break;
Expand Down
4 changes: 4 additions & 0 deletions xls/dslx/frontend/module.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ enum class ModuleAttribute : uint8_t {
// Enable #channel() attributes for this module.
kChannelAttributes,

// Enable read and write with optional labels for state access for this
// module.
kExplicitStateAccess,

kGenerics,

// Enable `trait` declarations.
Expand Down
3 changes: 3 additions & 0 deletions xls/dslx/frontend/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,9 @@ absl::Status Parser::ParseModuleAttribute() {
} else if (feature == "channel_attributes") {
module_->AddAttribute(ModuleAttribute::kChannelAttributes,
attribute_span);
} else if (feature == "explicit_state_access") {
module_->AddAttribute(ModuleAttribute::kExplicitStateAccess,
attribute_span);
} else if (feature == "generics") {
module_->AddAttribute(ModuleAttribute::kGenerics, attribute_span);
} else if (feature == "traits") {
Expand Down
8 changes: 8 additions & 0 deletions xls/dslx/frontend/parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3451,6 +3451,14 @@ TEST_F(ParserTest, ParseTypeInferenceV1AndV2Attributes) {
"and `type_inference_v2` attributes")));
}

TEST_F(ParserTest, ParseExplicitStateAccessAttribute) {
XLS_ASSERT_OK_AND_ASSIGN(std::unique_ptr<Module> module, Parse(R"(
#![feature(explicit_state_access)]
)"));
EXPECT_THAT(module->attributes(),
testing::ElementsAre(ModuleAttribute::kExplicitStateAccess));
}

// Verifies that we can walk backwards through a tree. In this case, from the
// terminal node to the defining expr.
TEST(ParserBackrefTest, CanFindDefiner) {
Expand Down