本文整理汇总了C++中AstInterface类的典型用法代码示例。如果您正苦于以下问题:C++ AstInterface类的具体用法?C++ AstInterface怎么用?C++ AstInterface使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AstInterface类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Traverse
virtual bool Traverse( AstInterface &fa, const AstNodePtr& s,
AstInterface::TraversalVisitType t)
{
HasValueMapReplace valrepl( fa, valmap, false);
if (ValueAnnotation::get_inst()->is_value_restrict_op( fa, s, &append, &valrepl, &astcodegen))
return true;
AstNodePtr lhs, rhs;
AstInterface::AstNodeList vars, args;
HasValueDescriptor desc;
if (fa.IsAssignment(s, &lhs, &rhs)) {
if (append.has_value( rhs, &desc) ) {
append( lhs, desc);
}
}
else if (fa.IsVariableDecl( s, &vars, &args)) {
AstInterface::AstNodeList::iterator pv = vars.begin();
AstInterface::AstNodeList::iterator pa = args.begin();
while (pv != vars.end()) {
lhs = *pv;
rhs = *pa;
if (append.has_value( rhs, &desc) ) {
append( lhs, desc );
}
++pv;
++pa;
}
}
return true;
}
示例2: IsFortranLoop
bool SymbolicValGenerator::
IsFortranLoop(AstInterface& fa, const AstNodePtr& s, SymbolicVar* ivar ,
SymbolicVal* lb , SymbolicVal* ub, SymbolicVal* step, AstNodePtr* body)
{
AstNodePtr ivarast, lbast, ubast, stepast, ivarscope;
if (!fa.IsFortranLoop(s, &ivarast, &lbast, &ubast, &stepast, body))
return false;
std::string varname;
if (! fa.IsVarRef(ivarast, 0, &varname, &ivarscope)) {
return false;
}
if (ivar != 0)
*ivar = SymbolicVar(varname, ivarscope);
if (lb != 0)
*lb = SymbolicValGenerator::GetSymbolicVal(fa,lbast);
if (ub != 0)
*ub = SymbolicValGenerator::GetSymbolicVal(fa,ubast);
if (step != 0) {
if (stepast != AST_NULL)
*step = SymbolicValGenerator::GetSymbolicVal(fa,stepast);
else
*step = SymbolicVal(1);
}
return true;
}
示例3: CodeGen
AstNodePtr SymbolicConst :: CodeGen(AstInterface &fa) const
{
if (type == "int")
return fa.CreateConstInt(intval);
else
return fa.CreateConstant( type, val);
}
示例4: ProcessMod
void PtrAnal::
ProcessMod(AstInterface& fa, const std::string& readname,
std::list<std::string>& fields, const AstNodePtr& mod)
{
std::string modname;
AstNodePtr p = mod;
if (fa.IsVarRef(mod) || fa.IsArrayAccess(mod, &p)) {
modname = Get_VarName(fa,p);
Stmt stmt_last = fields.size()?
field_x_eq_y(modname, fields, readname)
: x_eq_y(modname, readname);
stmts_pushback(stmts,stmt_last);
namemap[mod.get_ptr()] = VarRef(stmt_last,modname);
}
else {
AstInterface::OperatorEnum op;
AstNodePtr p2;
if (fa.IsUnaryOp(mod,&op, &p) && op == AstInterface::UOP_DEREF) {
std::string lhs = Get_VarName(fa,p);
Stmt stmt_last = deref_x_eq_y(lhs, fields, readname);
stmts_pushback(stmts,stmt_last);
namemap[p.get_ptr()] = VarRef(stmt_last,lhs);
namemap[mod.get_ptr()] = VarRef(stmt_last, readname);
}
else if (fa.IsBinaryOp(mod,&op,&p,&p2)) {
if (op==AstInterface::BOP_DOT_ACCESS) {
std::string field = Local_GetFieldName(fa, p2);
fields.push_front(field);
ProcessMod(fa, readname, fields, p);
Stmt stmt_last = stmts_back(stmts);
namemap[mod.get_ptr()] = VarRef(stmt_last, readname);
}
else if (op==AstInterface::BOP_ARROW_ACCESS) {
std::string lhs = Get_VarName(fa, p), field = Local_GetFieldName(fa, p2);
fields.push_front(field);
Stmt stmt_last = deref_x_eq_y(lhs,fields,readname);
stmts_pushback(stmts,stmt_last);
namemap[p.get_ptr()] = VarRef(stmt_last,lhs);
namemap[mod.get_ptr()] = VarRef(stmt_last, readname);
}
else {
std::cerr << "can't handle " << AstToString(mod) << "\n";
assert(false); // other operations? to be handled later
}
}
else if (fa.IsFunctionCall(mod)) {
std::string lhs = Get_VarName(fa, mod);
Stmt stmt_last = deref_x_eq_y(lhs, fields, readname);
stmts_pushback(stmts,stmt_last);
namemap[mod.get_ptr()] = VarRef(stmt_last,lhs);
}
else {
std::cerr << "cannot process " << AstToString(mod) << "\n";
assert(false); // other operations? to be handled later
}
}
}
示例5: CodeGenOP
AstNodePtr SymbolicMultiply::
CodeGenOP( AstInterface &fa, const AstNodePtr& a1, const AstNodePtr& a2) const
{
int val = 0;
if (fa.IsConstInt(a1, &val) && val == -1)
return fa.CreateUnaryOP(AstInterface::UOP_MINUS, a2);
else if (fa.IsConstInt(a2, &val) && val == -1)
return fa.CreateUnaryOP(AstInterface::UOP_MINUS, a1);
return fa.CreateBinaryOP(AstInterface::BOP_TIMES, a1, a2);
}
示例6: operator
bool operator()( AstInterface& fa, const AstNodePtr& head, AstNodePtr& result)
{
#ifdef DEBUG
std::cerr << "LoopTransformationWrap:operator()\n";
#endif
if (!fa.IsStatement(head))
return false;
fa.SetRoot( head);
return LoopTransformation(head, result);
}
示例7: get_modify
bool ArrayUseAccessFunction::get_modify(AstInterface& fa, const AstNodePtr& fc,
CollectObject<AstNodePtr>* collect)
{
AstInterface::AstNodeList args;
if (prev1 != 0 && prev1->get_modify(fa, fc, collect))
return true;
std::string sig;
AstNodePtr f;
if (fa.IsFunctionCall(fc, &f,&args) && fa.IsVarRef(f,0,&sig) && sig == funcname) {
return true;
}
return false;
}
示例8: CreateArrayAccess
AstNodePtr ArrayUseAccessFunction::
CreateArrayAccess( AstInterface& fa, const AstNodePtr& arr,
AstInterface::AstNodeList& index)
{
if (prev != 0)
return prev->CreateArrayAccess(fa, arr, index);
if (index.size() > 1) {
AstInterface::AstNodeList tmp = index;
tmp.push_front(arr);
return fa.CreateFunctionCall(funcname, tmp);
}
else
return fa.CreateArrayAccess(arr, index);
}
示例9: ProcessLoop
bool BuildAstTreeDepGraph::
ProcessLoop( AstInterface &fa, const AstNodePtr& l, const AstNodePtr& body,
AstInterface::TraversalVisitType t)
{
if (t == AstInterface::PreVisit) {
GraphAccessInterface::Node *n = graph->CreateNodeImpl(l, GetStmtDomain(l));
AstNodePtr init,cond,incr;
if (!fa.IsLoop(l, &init, &cond, &incr))
assert(false);
for (StmtStackType::Iterator p(stmtNodes); !p.ReachEnd(); ++p) {
if (init != AST_NULL)
ComputeDataDep(*p, StmtNodeInfo(n,init), DEPTYPE_DATA );
if (cond != AST_NULL)
ComputeDataDep(*p, StmtNodeInfo(n,cond), DEPTYPE_DATA );
if (incr != AST_NULL)
ComputeDataDep(*p, StmtNodeInfo(n,incr), DEPTYPE_DATA );
}
for (StmtStackType::Iterator ps(gotoNodes); !ps.ReachEnd(); ++ps) {
StmtNodeInfo info(n,l);
ComputeCtrlDep((*ps), info);
}
ctrlNodes.PushFirst(StmtNodeInfo(n,l) );
}
else {
ctrlNodes.PopFirst();
}
return ProcessAstTree::ProcessLoop(fa, l, body, t);
}
示例10: AliasAnnotAnal
static bool
AliasAnnotAnal(AstInterface& fa,
OperatorAnnotCollection <OperatorAliasDescriptor>& aliasInfo,
const AstNodePtr& fc, const AstNodePtr& result,
CollectObject< pair<AstNodePtr, int> >& collectalias)
{
AstInterface::AstNodeList args;
OperatorAliasDescriptor desc;
if (!aliasInfo.known_operator( fa, fc, &args, &desc, false) )
return false;
ReplaceParams paramMap( desc.get_param_decl().get_params(), args);
paramMap.add("result", result);
int index = 0;
for (OperatorAliasDescriptor::const_iterator p1 = desc.begin();
p1 != desc.end(); ++p1, ++index) {
const NameGroup& cur = *p1;
for (NameGroup::const_iterator p2 = cur.begin();
p2 != cur.end(); ++p2) {
string varname = *p2;
AstNodePtr arg = paramMap.find(varname).get_ast();
if (arg != AST_NULL) {
collectalias( pair<AstNodePtr, int>(arg, index));
}
else {
AstNodePtr var = fa.CreateVarRef(varname);
collectalias( pair<AstNodePtr, int>(var, index));
}
}
}
return true;
}
示例11: GetArrayBound
bool ArrayUseAccessFunction::
GetArrayBound( AstInterface& fa, const AstNodePtr& array,
int dim, int &lb, int &ub)
{
if (prev != 0)
return prev->GetArrayBound(fa, array, dim, lb, ub);
return fa.GetArrayBound(array, dim, lb, ub);
}
示例12: may_alias
bool PtrAnal::
may_alias(AstInterface& fa, const AstNodePtr& _r1, const AstNodePtr& _r2)
{
AstNodePtr r1 = fa.IsExpression(_r1);
AstNodePtr r2 = fa.IsExpression(_r2);
if (r1 == AST_NULL || r2 == AST_NULL)
assert(false);
std::string varname1 = Get_VarName(fa, r1), varname2 = Get_VarName(fa, r2);
return may_alias(varname1, varname2);
}
示例13: get_read
bool ArrayUseAccessFunction::get_read(AstInterface& fa, const AstNodePtr& fc,
CollectObject<AstNodePtr>* collect)
{
AstInterface::AstNodeList args;
if (prev1 != 0 && prev1->get_read(fa, fc, collect))
return true;
std::string sig;
AstNodePtr f;
if (fa.IsFunctionCall(fc, &f,&args) && fa.IsVarRef(f,0,&sig) && sig == funcname) {
if (collect != 0) {
AstInterface::AstNodeList::const_iterator argp = args.begin();
for ( ++argp; argp != args.end(); ++argp) {
(*collect)(*argp);
}
}
return true;
}
return false;
}
示例14: IsUniqueArray
bool ArrayUseAccessFunction::
IsUniqueArray( AstInterface& fa, const AstNodePtr& array)
{
if (prev != 0 && prev->IsUniqueArray(fa, array))
return true;
AstNodeType t;
if (!fa.IsVarRef(array, &t)) assert(0);
return false;
}
示例15: Local_GetFieldName
static std::string
Local_GetFieldName(AstInterface& fa, const AstNodePtr& field)
{
std::string name;
if (fa.IsVarRef(field, 0, &name)) {
assert(name != "");
return "d:" + name;
}
std::cerr << "Not field name: " << AstToString(field) << "\n";
assert(false);
}