From: Chris Lattner Date: Sun, 26 Apr 2009 17:19:08 +0000 (+0000) Subject: pull the constraint string into the ConstraintInfo struct X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=432c86969eced2ce658b3f3f2aa7407c8864f21b;p=clang pull the constraint string into the ConstraintInfo struct instead of passing it around in addition to it. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70135 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/clang.xcodeproj/project.pbxproj b/clang.xcodeproj/project.pbxproj index c6001868eb..312a1bae5a 100644 --- a/clang.xcodeproj/project.pbxproj +++ b/clang.xcodeproj/project.pbxproj @@ -51,7 +51,6 @@ 356EF9B50C8F7DDF006650F5 /* LiveVariables.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 356EF9B40C8F7DDF006650F5 /* LiveVariables.cpp */; }; 35707EFE0CD0F5CC000B2204 /* SourceLocation.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35707EFD0CD0F5CC000B2204 /* SourceLocation.cpp */; }; 357EA27D0F2526F300439B60 /* SemaLookup.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 357EA27C0F2526F300439B60 /* SemaLookup.cpp */; }; - 3580CC0C0D072E5C00C5E4F4 /* LangOptions.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3580CC0B0D072E5C00C5E4F4 /* LangOptions.cpp */; }; 35847BE50CC7DBAF00C40FFF /* StmtIterator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35847BE40CC7DBAF00C40FFF /* StmtIterator.cpp */; }; 35862B0D0E3628CB0009F542 /* CheckDeadStores.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35862B0C0E3628CB0009F542 /* CheckDeadStores.cpp */; }; 35862B120E3629850009F542 /* GRExprEngineInternalChecks.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 35862B110E3629850009F542 /* GRExprEngineInternalChecks.cpp */; }; @@ -395,7 +394,6 @@ 356EF9B40C8F7DDF006650F5 /* LiveVariables.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = LiveVariables.cpp; path = lib/Analysis/LiveVariables.cpp; sourceTree = ""; }; 35707EFD0CD0F5CC000B2204 /* SourceLocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = SourceLocation.cpp; sourceTree = ""; tabWidth = 2; }; 357EA27C0F2526F300439B60 /* SemaLookup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaLookup.cpp; path = lib/Sema/SemaLookup.cpp; sourceTree = ""; tabWidth = 2; }; - 3580CC0B0D072E5C00C5E4F4 /* LangOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = LangOptions.cpp; sourceTree = ""; tabWidth = 2; }; 35847BE30CC7DB9000C40FFF /* StmtIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = StmtIterator.h; path = clang/AST/StmtIterator.h; sourceTree = ""; tabWidth = 2; }; 35847BE40CC7DBAF00C40FFF /* StmtIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = StmtIterator.cpp; path = lib/AST/StmtIterator.cpp; sourceTree = ""; tabWidth = 2; }; 35862B0C0E3628CB0009F542 /* CheckDeadStores.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckDeadStores.cpp; path = lib/Analysis/CheckDeadStores.cpp; sourceTree = ""; }; @@ -1260,7 +1258,6 @@ DED7D75D0A5242C7003AD0FB /* Diagnostic.cpp */, DED7D75E0A5242C7003AD0FB /* FileManager.cpp */, DE3986F30CB8D50C00223765 /* IdentifierTable.cpp */, - 3580CC0B0D072E5C00C5E4F4 /* LangOptions.cpp */, 35707EFD0CD0F5CC000B2204 /* SourceLocation.cpp */, DED7D76D0A5242C7003AD0FB /* SourceManager.cpp */, DED626C80AE0C065001E80A4 /* TargetInfo.cpp */, @@ -1536,7 +1533,6 @@ DE3986F40CB8D50C00223765 /* IdentifierTable.cpp in Sources */, 35847BE50CC7DBAF00C40FFF /* StmtIterator.cpp in Sources */, 35707EFE0CD0F5CC000B2204 /* SourceLocation.cpp in Sources */, - 3580CC0C0D072E5C00C5E4F4 /* LangOptions.cpp in Sources */, DE704B260D0FBEBE009C7762 /* SemaDeclObjC.cpp in Sources */, DE704DD20D1668A4009C7762 /* HeaderMap.cpp in Sources */, 35BB2D7F0D19954000944DB5 /* ASTConsumer.cpp in Sources */, diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h index eb26577cd8..e01e9da066 100644 --- a/include/clang/Basic/TargetInfo.h +++ b/include/clang/Basic/TargetInfo.h @@ -208,9 +208,15 @@ public: }; unsigned Flags; int TiedOperand; - public: - ConstraintInfo() : Flags(0), TiedOperand(-1) {} + std::string ConstraintStr; + public: + ConstraintInfo(const char *str, unsigned strlen) + : Flags(0), TiedOperand(-1), ConstraintStr(str, str+strlen) {} + explicit ConstraintInfo(const std::string &Str) + : Flags(0), TiedOperand(-1), ConstraintStr(Str) {} + + const std::string &getConstraintStr() const { return ConstraintStr; } bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; } bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; } bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; } @@ -229,9 +235,8 @@ public: // validateOutputConstraint, validateInputConstraint - Checks that // a constraint is valid and provides information about it. // FIXME: These should return a real error instead of just true/false. - bool validateOutputConstraint(const char *Name, ConstraintInfo &Info) const; - bool validateInputConstraint(const char *Name, - const std::string *OutputNamesBegin, + bool validateOutputConstraint(ConstraintInfo &Info) const; + bool validateInputConstraint(const std::string *OutputNamesBegin, const std::string *OutputNamesEnd, ConstraintInfo* OutputConstraints, ConstraintInfo &info) const; diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp index cee13eab41..b8aa535329 100644 --- a/lib/Basic/TargetInfo.cpp +++ b/lib/Basic/TargetInfo.cpp @@ -163,8 +163,8 @@ const char *TargetInfo::getNormalizedGCCRegisterName(const char *Name) const { return Name; } -bool TargetInfo::validateOutputConstraint(const char *Name, - ConstraintInfo &Info) const { +bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const { + const char *Name = Info.getConstraintStr().c_str(); // An output constraint must start with '=' or '+' if (*Name != '=' && *Name != '+') return false; @@ -231,11 +231,12 @@ bool TargetInfo::resolveSymbolicName(const char *&Name, return false; } -bool TargetInfo::validateInputConstraint(const char *Name, - const std::string *OutputNamesBegin, +bool TargetInfo::validateInputConstraint(const std::string *OutputNamesBegin, const std::string *OutputNamesEnd, ConstraintInfo *OutputConstraints, ConstraintInfo &Info) const { + const char *Name = Info.ConstraintStr.c_str(); + while (*Name) { switch (*Name) { default: diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp index 6fc4a08dd5..4d36207b54 100644 --- a/lib/CodeGen/CGStmt.cpp +++ b/lib/CodeGen/CGStmt.cpp @@ -798,9 +798,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) { std::string OutputConstraint(S.getOutputConstraint(i)); - TargetInfo::ConstraintInfo Info; - bool result = Target.validateOutputConstraint(OutputConstraint.c_str(), - Info); + TargetInfo::ConstraintInfo Info(OutputConstraint); + bool result = Target.validateOutputConstraint(Info); assert(result && "Failed to parse output constraint"); result=result; OutputConstraintInfos.push_back(Info); @@ -853,9 +852,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) { std::string InputConstraint(S.getInputConstraint(i)); - TargetInfo::ConstraintInfo Info; - bool result = Target.validateInputConstraint(InputConstraint.c_str(), - S.begin_output_names(), + TargetInfo::ConstraintInfo Info(InputConstraint); + bool result = Target.validateInputConstraint(S.begin_output_names(), S.end_output_names(), &OutputConstraintInfos[0], Info); result=result; diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 62623f37e3..ed5692c311 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -922,15 +922,15 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) << Literal->getSourceRange()); - std::string OutputConstraint(Literal->getStrData(), - Literal->getByteLength()); - - TargetInfo::ConstraintInfo Info; - if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),Info)) + TargetInfo::ConstraintInfo Info(Literal->getStrData(), + Literal->getByteLength()); + if (!Context.Target.validateOutputConstraint(Info)) return StmtError(Diag(Literal->getLocStart(), - diag::err_asm_invalid_output_constraint) << OutputConstraint); + diag::err_asm_invalid_output_constraint) + << Info.getConstraintStr()); // Check that the output exprs are valid lvalues. + // FIXME: Operands to asms should not be parsed as ParenExprs. ParenExpr *OutputExpr = cast(Exprs[i]); if (CheckAsmLValue(OutputExpr, *this)) { return StmtError(Diag(OutputExpr->getSubExpr()->getLocStart(), @@ -947,17 +947,15 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character) << Literal->getSourceRange()); - std::string InputConstraint(Literal->getStrData(), - Literal->getByteLength()); - - TargetInfo::ConstraintInfo Info; - if (!Context.Target.validateInputConstraint(InputConstraint.c_str(), - &Names[0], + TargetInfo::ConstraintInfo Info(Literal->getStrData(), + Literal->getByteLength()); + if (!Context.Target.validateInputConstraint(&Names[0], &Names[0] + NumOutputs, &OutputConstraintInfos[0], Info)) { return StmtError(Diag(Literal->getLocStart(), - diag::err_asm_invalid_input_constraint) << InputConstraint); + diag::err_asm_invalid_input_constraint) + << Info.getConstraintStr()); } ParenExpr *InputExpr = cast(Exprs[i]); @@ -967,14 +965,15 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, if (CheckAsmLValue(InputExpr, *this)) return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(), diag::err_asm_invalid_lvalue_in_input) - << InputConstraint << InputExpr->getSubExpr()->getSourceRange()); + << Info.getConstraintStr() + << InputExpr->getSubExpr()->getSourceRange()); } if (Info.allowsRegister()) { if (InputExpr->getType()->isVoidType()) { return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(), diag::err_asm_invalid_type_in_input) - << InputExpr->getType() << InputConstraint + << InputExpr->getType() << Info.getConstraintStr() << InputExpr->getSubExpr()->getSourceRange()); } }