pull the constraint string into the ConstraintInfo struct

instead of passing it around in addition to it.

llvm-svn: 70135
This commit is contained in:
Chris Lattner 2009-04-26 17:19:08 +00:00
parent 8d319047c5
commit c3f4c7b1c5
5 changed files with 33 additions and 34 deletions

View File

@ -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 = "<group>"; };
35707EFD0CD0F5CC000B2204 /* SourceLocation.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = SourceLocation.cpp; sourceTree = "<group>"; tabWidth = 2; };
357EA27C0F2526F300439B60 /* SemaLookup.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = SemaLookup.cpp; path = lib/Sema/SemaLookup.cpp; sourceTree = "<group>"; tabWidth = 2; };
3580CC0B0D072E5C00C5E4F4 /* LangOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; path = LangOptions.cpp; sourceTree = "<group>"; tabWidth = 2; };
35847BE30CC7DB9000C40FFF /* StmtIterator.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.c.h; name = StmtIterator.h; path = clang/AST/StmtIterator.h; sourceTree = "<group>"; tabWidth = 2; };
35847BE40CC7DBAF00C40FFF /* StmtIterator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 2; lastKnownFileType = sourcecode.cpp.cpp; name = StmtIterator.cpp; path = lib/AST/StmtIterator.cpp; sourceTree = "<group>"; tabWidth = 2; };
35862B0C0E3628CB0009F542 /* CheckDeadStores.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckDeadStores.cpp; path = lib/Analysis/CheckDeadStores.cpp; sourceTree = "<group>"; };
@ -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 */,

View File

@ -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;

View File

@ -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:

View File

@ -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;

View File

@ -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<ParenExpr>(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<ParenExpr>(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());
}
}