Store output and input operands as well as clobber information in the AsmStmt. Ted, could you please review the serialization/deserialization code?
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@44266 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/AST/Stmt.cpp b/AST/Stmt.cpp
index ccd27af..9a4d434 100644
--- a/AST/Stmt.cpp
+++ b/AST/Stmt.cpp
@@ -111,6 +111,29 @@
}
}
+AsmStmt::AsmStmt(SourceLocation asmloc,
+ unsigned numoutputs,
+ unsigned numinputs,
+ std::string *names,
+ StringLiteral **constraints,
+ Expr **exprs,
+ StringLiteral *asmstr,
+ unsigned numclobbers,
+ StringLiteral **clobbers,
+ SourceLocation rparenloc)
+ : Stmt(AsmStmtClass), AsmLoc(asmloc), RParenLoc(rparenloc), AsmStr(asmstr)
+ , NumOutputs(numoutputs), NumInputs(numinputs)
+{
+ for (unsigned i = 0, e = numinputs + numoutputs; i != e; i++) {
+ Names.push_back(names[i]);
+ Exprs.push_back(exprs[i]);
+ Constraints.push_back(constraints[i]);
+ }
+
+ for (unsigned i = 0; i != numclobbers; i++)
+ Clobbers.push_back(clobbers[i]);
+}
+
//===----------------------------------------------------------------------===//
// Child Iterators for iterating over subexpressions/substatements
//===----------------------------------------------------------------------===//
diff --git a/AST/StmtPrinter.cpp b/AST/StmtPrinter.cpp
index 306bfcb..cc6ffda 100644
--- a/AST/StmtPrinter.cpp
+++ b/AST/StmtPrinter.cpp
@@ -328,6 +328,57 @@
void StmtPrinter::VisitAsmStmt(AsmStmt *Node) {
Indent() << "asm (";
VisitStringLiteral(Node->getAsmString());
+
+ // Outputs
+ if (Node->getNumOutputs() != 0 || Node->getNumInputs() != 0 ||
+ Node->getNumClobbers() != 0)
+ OS << " : ";
+
+ for (unsigned i = 0, e = Node->getNumOutputs(); i != e; ++i) {
+ if (i != 0)
+ OS << ", ";
+
+ if (!Node->getOutputName(i).empty()) {
+ OS << '[';
+ OS << Node->getOutputName(i);
+ OS << "] ";
+ }
+
+ VisitStringLiteral(Node->getOutputConstraint(i));
+ OS << " ";
+ Visit(Node->getOutputExpr(i));
+ }
+
+ // Inputs
+ if (Node->getNumInputs() != 0 || Node->getNumClobbers() != 0)
+ OS << " : ";
+
+ for (unsigned i = 0, e = Node->getNumInputs(); i != e; ++i) {
+ if (i != 0)
+ OS << ", ";
+
+ if (!Node->getInputName(i).empty()) {
+ OS << '[';
+ OS << Node->getInputName(i);
+ OS << "] ";
+ }
+
+ VisitStringLiteral(Node->getInputConstraint(i));
+ OS << " ";
+ Visit(Node->getInputExpr(i));
+ }
+
+ // Clobbers
+ if (Node->getNumClobbers() != 0)
+ OS << " : ";
+
+ for (unsigned i = 0, e = Node->getNumClobbers(); i != e; ++i) {
+ if (i != 0)
+ OS << ", ";
+
+ VisitStringLiteral(Node->getClobber(i));
+ }
+
OS << ");\n";
}
diff --git a/AST/StmtSerialization.cpp b/AST/StmtSerialization.cpp
index f2c7834..46f8559 100644
--- a/AST/StmtSerialization.cpp
+++ b/AST/StmtSerialization.cpp
@@ -197,8 +197,27 @@
void AsmStmt::EmitImpl(Serializer& S) const {
S.Emit(AsmLoc);
+
getAsmString()->EmitImpl(S);
S.Emit(RParenLoc);
+
+ S.EmitInt(NumOutputs);
+ S.EmitInt(NumInputs);
+
+ unsigned size = NumOutputs + NumInputs;
+
+ for (unsigned i = 0; i < size; ++i)
+ S.EmitCStr(Names[i].c_str());
+
+ for (unsigned i = 0; i < size; ++i)
+ Constraints[i]->EmitImpl(S);
+
+ for (unsigned i = 0; i < size; ++i)
+ S.EmitOwnedPtr(Exprs[i]);
+
+ S.EmitInt(Clobbers.size());
+ for (unsigned i = 0, e = Clobbers.size(); i != e; ++i)
+ Clobbers[i]->EmitImpl(S);
}
AsmStmt* AsmStmt::CreateImpl(Deserializer& D) {
@@ -206,7 +225,37 @@
StringLiteral *AsmStr = StringLiteral::CreateImpl(D);
SourceLocation PLoc = SourceLocation::ReadVal(D);
- return new AsmStmt(ALoc, AsmStr, PLoc);
+ AsmStmt *Stmt = new AsmStmt(ALoc, 0, 0, 0, 0, 0,
+ AsmStr,
+ 0, 0, PLoc);
+
+ Stmt->NumOutputs = D.ReadInt();
+ Stmt->NumInputs = D.ReadInt();
+
+ unsigned size = Stmt->NumOutputs + Stmt->NumInputs;
+
+ Stmt->Names.reserve(size);
+ for (unsigned i = 0; i < size; ++i) {
+ std::vector<char> data;
+ D.ReadCStr(data, false);
+
+ Stmt->Names.push_back(std::string(&data[0], data.size()));
+ }
+
+ Stmt->Constraints.reserve(size);
+ for (unsigned i = 0; i < size; ++i)
+ Stmt->Constraints.push_back(StringLiteral::CreateImpl(D));
+
+ Stmt->Exprs.reserve(size);
+ for (unsigned i = 0; i < size; ++i)
+ Stmt->Exprs.push_back(D.ReadOwnedPtr<Expr>());
+
+ unsigned NumClobbers = D.ReadInt();
+ Stmt->Clobbers.reserve(NumClobbers);
+ for (unsigned i = 0; i < NumClobbers; ++i)
+ Stmt->Clobbers.push_back(StringLiteral::CreateImpl(D));
+
+ return Stmt;
}
void BinaryOperator::EmitImpl(Serializer& S) const {