diff --git a/lib/TableGen/Operations.cpp b/lib/TableGen/Operations.cpp index dcfd06b..d10f3b7 100644 --- a/lib/TableGen/Operations.cpp +++ b/lib/TableGen/Operations.cpp @@ -159,8 +159,20 @@ unsigned OperationBase::getNumFullArguments() const { void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out, FmtContext &fmt) const { + llvm::SmallVector argNames; + + unsigned numSuperclassArgs = 0; + if (m_superclass) + numSuperclassArgs = m_superclass->getNumFullArguments(); + for (const auto &arg : m_arguments) { + const std::string capitalizedArgName = + convertToCamelFromSnakeCase(arg.name, true); + const bool isVarArg = arg.type->isVarArgList(); + + argNames.push_back(capitalizedArgName + (isVarArg ? "Start" : "")); + std::string defaultDeclaration = "$0 get$1() $2;"; if (!arg.type->isImmutable()) { @@ -178,7 +190,14 @@ void OperationBase::emitArgumentAccessorDeclarations(llvm::raw_ostream &out, } out << tgfmt(defaultDeclaration, &fmt, arg.type->getGetterCppType(), - convertToCamelFromSnakeCase(arg.name, true), !isVarArg ? "const" : "", arg.name); + capitalizedArgName, !isVarArg ? "const" : "", arg.name); + } + + if (!argNames.empty()) { + out << "enum class ArgumentIndex: uint32_t {\n"; + for (const auto &[index, argName] : llvm::enumerate(argNames)) + out << tgfmt("$0 = $1,\n", &fmt, argName, numSuperclassArgs + index); + out << "};"; } } diff --git a/test/example/generated/ExampleDialect.h.inc b/test/example/generated/ExampleDialect.h.inc index 0e3e59b..9e5794f 100644 --- a/test/example/generated/ExampleDialect.h.inc +++ b/test/example/generated/ExampleDialect.h.inc @@ -104,7 +104,11 @@ uint32_t getNumElements() const; void setCount(::llvm::Value * count); ::llvm::Value * getInitial() const; void setInitial(::llvm::Value * initial); - + enum class ArgumentIndex: uint32_t { +Ptr = 0, +Count = 1, +Initial = 2, +}; }; class Add32Op : public ::llvm::CallInst { @@ -128,7 +132,11 @@ bool verifier(::llvm::raw_ostream &errs); void setRhs(::llvm::Value * rhs); uint32_t getExtra() const; void setExtra(uint32_t extra); - + enum class ArgumentIndex: uint32_t { +Lhs = 0, +Rhs = 1, +Extra = 2, +}; ::llvm::Value * getResult(); @@ -153,7 +161,10 @@ bool verifier(::llvm::raw_ostream &errs); void setLhs(::llvm::Value * lhs); ::llvm::Value * getRhs() const; void setRhs(::llvm::Value * rhs); - + enum class ArgumentIndex: uint32_t { +Lhs = 0, +Rhs = 1, +}; ::llvm::Value * getResult(); @@ -178,7 +189,10 @@ bool verifier(::llvm::raw_ostream &errs); void setVector(::llvm::Value * vector); ::llvm::Value * getIndex() const; void setIndex(::llvm::Value * index); - + enum class ArgumentIndex: uint32_t { +Vector = 0, +Index = 1, +}; ::llvm::Value * getResult(); @@ -201,7 +215,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource() const; void setSource(::llvm::Value * source); - + enum class ArgumentIndex: uint32_t { +Source = 0, +}; ::llvm::Value * getResult(); @@ -245,7 +261,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource() const; void setSource(::llvm::Value * source); - + enum class ArgumentIndex: uint32_t { +Source = 0, +}; ::llvm::Value * getResult(); @@ -268,7 +286,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getSource() const; void setSource(::llvm::Value * source); - + enum class ArgumentIndex: uint32_t { +Source = 0, +}; ::llvm::Value * getResult(); @@ -289,7 +309,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -bool getVal() const; +bool getVal() const;enum class ArgumentIndex: uint32_t { +Val = 0, +}; }; @@ -315,7 +337,11 @@ bool verifier(::llvm::raw_ostream &errs); void setValue(::llvm::Value * value); ::llvm::Value * getIndex() const; void setIndex(::llvm::Value * index); - + enum class ArgumentIndex: uint32_t { +Vector = 0, +Value = 1, +Index = 2, +}; ::llvm::Value * getResult(); @@ -340,7 +366,10 @@ bool verifier(::llvm::raw_ostream &errs); void setInstName(::llvm::Value * instName); ::llvm::Value * getInstName_0() const; void setInstName_0(::llvm::Value * instName_0); - + enum class ArgumentIndex: uint32_t { +InstName = 0, +InstName_0 = 1, +}; ::llvm::Value * getResult(); @@ -363,7 +392,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getInstName() const; void setInstName(::llvm::Value * instName); - + enum class ArgumentIndex: uint32_t { +InstName = 0, +}; ::llvm::Value * getResult(); @@ -388,7 +419,9 @@ bool verifier(::llvm::raw_ostream &errs); /// Returns a new op with the same arguments and a new tail argument list. /// The object on which this is called will be replaced and erased. InstNameConflictVarargsOp *replaceInstName_0(::llvm::ArrayRef); - + enum class ArgumentIndex: uint32_t { +InstName_0Start = 0, +}; ::llvm::Value * getResult(); @@ -453,7 +486,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData() const; void setData(::llvm::Value * data); - + enum class ArgumentIndex: uint32_t { +Data = 0, +}; }; @@ -475,7 +510,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Type * getSizeofType() const; void setSizeofType(::llvm::Type * sizeof_type); - + enum class ArgumentIndex: uint32_t { +SizeofType = 0, +}; ::llvm::Value * getResult(); @@ -559,7 +596,9 @@ bool verifier(::llvm::raw_ostream &errs); bool verifier(::llvm::raw_ostream &errs); -::llvm::StringRef getVal() const; +::llvm::StringRef getVal() const;enum class ArgumentIndex: uint32_t { +Val = 0, +}; }; @@ -581,7 +620,9 @@ bool verifier(::llvm::raw_ostream &errs); ::llvm::Value * getData() const; void setData(::llvm::Value * data); - + enum class ArgumentIndex: uint32_t { +Data = 0, +}; }; @@ -607,7 +648,10 @@ bool verifier(::llvm::raw_ostream &errs); /// Returns a new op with the same arguments and a new tail argument list. /// The object on which this is called will be replaced and erased. WriteVarArgOp *replaceArgs(::llvm::ArrayRef); - + enum class ArgumentIndex: uint32_t { +Data = 0, +ArgsStart = 1, +}; };