diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index 5463bec..f53a09a 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -159,15 +159,17 @@ unsigned OperationBase::getNumFullArguments() const { void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out, FmtContext &fmt) const { for (const auto &arg : m_arguments) { - std::string defaultDeclaration = "$0 get$1();"; - if (!arg.type->isVarArgList() && !arg.type->isImmutable()) { + const bool isVarArg = arg.type->isVarArgList(); + std::string defaultDeclaration = "$0 get$1() $2;"; + + if (!isVarArg && !arg.type->isImmutable()) { defaultDeclaration += R"( - void set$1($0 $2); + void set$1($0 $3); )"; } out << tgfmt(defaultDeclaration, &fmt, arg.type->getGetterCppType(), - convertToCamelFromSnakeCase(arg.name, true), arg.name); + convertToCamelFromSnakeCase(arg.name, true), !isVarArg ? "const" : "", arg.name); } } @@ -196,9 +198,10 @@ void AccessorBuilder::emitGetterDefinition() const { } m_fmt.addSubst("fromLlvm", fromLlvm); + m_fmt.addSubst("const", !m_arg.type->isVarArgList() ? "const" : ""); m_os << tgfmt(R"( - $cppType $_op::get$Name() { + $cppType $_op::get$Name() $const { return $fromLlvm; })", &m_fmt); diff --git a/test/example/generated/ExampleDialect.cpp.inc b/test/example/generated/ExampleDialect.cpp.inc index 13f57dd..c8b2695 100644 --- a/test/example/generated/ExampleDialect.cpp.inc +++ b/test/example/generated/ExampleDialect.cpp.inc @@ -320,21 +320,21 @@ return true; } - ::llvm::Value * StreamReduceOp::getPtr() { + ::llvm::Value * StreamReduceOp::getPtr() const { return getArgOperand(0); } void StreamReduceOp::setPtr(::llvm::Value * ptr) { setArgOperand(0, ptr); } - ::llvm::Value * StreamReduceOp::getCount() { + ::llvm::Value * StreamReduceOp::getCount() const { return getArgOperand(1); } void StreamReduceOp::setCount(::llvm::Value * count) { setArgOperand(1, count); } - ::llvm::Value * StreamReduceOp::getInitial() { + ::llvm::Value * StreamReduceOp::getInitial() const { return getArgOperand(2); } @@ -439,21 +439,21 @@ uint32_t const extra = getExtra(); } - ::llvm::Value * Add32Op::getLhs() { + ::llvm::Value * Add32Op::getLhs() const { return getArgOperand(0); } void Add32Op::setLhs(::llvm::Value * lhs) { setArgOperand(0, lhs); } - ::llvm::Value * Add32Op::getRhs() { + ::llvm::Value * Add32Op::getRhs() const { return getArgOperand(1); } void Add32Op::setRhs(::llvm::Value * rhs) { setArgOperand(1, rhs); } - uint32_t Add32Op::getExtra() { + uint32_t Add32Op::getExtra() const { return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(2))->getZExtValue() ; } @@ -541,14 +541,14 @@ rhs } - ::llvm::Value * CombineOp::getLhs() { + ::llvm::Value * CombineOp::getLhs() const { return getArgOperand(0); } void CombineOp::setLhs(::llvm::Value * lhs) { setArgOperand(0, lhs); } - ::llvm::Value * CombineOp::getRhs() { + ::llvm::Value * CombineOp::getRhs() const { return getArgOperand(1); } @@ -645,14 +645,14 @@ index } - ::llvm::Value * ExtractElementOp::getVector() { + ::llvm::Value * ExtractElementOp::getVector() const { return getArgOperand(0); } void ExtractElementOp::setVector(::llvm::Value * vector) { setArgOperand(0, vector); } - ::llvm::Value * ExtractElementOp::getIndex() { + ::llvm::Value * ExtractElementOp::getIndex() const { return getArgOperand(1); } @@ -822,7 +822,7 @@ source } - ::llvm::Value * FromFixedVectorOp::getSource() { + ::llvm::Value * FromFixedVectorOp::getSource() const { return getArgOperand(0); } @@ -982,7 +982,7 @@ source } - ::llvm::Value * IExtOp::getSource() { + ::llvm::Value * IExtOp::getSource() const { return getArgOperand(0); } @@ -1080,7 +1080,7 @@ source } - ::llvm::Value * ITruncOp::getSource() { + ::llvm::Value * ITruncOp::getSource() const { return getArgOperand(0); } @@ -1154,7 +1154,7 @@ source } - bool ImmutableOp::getVal() { + bool ImmutableOp::getVal() const { return ::llvm::cast<::llvm::ConstantInt>(getArgOperand(0))->getZExtValue() ; } @@ -1257,21 +1257,21 @@ index } - ::llvm::Value * InsertElementOp::getVector() { + ::llvm::Value * InsertElementOp::getVector() const { return getArgOperand(0); } void InsertElementOp::setVector(::llvm::Value * vector) { setArgOperand(0, vector); } - ::llvm::Value * InsertElementOp::getValue() { + ::llvm::Value * InsertElementOp::getValue() const { return getArgOperand(1); } void InsertElementOp::setValue(::llvm::Value * value) { setArgOperand(1, value); } - ::llvm::Value * InsertElementOp::getIndex() { + ::llvm::Value * InsertElementOp::getIndex() const { return getArgOperand(2); } @@ -1348,14 +1348,14 @@ instName_0 } - ::llvm::Value * InstNameConflictDoubleOp::getInstName() { + ::llvm::Value * InstNameConflictDoubleOp::getInstName() const { return getArgOperand(0); } void InstNameConflictDoubleOp::setInstName(::llvm::Value * instName) { setArgOperand(0, instName); } - ::llvm::Value * InstNameConflictDoubleOp::getInstName_0() { + ::llvm::Value * InstNameConflictDoubleOp::getInstName_0() const { return getArgOperand(1); } @@ -1429,7 +1429,7 @@ instName } - ::llvm::Value * InstNameConflictOp::getInstName() { + ::llvm::Value * InstNameConflictOp::getInstName() const { return getArgOperand(0); } @@ -1497,7 +1497,7 @@ instName } - ::llvm::iterator_range<::llvm::User::value_op_iterator> InstNameConflictVarargsOp::getInstName_0() { + ::llvm::iterator_range<::llvm::User::value_op_iterator> InstNameConflictVarargsOp::getInstName_0() { return ::llvm::make_range( value_op_iterator(arg_begin() + 0), value_op_iterator(arg_end())); @@ -1673,7 +1673,7 @@ data } - ::llvm::Value * SetWriteOp::getData() { + ::llvm::Value * SetWriteOp::getData() const { return getArgOperand(0); } @@ -1746,7 +1746,7 @@ data } - ::llvm::Type * SizeOfOp::getSizeofType() { + ::llvm::Type * SizeOfOp::getSizeofType() const { return getArgOperand(0)->getType(); } @@ -2096,7 +2096,7 @@ initial } - ::llvm::StringRef StringAttrOp::getVal() { + ::llvm::StringRef StringAttrOp::getVal() const { return ::llvm::cast<::llvm::ConstantDataArray>(::llvm::cast<::llvm::GlobalVariable>(getArgOperand(0))->getInitializer())->getAsString() ; } @@ -2155,7 +2155,7 @@ data } - ::llvm::Value * WriteOp::getData() { + ::llvm::Value * WriteOp::getData() const { return getArgOperand(0); } @@ -2220,14 +2220,14 @@ data } - ::llvm::Value * WriteVarArgOp::getData() { + ::llvm::Value * WriteVarArgOp::getData() const { return getArgOperand(0); } void WriteVarArgOp::setData(::llvm::Value * data) { setArgOperand(0, data); } - ::llvm::iterator_range<::llvm::User::value_op_iterator> WriteVarArgOp::getArgs() { + ::llvm::iterator_range<::llvm::User::value_op_iterator> WriteVarArgOp::getArgs() { return ::llvm::make_range( value_op_iterator(arg_begin() + 1), value_op_iterator(arg_end())); diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index 1918a5e..913d295 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -98,11 +98,11 @@ uint32_t getNumElements() const; return ::llvm::isa<::llvm::CallInst>(v) && classof(::llvm::cast<::llvm::CallInst>(v)); } - ::llvm::Value * getPtr(); + ::llvm::Value * getPtr() const; void setPtr(::llvm::Value * ptr); - ::llvm::Value * getCount(); + ::llvm::Value * getCount() const; void setCount(::llvm::Value * count); - ::llvm::Value * getInitial(); + ::llvm::Value * getInitial() const; void setInitial(::llvm::Value * initial); }; @@ -122,11 +122,11 @@ uint32_t getNumElements() const; bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getLhs(); +::llvm::Value * getLhs() const; void setLhs(::llvm::Value * lhs); - ::llvm::Value * getRhs(); + ::llvm::Value * getRhs() const; void setRhs(::llvm::Value * rhs); - uint32_t getExtra(); + uint32_t getExtra() const; void setExtra(uint32_t extra); ::llvm::Value * getResult(); @@ -149,9 +149,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getLhs(); +::llvm::Value * getLhs() const; void setLhs(::llvm::Value * lhs); - ::llvm::Value * getRhs(); + ::llvm::Value * getRhs() const; void setRhs(::llvm::Value * rhs); ::llvm::Value * getResult(); @@ -174,9 +174,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getVector(); +::llvm::Value * getVector() const; void setVector(::llvm::Value * vector); - ::llvm::Value * getIndex(); + ::llvm::Value * getIndex() const; void setIndex(::llvm::Value * index); ::llvm::Value * getResult(); @@ -199,7 +199,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getSource(); +::llvm::Value * getSource() const; void setSource(::llvm::Value * source); ::llvm::Value * getResult(); @@ -243,7 +243,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getSource(); +::llvm::Value * getSource() const; void setSource(::llvm::Value * source); ::llvm::Value * getResult(); @@ -266,7 +266,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getSource(); +::llvm::Value * getSource() const; void setSource(::llvm::Value * source); ::llvm::Value * getResult(); @@ -289,7 +289,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -bool getVal(); +bool getVal() const; }; @@ -309,11 +309,11 @@ bool getVal(); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getVector(); +::llvm::Value * getVector() const; void setVector(::llvm::Value * vector); - ::llvm::Value * getValue(); + ::llvm::Value * getValue() const; void setValue(::llvm::Value * value); - ::llvm::Value * getIndex(); + ::llvm::Value * getIndex() const; void setIndex(::llvm::Value * index); ::llvm::Value * getResult(); @@ -336,9 +336,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getInstName(); +::llvm::Value * getInstName() const; void setInstName(::llvm::Value * instName); - ::llvm::Value * getInstName_0(); + ::llvm::Value * getInstName_0() const; void setInstName_0(::llvm::Value * instName_0); ::llvm::Value * getResult(); @@ -361,7 +361,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getInstName(); +::llvm::Value * getInstName() const; void setInstName(::llvm::Value * instName); ::llvm::Value * getResult(); @@ -384,7 +384,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::iterator_range<::llvm::User::value_op_iterator> getInstName_0(); +::llvm::iterator_range<::llvm::User::value_op_iterator> getInstName_0() ; ::llvm::Value * getResult(); @@ -447,7 +447,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getData(); +::llvm::Value * getData() const; void setData(::llvm::Value * data); @@ -469,7 +469,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Type * getSizeofType(); +::llvm::Type * getSizeofType() const; void setSizeofType(::llvm::Type * sizeof_type); ::llvm::Value * getResult(); @@ -555,7 +555,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::StringRef getVal(); +::llvm::StringRef getVal() const; }; @@ -575,7 +575,7 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getData(); +::llvm::Value * getData() const; void setData(::llvm::Value * data); @@ -597,9 +597,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::Value * getData(); +::llvm::Value * getData() const; void setData(::llvm::Value * data); - ::llvm::iterator_range<::llvm::User::value_op_iterator> getArgs(); + ::llvm::iterator_range<::llvm::User::value_op_iterator> getArgs() ; };