add some helper methods to AsmStmt and add some comments.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@66521 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/AST/Stmt.h b/include/clang/AST/Stmt.h
index 465b26f..40420dd 100644
--- a/include/clang/AST/Stmt.h
+++ b/include/clang/AST/Stmt.h
@@ -923,36 +923,65 @@
bool isVolatile() const { return IsVolatile; }
bool isSimple() const { return IsSimple; }
+ //===--- Output operands ---===//
+
unsigned getNumOutputs() const { return NumOutputs; }
const std::string &getOutputName(unsigned i) const {
return Names[i];
}
- const StringLiteral *getOutputConstraint(unsigned i) const {
+ /// getOutputConstraint - Return the constraint string for the specified
+ /// output operand. All output constraints are known to be non-empty (either
+ /// '=' or '+').
+ std::string getOutputConstraint(unsigned i) const;
+
+ const StringLiteral *getOutputConstraintLiteral(unsigned i) const {
return Constraints[i];
}
-
- StringLiteral *getOutputConstraint(unsigned i)
- { return Constraints[i]; }
-
- const Expr *getOutputExpr(unsigned i) const;
+ StringLiteral *getOutputConstraintLiteral(unsigned i) {
+ return Constraints[i];
+ }
+
+
Expr *getOutputExpr(unsigned i);
+ const Expr *getOutputExpr(unsigned i) const {
+ return const_cast<AsmStmt*>(this)->getOutputExpr(i);
+ }
+
+ /// isOutputPlusConstraint - Return true if the specified output constraint
+ /// is a "+" constraint (which is both an input and an output) or false if it
+ /// is an "=" constraint (just an output).
+ bool isOutputPlusConstraint(unsigned i) const {
+ return getOutputConstraint(i)[0] == '+';
+ }
+
+ //===--- Input operands ---===//
+
unsigned getNumInputs() const { return NumInputs; }
const std::string &getInputName(unsigned i) const {
return Names[i + NumOutputs];
}
- StringLiteral *getInputConstraint(unsigned i) {
+
+ /// getInputConstraint - Return the specified input constraint. Unlike output
+ /// constraints, these can be empty.
+ std::string getInputConstraint(unsigned i) const;
+
+ const StringLiteral *getInputConstraintLiteral(unsigned i) const {
return Constraints[i + NumOutputs];
}
- const StringLiteral *getInputConstraint(unsigned i) const {
+ StringLiteral *getInputConstraintLiteral(unsigned i) {
return Constraints[i + NumOutputs];
}
-
+
+
Expr *getInputExpr(unsigned i);
- const Expr *getInputExpr(unsigned i) const;
+
+ const Expr *getInputExpr(unsigned i) const {
+ return const_cast<AsmStmt*>(this)->getInputExpr(i);
+ }
const StringLiteral *getAsmString() const { return AsmStr; }
StringLiteral *getAsmString() { return AsmStr; }
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp
index 749b677..682a9b1 100644
--- a/lib/AST/Stmt.cpp
+++ b/lib/AST/Stmt.cpp
@@ -130,17 +130,28 @@
}
}
-const Expr* AsmStmt::getOutputExpr(unsigned i) const {
+Expr *AsmStmt::getOutputExpr(unsigned i) {
return cast<Expr>(Exprs[i]);
}
-Expr* AsmStmt::getOutputExpr(unsigned i) {
- return cast<Expr>(Exprs[i]);
+
+/// getOutputConstraint - Return the constraint string for the specified
+/// output operand. All output constraints are known to be non-empty (either
+/// '=' or '+').
+std::string AsmStmt::getOutputConstraint(unsigned i) const {
+ return std::string(Constraints[i]->getStrData(),
+ Constraints[i]->getByteLength());
}
-Expr* AsmStmt::getInputExpr(unsigned i) {
+
+
+Expr *AsmStmt::getInputExpr(unsigned i) {
return cast<Expr>(Exprs[i + NumOutputs]);
}
-const Expr* AsmStmt::getInputExpr(unsigned i) const {
- return cast<Expr>(Exprs[i + NumOutputs]);
+
+/// getInputConstraint - Return the specified input constraint. Unlike output
+/// constraints, these can be empty.
+std::string AsmStmt::getInputConstraint(unsigned i) const {
+ return std::string(Constraints[i + NumOutputs]->getStrData(),
+ Constraints[i + NumOutputs]->getByteLength());
}
//===----------------------------------------------------------------------===//
diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp
index e6ac310..bcd1a86 100644
--- a/lib/AST/StmtPrinter.cpp
+++ b/lib/AST/StmtPrinter.cpp
@@ -397,7 +397,7 @@
OS << "] ";
}
- VisitStringLiteral(Node->getOutputConstraint(i));
+ VisitStringLiteral(Node->getOutputConstraintLiteral(i));
OS << " ";
Visit(Node->getOutputExpr(i));
}
@@ -416,7 +416,7 @@
OS << "] ";
}
- VisitStringLiteral(Node->getInputConstraint(i));
+ VisitStringLiteral(Node->getInputConstraintLiteral(i));
OS << " ";
Visit(Node->getInputExpr(i));
}
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 69ed080..3fd6526 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -919,8 +919,7 @@
llvm::SmallVector<TargetInfo::ConstraintInfo, 4> OutputConstraintInfos;
for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) {
- std::string OutputConstraint(S.getOutputConstraint(i)->getStrData(),
- S.getOutputConstraint(i)->getByteLength());
+ std::string OutputConstraint(S.getOutputConstraint(i));
TargetInfo::ConstraintInfo Info;
bool result = Target.validateOutputConstraint(OutputConstraint.c_str(),
@@ -973,8 +972,7 @@
for (unsigned i = 0, e = S.getNumInputs(); i != e; i++) {
const Expr *InputExpr = S.getInputExpr(i);
- std::string InputConstraint(S.getInputConstraint(i)->getStrData(),
- S.getInputConstraint(i)->getByteLength());
+ std::string InputConstraint(S.getInputConstraint(i));
TargetInfo::ConstraintInfo Info;
bool result = Target.validateInputConstraint(InputConstraint.c_str(),