source: icGREP/icgrep-devel/icgrep/pablo/ps_if.cpp @ 4524

Last change on this file since 4524 was 4524, checked in by nmedfort, 5 years ago

Safer use of initializer_list

File size: 1.3 KB
Line 
1#include <pablo/ps_if.h>
2#include <pablo/codegenstate.h>
3#include <pablo/ps_assign.h>
4
5namespace pablo {
6
7If::If(PabloAST * expr, const std::initializer_list<Assign *> definedVars, PabloBlock & body, PabloBlock * parent)
8: Statement(ClassTypeId::If, {expr}, nullptr, parent)
9, mBody(body)
10, mDefined(definedVars.begin(), definedVars.end(), mVectorAllocator)
11, mCarryCount(0)
12, mAdvanceCount(0)
13{
14    // Conceptually, having a defined var X is identical to having:
15    //
16    // Assign(X, 0)
17    // If (...)
18    //    Next(Assign(X), ...)
19    //
20    // Since the implied 'Next' node is a user of the Assign node, and the Assign node is
21    // embedded into the If, the defined var is a user of the If node. However, since the
22    // Assign's value is also dependant on the 'Next' value, the If node is also a user
23    // of it.
24
25    for (PabloAST * assign : mDefined) {
26        assign->addUser(this);
27        addUser(assign);
28    }
29}
30
31If::If(PabloAST * expr, const std::vector<Assign *> & definedVars, PabloBlock & body, PabloBlock * parent)
32: Statement(ClassTypeId::If, {expr}, nullptr, parent)
33, mBody(body)
34, mDefined(definedVars.begin(), definedVars.end(), mVectorAllocator)
35, mCarryCount(0)
36, mAdvanceCount(0)
37{
38    for (PabloAST * assign : mDefined) {
39        assign->addUser(this);
40        addUser(assign);
41    }
42}
43
44
45}
Note: See TracBrowser for help on using the repository browser.