Convert asm statement action to smart pointers.

llvm-svn: 62464
This commit is contained in:
Sebastian Redl 2009-01-18 16:53:17 +00:00
parent 573feed2a8
commit 24b8e15dfa
5 changed files with 103 additions and 111 deletions

View File

@ -365,22 +365,21 @@ namespace {
llvm::cout << __FUNCTION__ << "\n"; llvm::cout << __FUNCTION__ << "\n";
return StmtEmpty(); return StmtEmpty();
} }
virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
bool IsSimple, bool IsSimple,
bool IsVolatile, bool IsVolatile,
unsigned NumOutputs, unsigned NumOutputs,
unsigned NumInputs, unsigned NumInputs,
std::string *Names, std::string *Names,
ExprTy **Constraints, MultiExprArg Constraints,
ExprTy **Exprs, MultiExprArg Exprs,
ExprTy *AsmString, ExprArg AsmString,
unsigned NumClobbers, MultiExprArg Clobbers,
ExprTy **Clobbers, SourceLocation RParenLoc) {
SourceLocation RParenLoc) {
llvm::cout << __FUNCTION__ << "\n"; llvm::cout << __FUNCTION__ << "\n";
return 0; return StmtEmpty();
} }
// Objective-c statements // Objective-c statements
virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
SourceLocation RParen, StmtTy *Parm, SourceLocation RParen, StmtTy *Parm,

View File

@ -459,21 +459,20 @@ public:
ExprArg RetValExp) { ExprArg RetValExp) {
return StmtEmpty(); return StmtEmpty();
} }
virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
bool IsSimple, bool IsSimple,
bool IsVolatile, bool IsVolatile,
unsigned NumOutputs, unsigned NumOutputs,
unsigned NumInputs, unsigned NumInputs,
std::string *Names, std::string *Names,
ExprTy **Constraints, MultiExprArg Constraints,
ExprTy **Exprs, MultiExprArg Exprs,
ExprTy *AsmString, ExprArg AsmString,
unsigned NumClobbers, MultiExprArg Clobbers,
ExprTy **Clobbers, SourceLocation RParenLoc) {
SourceLocation RParenLoc) { return StmtEmpty();
return 0;
} }
// Objective-c statements // Objective-c statements
virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
SourceLocation RParen, StmtTy *Parm, SourceLocation RParen, StmtTy *Parm,

View File

@ -1155,12 +1155,11 @@ Parser::OwningStmtResult Parser::ParseAsmStatement(bool &msAsm) {
RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc); RParenLoc = MatchRHSPunctuation(tok::r_paren, Loc);
} }
return Owned(Actions.ActOnAsmStmt(AsmLoc, isSimple, isVolatile, return Actions.ActOnAsmStmt(AsmLoc, isSimple, isVolatile,
NumOutputs, NumInputs, NumOutputs, NumInputs, &Names[0],
&Names[0], Constraints.take(), move_convert(Constraints), move_convert(Exprs),
Exprs.take(), AsmString.release(), move_convert(AsmString), move_convert(Clobbers),
Clobbers.size(), Clobbers.take(), RParenLoc);
RParenLoc));
} }
/// ParseAsmOperands - Parse the asm-operands production as used by /// ParseAsmOperands - Parse the asm-operands production as used by

View File

