Skip to content

Commit

Permalink
[FIREmitter] Support String constants
Browse files Browse the repository at this point in the history
  • Loading branch information
youngar committed Jul 31, 2023
1 parent b7119e8 commit b4f0691
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion include/circt/Dialect/FIRRTL/FIRRTLVisitors.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ExprVisitor {
UninferredResetCastOp, ConstCastOp, RefCastOp,
mlir::UnrealizedConversionCastOp,
// Property expressions.
BigIntConstantOp>([&](auto expr) -> ResultType {
StringConstantOp, BigIntConstantOp>([&](auto expr) -> ResultType {
return thisCast->visitExpr(expr, args...);
})
.Default([&](auto expr) -> ResultType {
Expand Down Expand Up @@ -197,6 +197,7 @@ class ExprVisitor {
HANDLE(RefCastOp, Unhandled);

// Property expressions.
HANDLE(StringConstantOp, Unhandled);
HANDLE(BigIntConstantOp, Unhandled);
#undef HANDLE
};
Expand Down
10 changes: 9 additions & 1 deletion lib/Dialect/FIRRTL/Export/FIREmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct Emitter {
void emitExpression(RefSubOp op);
void emitExpression(UninferredResetCastOp op);
void emitExpression(ConstCastOp op);
void emitExpression(StringConstantOp op);
void emitExpression(BigIntConstantOp op);

void emitPrimExpr(StringRef mnemonic, Operation *op,
Expand Down Expand Up @@ -1010,7 +1011,8 @@ void Emitter::emitExpression(Value value) {
CvtPrimOp, NegPrimOp, NotPrimOp, AndRPrimOp, OrRPrimOp, XorRPrimOp,
// Miscellaneous
BitsPrimOp, HeadPrimOp, TailPrimOp, PadPrimOp, MuxPrimOp, ShlPrimOp,
ShrPrimOp, UninferredResetCastOp, ConstCastOp, BigIntConstantOp,
ShrPrimOp, UninferredResetCastOp, ConstCastOp, StringConstantOp,
BigIntConstantOp,
// Reference expressions
RefSendOp, RefResolveOp, RefSubOp>([&](auto op) {
ps.scopedBox(PP::ibox0, [&]() { emitExpression(op); });
Expand Down Expand Up @@ -1122,6 +1124,12 @@ void Emitter::emitExpression(BigIntConstantOp op) {
ps << ")";
}

void Emitter::emitExpression(StringConstantOp op) {
ps << "String(";
ps.writeQuotedEscaped(op.getValue());
ps << ")";
}

void Emitter::emitExpression(ConstCastOp op) { emitExpression(op.getInput()); }

void Emitter::emitPrimExpr(StringRef mnemonic, Operation *op,
Expand Down
13 changes: 9 additions & 4 deletions test/Dialect/FIRRTL/emit-basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -640,10 +640,15 @@ firrtl.circuit "Foo" {
}

// CHECK-LABEL: module Properties :
firrtl.module @Properties(out %out : !firrtl.bigint) {
// CHECK: propassign out, Integer(99)
%0 = firrtl.bigint 99
firrtl.propassign %out, %0 : !firrtl.bigint
firrtl.module @Properties(out %string : !firrtl.string,
out %integer : !firrtl.bigint) {
// CHECK: propassign string, String("hello")
%0 = firrtl.string "hello"
firrtl.propassign %string, %0 : !firrtl.string

// CHECK: propassign integer, Integer(99)
%1 = firrtl.bigint 99
firrtl.propassign %integer, %1 : !firrtl.bigint
}

// Test optional group declaration and definition emission.
Expand Down

0 comments on commit b4f0691

Please sign in to comment.