本文整理汇总了C++中AstVar类的典型用法代码示例。如果您正苦于以下问题:C++ AstVar类的具体用法?C++ AstVar怎么用?C++ AstVar使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AstVar类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: visit
virtual void visit(AstRepeat* nodep, AstNUser*) {
// So later optimizations don't need to deal with them,
// REPEAT(count,body) -> loop=count,WHILE(loop>0) { body, loop-- }
// Note var can be signed or unsigned based on original number.
AstNode* countp = nodep->countp()->unlinkFrBackWithNext();
string name = string("__Vrepeat")+cvtToStr(m_repeatNum++);
// Spec says value is integral, if negative is ignored
AstVar* varp = new AstVar(nodep->fileline(), AstVarType::BLOCKTEMP, name,
nodep->findSigned32DType());
varp->usedLoopIdx(true);
m_modp->addStmtp(varp);
AstNode* initsp = new AstAssign(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, true),
countp);
AstNode* decp = new AstAssign(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, true),
new AstSub(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
new AstConst(nodep->fileline(), 1)));
V3Number zero (nodep->fileline(), 32, 0); zero.isSigned(true);
AstNode* zerosp = new AstConst(nodep->fileline(), zero);
AstNode* condp = new AstGtS(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
zerosp);
AstNode* bodysp = nodep->bodysp(); if (bodysp) bodysp->unlinkFrBackWithNext();
AstNode* newp = new AstWhile(nodep->fileline(),
condp,
bodysp,
decp);
initsp = initsp->addNext(newp);
newp = initsp;
nodep->replaceWith(newp);
nodep->deleteTree(); VL_DANGLING(nodep);
}
示例2: varIt
void AstPrinterVisitor::visitBlockNode(BlockNode* node) {
if (!isMainScope(node->scope())) {
_output << "{" << endl;
}
Scope::VarIterator varIt(node->scope());
while(varIt.hasNext()) {
AstVar* var = varIt.next();
printVarType(var->type());
_output << " " << var->name();
printSemicolon();
}
Scope::FunctionIterator funcIt(node->scope());
while(funcIt.hasNext()) {
FunctionNode* func = funcIt.next()->node();
func->visit(this);
}
for (uint32_t i = 0; i < node->nodes(); ++i) {
node->nodeAt(i)->visit(this);
if (!(node->nodeAt(i)->isIfNode()
|| node->nodeAt(i)->isWhileNode()
|| node->nodeAt(i)->isForNode()
|| node->nodeAt(i)->isReturnNode()
|| node->nodeAt(i)->isBlockNode())) {
printSemicolon();
}
}
if (!isMainScope(node->scope())) {
_output << "}" << endl;
}
}
示例3: visit
virtual void visit(AstVarScope* nodep, AstNUser*) {
nodep->iterateChildren(*this);
// Avoid updating this if (), instead see varp->isTrace()
if (!nodep->varp()->isTemp() && !nodep->varp()->isFuncLocal()) {
UINFO(5, " vsc "<<nodep<<endl);
AstVar* varp = nodep->varp();
AstScope* scopep = nodep->scopep();
// Compute show name
// This code assumes SPTRACEVCDC_VERSION >= 1330;
// it uses spaces to separate hierarchy components.
m_traShowname = AstNode::vcdName(scopep->name() + " " + varp->name());
if (m_traShowname.substr(0,4) == "TOP ") m_traShowname.replace(0,4,"");
if (!m_initSubFuncp) nodep->v3fatalSrc("NULL");
m_traVscp = nodep;
m_traValuep = NULL;
if (varIgnoreTrace(varp)) {
addIgnore(varIgnoreTrace(varp));
} else {
++m_statSigs;
if (nodep->valuep()) m_traValuep = nodep->valuep()->cloneTree(true);
else m_traValuep = new AstVarRef(nodep->fileline(), nodep, false);
{
// Recurse into data type of the signal; the visitors will call addTraceDecl()
varp->dtypeSkipRefp()->accept(*this);
}
// Cleanup
if (m_traValuep) { m_traValuep->deleteTree(); m_traValuep=NULL; }
}
m_traVscp = NULL;
m_traValuep = NULL;
m_traShowname = "";
}
}
示例4: createVarSc
AstVarScope* createVarSc(AstVarScope* oldvarscp, string name, int width/*0==fromoldvar*/) {
// Because we've already scoped it, we may need to add both the AstVar and the AstVarScope
if (!oldvarscp->scopep()) oldvarscp->v3fatalSrc("Var unscoped");
AstVar* varp;
AstNodeModule* addmodp = oldvarscp->scopep()->modp();
// We need a new AstVar, but only one for all scopes, to match the new AstVarScope
VarMap::iterator iter = m_modVarMap.find(make_pair(addmodp,name));
if (iter != m_modVarMap.end()) {
// Created module's AstVar earlier under some other scope
varp = iter->second;
} else {
if (width==0) {
varp = new AstVar (oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, oldvarscp->varp());
varp->widthSignedFrom(oldvarscp);
} else { // Used for vset and dimensions, so can zero init
varp = new AstVar (oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, AstBitPacked(), width);
}
addmodp->addStmtp(varp);
m_modVarMap.insert(make_pair(make_pair(addmodp, name), varp));
}
AstVarScope* varscp = new AstVarScope (oldvarscp->fileline(), oldvarscp->scopep(), varp);
oldvarscp->scopep()->addVarp(varscp);
return varscp;
}
示例5: error
void ByteCodeVisitor::visitFunctionNode(mathvm::FunctionNode *node) {
BytecodeFunction *dump = currentBytecodeFunction;
if (currScope) {
AstFunction *function = currScope->lookupFunction(node->name());
if (!function) {
error("undeclared function %s", node->name().c_str());
}
AstFunctionInfo *astFunctionInfo = (AstFunctionInfo *) function->info();
currentBytecodeFunction = astFunctionInfo->function;
} else {
currentBytecodeFunction = dynamic_cast<BytecodeFunction *>(interpreterCode->functionById((uint16_t) 0));
}
std::vector<VarType> newStack;
currStack = &newStack;
Scope::VarIterator varIterator(node->body()->scope()->parent());
while (varIterator.hasNext()) {
AstVar *var = varIterator.next();
pushStack(var->type());//ensure that variables on stack is ok
store(var);
}
visitBlockNode(node->body());
currentBytecodeFunction = dump;
currScope = currScope->parent();//jump parameters scope
}
示例6: visitFunctionNode
void ASTtoByteCodeTranslator::visitFunctionNode(FunctionNode* node) {
uint16_t varId = 0;
for(size_t i = 0; i < node->parametersNumber(); ++i) {
AstVar *var = node->body()->scope()->lookupVariable(node->parameterName(node->parametersNumber() - i - 1));
varMap[var] = varId;
Bytecode *bytecode = funStack.top()->bytecode();
switch (var->type()) {
case VT_INT:
bytecode->addInsn(BC_STOREIVAR);
break;
case VT_DOUBLE:
bytecode->addInsn(BC_STOREDVAR);
break;
case VT_STRING:
bytecode->addInsn(BC_STORESVAR);
break;
default:
bytecode->addInsn(BC_INVALID);
break;
}
bytecode->addUInt16(varId++);
}
node->body()->visit(this);
}
示例7: insertImplicit
AstArraySel* insertImplicit(AstNode* nodep, unsigned start, unsigned count) {
// Insert any implicit slices as explicit slices (ArraySel nodes).
// Return a new pointer to replace nodep() in the ArraySel.
UINFO(9," insertImplicit (start="<<start<<",c="<<count<<") "<<nodep<<endl);
AstVarRef* refp = nodep->user1p()->castNode()->castVarRef();
if (!refp) nodep->v3fatalSrc("No VarRef in user1 of node "<<nodep);
AstVar* varp = refp->varp();
AstNode* topp = nodep;
for (unsigned i = start; i < start + count; ++i) {
AstNodeDType* dtypep = varp->dtypep()->dtypeDimensionp(i-1);
AstUnpackArrayDType* adtypep = dtypep->castUnpackArrayDType();
if (!adtypep) nodep->v3fatalSrc("insertImplicit tried to expand an array without an ArrayDType");
vlsint32_t msb = adtypep->msb();
vlsint32_t lsb = adtypep->lsb();
if (lsb > msb) {
// Below code assumes big bit endian; just works out if we swap
int x = msb; msb = lsb; lsb = x;
}
UINFO(9," ArraySel-child: "<<topp<<endl);
AstArraySel* newp = new AstArraySel(nodep->fileline(), topp,
// "lsb-lsb": Arrays are zero-based so index 0 is always lsb
new AstConst(nodep->fileline(), lsb-lsb));
if (!newp->dtypep()) {
newp->v3fatalSrc("ArraySel dtyping failed when resolving slice"); // see ArraySel constructor
}
newp->user1p(refp);
newp->start(lsb);
newp->length(msb - lsb + 1);
topp = newp;
}
return topp->castArraySel();
}
示例8: funIt
void Printer::printBlockContents(BlockNode* node) {
// functions delcarations
Scope::FunctionIterator funIt(node->scope());
while (funIt.hasNext()) {
funIt.next()->node()->visit(this);
out << '\n';
}
// variables declarations
Scope::VarIterator varIt(node->scope());
while (varIt.hasNext()) {
AstVar* var = varIt.next();
out << typeToName(var->type())
<< " " << var->name() << ";\n";
}
// nodes
for (size_t i = 0; i < node->nodes(); ++i) {
AstNode* subNode = node->nodeAt(i);
subNode->visit(this);
if (!subNode->isIfNode() &&
!subNode->isWhileNode() &&
!subNode->isForNode()) {
out << ';';
}
out << '\n';
}
}
示例9: printVars
void printVars(Scope *scope)
{
Scope::VarIterator iter(scope);
while (iter.hasNext()) {
AstVar *astVar = iter.next();
out << typeToName(astVar->type()) << " " << astVar->name() << ";" << endl;
}
}
示例10: vit
void TypeInferenceVisitor::processFunction(AstFunction* function) {
Scope* scope = function->scope();
Scope::VarIterator vit(scope);
while(vit.hasNext()) {
AstVar* var = vit.next();
_types[var] = var->type();
}
function->node()->visit(this);
}
示例11: variableDeclaration
void variableDeclaration(Scope* scope) {
Scope::VarIterator iter(scope);
while (iter.hasNext()) {
AstVar* x = iter.next();
indent();
_output << typeToName(x->type()) << " "
<< x->name() << ";"
<< endl;
}
}
示例12: createEnableVar
AstVar* createEnableVar(AstNode* outp, AstVarRef* outrefp, AstNode* enrhsp, int width, string suffix="") {
// this function creates an __en Var that corresponds to
// the outp and outrefp and creates an assignw to enrhsp
AstVar* enp = new AstVar (outrefp->varp()->fileline(),
AstVarType::MODULETEMP,
outrefp->name() + "__en" + suffix + cvtToStr(m_unique++),
AstLogicPacked(), width);
enp->varType2Out();
if (enp->width() != enrhsp->width()) {
if (enrhsp->width1()) { // it seems from my futzing that the linter guarantees this condition
enrhsp = new AstReplicate(enrhsp->fileline(), enrhsp,
new AstConst(enrhsp->fileline(), V3Number(enrhsp->fileline(), 32, enp->width())));
enrhsp->width(enp->width(), enp->width()); //minwidth==width
} else {
enrhsp->v3error("Don't know how to deal with selection logic wider than 1 bit");
}
}
AstNode* newassp = new AstAssignW (enp->fileline(),
new AstVarRef (enp->fileline(), enp, true),
enrhsp);
if (debug()>=9) enp->dumpTreeAndNext(cout,"- cev-out: ");
if (debug()>=9) newassp->dumpTreeAndNext(cout,"- cev-out: ");
m_modp->addStmtp(enp);
m_modp->addStmtp(newassp);
outrefp->user1p(enp); // put __en signal into varref for later usage
outrefp->varp()->user1p(enp); // put __en signal into var as well in the event this is a single lhs driver and this needs passed up one level
return enp;
}
示例13: visit
virtual void visit(AstPin* nodep, AstNUser*) {
// Check to see if any output pins have __en pins and create the __en pins to match
AstVarRef* refp = findVarRef(nodep);
if (refp && refp->lvalue() && nodep->modVarp()->user1p()) {
AstVar* enchildp = (AstVar*)nodep->modVarp()->user1p();
UINFO(9, " Pulling __en var" << enchildp << endl);
AstVar* enp = new AstVar(enchildp->fileline(),
AstVarType::OUTPUT,
enchildp->name()+cvtToStr(m_unique++),
enchildp);
enp->user2(enchildp->user2());
m_modp->addStmtp(enp);
AstPin* pinp = new AstPin(nodep->fileline(),
nodep->pinNum(),
enp->name(),
new AstVarRef(nodep->fileline(), enp, true));
AstVarRef *rp = findVarRef(pinp);
rp->replaceWith(new AstVarRef(nodep->fileline(), enp, true));
rp->deleteTree(); rp=NULL;
pinp->width(enp->width(),enp->width()); // minwidth==width
pinp->modVarp(enchildp);
m_cellp->addPinsp(pinp);
refp->user1p(enp);
refp->varp()->user1p(enp);
}
// Simplify interconnect in preperation for V3Inst
// (This could be a separate visitor, but we're in the neighborhood)
V3Inst::pinReconnectSimple(nodep, m_cellp, m_modp);
}
示例14: fuctions
void ASTAnalyzer::printScopeDeclarations (Scope* scope) {
Scope::FunctionIterator fuctions(scope);
while (fuctions.hasNext()) {
fuctions.next()->node()->visit(this);
}
Scope::VarIterator vars(scope);
while (vars.hasNext()) {
AstVar* var = vars.next();
output << typeToName(var->type()) << " " << var->name() << ";\n";
}
}
示例15: m_scope
ScopeHandler::ScopeHandler(uint16_t iniLocalId, Scope *scope, ScopeHandler *parent)
: m_scope(scope)
, m_parent(parent)
{
Scope::VarIterator it = Scope::VarIterator(m_scope);
while(it.hasNext()) {
AstVar *var = it.next();
m_varNameToId[var->name()] = iniLocalId;
iniLocalId++;
}
}