@ -901,18 +901,17 @@ public:
OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc, OwningStmtResult ActOnBlockReturnStmt(SourceLocation ReturnLoc,
Expr *RetValExp); Expr *RetValExp);
virtual StmtResult ActOnAsmStmt(SourceLocation AsmLoc, virtual OwningStmtResult ActOnAsmStmt(SourceLocation AsmLoc,
bool IsSimple, bool IsSimple,
bool IsVolatile, bool IsVolatile,
unsigned NumOutputs, unsigned NumOutputs,
unsigned NumInputs, unsigned NumInputs,
std::string *Names, std::string *Names,
ExprTy **Constraints, MultiExprArg Constraints,
ExprTy **Exprs, MultiExprArg Exprs,
ExprTy *AsmString, ExprArg AsmString,
unsigned NumClobbers, MultiExprArg Clobbers,
ExprTy **Clobbers, SourceLocation RParenLoc);
SourceLocation RParenLoc);
virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc, virtual StmtResult ActOnObjCAtCatchStmt(SourceLocation AtLoc,
SourceLocation RParen, StmtTy *Parm, SourceLocation RParen, StmtTy *Parm,

View File

@ -831,112 +831,108 @@ Sema::ActOnReturnStmt(SourceLocation ReturnLoc, ExprArg rex) {
return Owned(new ReturnStmt(ReturnLoc, RetValExp)); return Owned(new ReturnStmt(ReturnLoc, RetValExp));
} }
Sema::StmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc, Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
bool IsSimple, bool IsSimple,
bool IsVolatile, bool IsVolatile,
unsigned NumOutputs, unsigned NumOutputs,
unsigned NumInputs, unsigned NumInputs,
std::string *Names, std::string *Names,
ExprTy **constraints, MultiExprArg constraints,
ExprTy **exprs, MultiExprArg exprs,
ExprTy *asmString, ExprArg asmString,
unsigned NumClobbers, MultiExprArg clobbers,
ExprTy **clobbers, SourceLocation RParenLoc) {
SourceLocation RParenLoc) { unsigned NumClobbers = clobbers.size();
StringLiteral **Constraints = reinterpret_cast<StringLiteral**>(constraints); StringLiteral **Constraints =
Expr **Exprs = reinterpret_cast<Expr **>(exprs); reinterpret_cast<StringLiteral**>(constraints.get());
StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString); Expr **Exprs = reinterpret_cast<Expr **>(exprs.get());
StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers); StringLiteral *AsmString = cast<StringLiteral>((Expr *)asmString.get());
StringLiteral **Clobbers = reinterpret_cast<StringLiteral**>(clobbers.get());
// The parser verifies that there is a string literal here. // The parser verifies that there is a string literal here.
if (AsmString->isWide()) if (AsmString->isWide())
// FIXME: We currently leak memory here. return StmtError(Diag(AsmString->getLocStart(),diag::err_asm_wide_character)
return Diag(AsmString->getLocStart(), diag::err_asm_wide_character) << AsmString->getSourceRange());
<< AsmString->getSourceRange();
for (unsigned i = 0; i != NumOutputs; i++) { for (unsigned i = 0; i != NumOutputs; i++) {
StringLiteral *Literal = Constraints[i]; StringLiteral *Literal = Constraints[i];
if (Literal->isWide()) if (Literal->isWide())
// FIXME: We currently leak memory here. return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
return Diag(Literal->getLocStart(), diag::err_asm_wide_character) << Literal->getSourceRange());
<< Literal->getSourceRange();
std::string OutputConstraint(Literal->getStrData(), std::string OutputConstraint(Literal->getStrData(),
Literal->getByteLength()); Literal->getByteLength());
TargetInfo::ConstraintInfo info; TargetInfo::ConstraintInfo info;
if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info)) if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info))
// FIXME: We currently leak memory here. return StmtError(Diag(Literal->getLocStart(),
return Diag(Literal->getLocStart(), diag::err_asm_invalid_output_constraint) << OutputConstraint);
diag::err_asm_invalid_output_constraint) << OutputConstraint;
// Check that the output exprs are valid lvalues. // Check that the output exprs are valid lvalues.
ParenExpr *OutputExpr = cast<ParenExpr>(Exprs[i]); ParenExpr *OutputExpr = cast<ParenExpr>(Exprs[i]);
Expr::isLvalueResult Result = OutputExpr->isLvalue(Context); Expr::isLvalueResult Result = OutputExpr->isLvalue(Context);
if (Result != Expr::LV_Valid) { if (Result != Expr::LV_Valid) {
// FIXME: We currently leak memory here. return StmtError(Diag(OutputExpr->getSubExpr()->getLocStart(),
return Diag(OutputExpr->getSubExpr()->getLocStart(),
diag::err_asm_invalid_lvalue_in_output) diag::err_asm_invalid_lvalue_in_output)
<< OutputExpr->getSubExpr()->getSourceRange(); << OutputExpr->getSubExpr()->getSourceRange());
} }
} }
for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) { for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
StringLiteral *Literal = Constraints[i]; StringLiteral *Literal = Constraints[i];
if (Literal->isWide()) if (Literal->isWide())
// FIXME: We currently leak memory here. return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
return Diag(Literal->getLocStart(), diag::err_asm_wide_character) << Literal->getSourceRange());
<< Literal->getSourceRange();
std::string InputConstraint(Literal->getStrData(),
std::string InputConstraint(Literal->getStrData(),
Literal->getByteLength()); Literal->getByteLength());
TargetInfo::ConstraintInfo info; TargetInfo::ConstraintInfo info;
if (!Context.Target.validateInputConstraint(InputConstraint.c_str(), if (!Context.Target.validateInputConstraint(InputConstraint.c_str(),
&Names[0], &Names[0],
&Names[0] + NumOutputs, info)) { &Names[0] + NumOutputs, info)) {
// FIXME: We currently leak memory here. return StmtError(Diag(Literal->getLocStart(),
return Diag(Literal->getLocStart(), diag::err_asm_invalid_input_constraint) << InputConstraint);
diag::err_asm_invalid_input_constraint) << InputConstraint;
} }
// Check that the input exprs aren't of type void. // Check that the input exprs aren't of type void.
ParenExpr *InputExpr = cast<ParenExpr>(Exprs[i]); ParenExpr *InputExpr = cast<ParenExpr>(Exprs[i]);
if (InputExpr->getType()->isVoidType()) { if (InputExpr->getType()->isVoidType()) {
// FIXME: We currently leak memory here. return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
return Diag(InputExpr->getSubExpr()->getLocStart(),
diag::err_asm_invalid_type_in_input) diag::err_asm_invalid_type_in_input)
<< InputExpr->getType() << InputConstraint << InputExpr->getType() << InputConstraint
<< InputExpr->getSubExpr()->getSourceRange(); << InputExpr->getSubExpr()->getSourceRange());
} }
if (info & TargetInfo::CI_AllowsRegister) if (info & TargetInfo::CI_AllowsRegister)
DefaultFunctionArrayConversion(Exprs[i]); DefaultFunctionArrayConversion(Exprs[i]);
} }
// Check that the clobbers are valid. // Check that the clobbers are valid.
for (unsigned i = 0; i != NumClobbers; i++) { for (unsigned i = 0; i != NumClobbers; i++) {
StringLiteral *Literal = Clobbers[i]; StringLiteral *Literal = Clobbers[i];
if (Literal->isWide()) if (Literal->isWide())
// FIXME: We currently leak memory here. return StmtError(Diag(Literal->getLocStart(),diag::err_asm_wide_character)
return Diag(Literal->getLocStart(), diag::err_asm_wide_character) << Literal->getSourceRange());
<< Literal->getSourceRange();
llvm::SmallString<16> Clobber(Literal->getStrData(),
llvm::SmallString<16> Clobber(Literal->getStrData(), Literal->getStrData() +
Literal->getStrData() +
Literal->getByteLength()); Literal->getByteLength());
if (!Context.Target.isValidGCCRegisterName(Clobber.c_str())) if (!Context.Target.isValidGCCRegisterName(Clobber.c_str()))
// FIXME: We currently leak memory here. return StmtError(Diag(Literal->getLocStart(),
return Diag(Literal->getLocStart(), diag::err_asm_unknown_register_name) << Clobber.c_str());
diag::err_asm_unknown_register_name) << Clobber.c_str();
} }
return new AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs, constraints.release();
Names, Constraints, Exprs, AsmString, NumClobbers, exprs.release();
Clobbers, RParenLoc); asmString.release();
clobbers.release();
return Owned(new AsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, NumInputs,
Names, Constraints, Exprs, AsmString, NumClobbers,
Clobbers, RParenLoc));
} }
Action::StmtResult Action::StmtResult