2121#include < utility>
2222#include < vector>
2323
24- #include " gmock/gmock.h"
25- #include " gtest/gtest.h"
2624#include " absl/container/flat_hash_map.h"
2725#include " absl/status/status.h"
2826#include " absl/status/status_matchers.h"
2927#include " absl/strings/str_cat.h"
3028#include " absl/strings/str_format.h"
3129#include " absl/types/span.h"
30+ #include " gmock/gmock.h"
31+ #include " gtest/gtest.h"
3232#include " xls/common/status/matchers.h"
3333#include " xls/ir/bits.h"
3434#include " xls/ir/fileno.h"
@@ -556,11 +556,8 @@ TEST_P(VastTest, ModuleWithUserDataTypes) {
556556 Module* module = f.Make <Module>(SourceInfo (), " my_module" );
557557 XLS_ASSERT_OK_AND_ASSIGN (
558558 LogicRef * out_ref,
559- module ->AddOutput (
560- " out" ,
561- f.Make <ExternType>(SourceInfo (), f.BitVectorType (64 , SourceInfo ()),
562- " foobar" ),
563- SourceInfo ()));
559+ module ->AddOutput (" out" , f.Make <ExternType>(SourceInfo (), " foobar" ),
560+ SourceInfo ()));
564561 module ->Add <ContinuousAssignment>(SourceInfo (), out_ref,
565562 f.Literal (UBits (32 , 64 ), SourceInfo ()));
566563 if (UseSystemVerilog ()) {
@@ -1825,25 +1822,21 @@ TEST_P(VastTest, TypeCastEmission) {
18251822 m->AddInput (" a" , f.BitVectorType (8 , si), si));
18261823 XLS_ASSERT_OK_AND_ASSIGN (
18271824 LogicRef * out_foo,
1828- m->AddOutput (" out_foo" ,
1829- f.Make <ExternType>(si, f.BitVectorType (8 , si), " foobar" ),
1830- si));
1825+ m->AddOutput (" out_foo" , f.Make <ExternType>(si, " foobar" ), si));
18311826 XLS_ASSERT_OK_AND_ASSIGN (
18321827 LogicRef * out_pkg,
1833- m->AddOutput (" out_pkg" ,
1834- f. Make <ExternPackageType>(si, " my_pkg " , " my_type_t " ), si));
1828+ m->AddOutput (" out_pkg" , f. Make <ExternType>(si, " my_pkg " , " my_type_t " ),
1829+ si));
18351830
18361831 // assign out_foo = foobar'(a + 1);
18371832 m->Add <ContinuousAssignment>(
18381833 si, out_foo,
1839- f.Make <TypeCast>(si,
1840- f.Make <ExternType>(si, f.BitVectorType (8 , si), " foobar" ),
1834+ f.Make <TypeCast>(si, f.Make <ExternType>(si, " foobar" ),
18411835 f.Add (a, f.PlainLiteral (1 , si), si)));
18421836 // assign out_pkg = my_pkg::my_type_t'(a);
18431837 m->Add <ContinuousAssignment>(
18441838 si, out_pkg,
1845- f.Make <TypeCast>(si, f.Make <ExternPackageType>(si, " my_pkg" , " my_type_t" ),
1846- a));
1839+ f.Make <TypeCast>(si, f.Make <ExternType>(si, " my_pkg" , " my_type_t" ), a));
18471840
18481841 EXPECT_EQ (m->Emit (nullptr ),
18491842 R"( module top(
@@ -2673,7 +2666,7 @@ TEST_P(VastTest, EnumAssignment) {
26732666 enum_type->AddMember (" RED" , f.PlainLiteral (0 , si), si);
26742667
26752668 // Note that this is an externally defined type.
2676- DataType* extern_enum_type = f.ExternType (enum_type, " color_e" , si);
2669+ DataType* extern_enum_type = f.ExternType (" color_e" , si);
26772670
26782671 XLS_ASSERT_OK_AND_ASSIGN (
26792672 LogicRef * signal, m->AddWire (" signal" , extern_enum_type, SourceInfo ()));
@@ -2699,7 +2692,7 @@ TEST_P(VastTest, ExternTypePort) {
26992692 enum_type->AddMember (" RED" , f.PlainLiteral (0 , si), si);
27002693
27012694 // Note that this is an externally defined type.
2702- DataType* extern_enum_type = f.ExternType (enum_type, " color_e" , si);
2695+ DataType* extern_enum_type = f.ExternType (" color_e" , si);
27032696
27042697 // Declare a port of the extern type.
27052698 XLS_ASSERT_OK_AND_ASSIGN (LogicRef * input,
@@ -2729,7 +2722,7 @@ TEST_P(VastTest, ExternalPackageTypePort) {
27292722 Module* m = f.AddModule (" top" , si);
27302723
27312724 // Make an extern package type to use in the `input` construction.
2732- auto * data_type = f.Make <ExternPackageType >(si, " mypack" , " mystruct_t" );
2725+ auto * data_type = f.Make <ExternType >(si, " mypack" , " mystruct_t" );
27332726
27342727 XLS_ASSERT_OK_AND_ASSIGN (LogicRef * input,
27352728 m->AddInput (" my_input" , data_type, si));
@@ -2753,7 +2746,7 @@ TEST_P(VastTest, ExternalPackageTypePackedArrayPort) {
27532746 Module* m = f.AddModule (" top" , si);
27542747
27552748 // Make an extern package type to use in the `input` construction.
2756- auto * data_type = f.Make <ExternPackageType >(si, " mypack" , " mystruct_t" );
2749+ auto * data_type = f.Make <ExternType >(si, " mypack" , " mystruct_t" );
27572750 const std::vector<int64_t > packed_dims = {2 , 3 , 4 };
27582751 const bool dims_are_max = false ;
27592752 auto * packed_array =
@@ -2943,6 +2936,42 @@ TEST_P(VastTest, ModuleParameterPortsWithIo) {
29432936endmodule)" );
29442937}
29452938
2939+ TEST_P (VastTest, MacroStatements) {
2940+ VerilogFile f (GetFileType ());
2941+ Module* m = f.AddModule (" top" , SourceInfo ());
2942+ XLS_ASSERT_OK_AND_ASSIGN (
2943+ LogicRef * a,
2944+ m->AddInput (" a" , f.BitVectorType (8 , SourceInfo ()), SourceInfo ()));
2945+ XLS_ASSERT_OK_AND_ASSIGN (
2946+ LogicRef * b,
2947+ m->AddInput (" b" , f.BitVectorType (8 , SourceInfo ()), SourceInfo ()));
2948+
2949+ m->Add <MacroStatement>(SourceInfo (),
2950+ f.Make <MacroRef>(SourceInfo (), " MY_MACRO1" ),
2951+ /* emit_semicolon=*/ true );
2952+ m->Add <MacroStatement>(
2953+ SourceInfo (),
2954+ f.Make <MacroRef>(SourceInfo (), " MY_MACRO2" , std::vector<Expression*>{}),
2955+ /* emit_semicolon=*/ false );
2956+ m->Add <MacroStatement>(
2957+ SourceInfo (),
2958+ f.Make <MacroRef>(SourceInfo (), " MY_MACRO3" , std::vector<Expression*>{a}),
2959+ /* emit_semicolon=*/ false );
2960+ m->Add <MacroStatement>(SourceInfo (),
2961+ f.Make <MacroRef>(SourceInfo (), " MY_MACRO4" ,
2962+ std::vector<Expression*>{a, b}),
2963+ /* emit_semicolon=*/ true );
2964+ EXPECT_EQ (m->Emit (nullptr ), R"( module top(
2965+ input wire [7:0] a,
2966+ input wire [7:0] b
2967+ );
2968+ `MY_MACRO1;
2969+ `MY_MACRO2()
2970+ `MY_MACRO3(a)
2971+ `MY_MACRO4(a, b);
2972+ endmodule)" );
2973+ }
2974+
29462975INSTANTIATE_TEST_SUITE_P (VastTestInstantiation, VastTest,
29472976 testing::Values (false , true ),
29482977 [](const testing::TestParamInfo<bool >& info) {
0 commit comments