ONE - On-device Neural Engine
Loading...
Searching...
No Matches
nnc::ArtifactBlock Class Reference

Represents a block of instructions. More...

#include <ArtifactModel.h>

Collaboration diagram for nnc::ArtifactBlock:

Public Member Functions

bool isBlock () const override
 If this entity represents something containing a block of instructions.
 
void accept (IArtifactGenerator *g) const override
 This is the core function of each artifact entity and is implemented by all concrete classes in the hierarchy.
 
void addStatement (const std::shared_ptr< ArtifactEntity > &statement)
 
const std::list< std::shared_ptr< ArtifactEntity > > & getStatements () const
 
std::shared_ptr< ArtifactVariablevar (const std::string &type_name, const std::string &var_name, const std::list< std::shared_ptr< ArtifactExpr > > &dimensions={}, const std::list< std::shared_ptr< ArtifactExpr > > &initializers={})
 Creates a new variable and place it to the block.
 
std::shared_ptr< ArtifactFunctionCallcall (const std::string &func_name, const std::list< std::shared_ptr< ArtifactExpr > > &param_list, std::shared_ptr< ArtifactExpr > call_on=nullptr, ArtifactCallType call_type=ArtifactCallType::obj)
 Creates a function call.
 
std::shared_ptr< ArtifactRetret (std::shared_ptr< ArtifactExpr > expr)
 Creates a return from function statement.
 
std::shared_ptr< ArtifactBreakbrk ()
 Creates a break from a loop instruction.
 
std::shared_ptr< ArtifactContcont ()
 Creates a continue in a loop instruction.
 
std::shared_ptr< ArtifactForLoopforLoop (std::shared_ptr< ArtifactVariable > init=nullptr, std::shared_ptr< ArtifactExpr > cond=nullptr, std::shared_ptr< ArtifactExpr > iter=nullptr)
 Creates a for loop instruction.
 
std::shared_ptr< ArtifactIfifCond (std::shared_ptr< ArtifactExpr > cond)
 Creates an 'if' blocks.
 
std::shared_ptr< ArtifactUnaryExprun (ArtifactUnOp op, std::shared_ptr< ArtifactExpr > expr)
 Creates an unary operation expression.
 
std::shared_ptr< ArtifactBinaryExprbin (ArtifactBinOp op, std::shared_ptr< ArtifactExpr > left, std::shared_ptr< ArtifactExpr > right)
 Creates a binary operation expression.
 
std::shared_ptr< ArtifactUnaryExprheapNew (std::shared_ptr< ArtifactExpr > expr)
 Creates a heap new operation expression.
 
std::shared_ptr< ArtifactUnaryExprheapFree (std::shared_ptr< ArtifactExpr > expr)
 Creates a heap free operation expression.
 
- Public Member Functions inherited from nnc::ArtifactEntity
virtual ~ArtifactEntity ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from nnc::ArtifactEntity
 ArtifactEntity ()=default
 

Detailed Description

Represents a block of instructions.

Definition at line 352 of file ArtifactModel.h.

Member Function Documentation

◆ accept()

void nnc::ArtifactBlock::accept ( IArtifactGenerator g) const
inlineoverridevirtual

This is the core function of each artifact entity and is implemented by all concrete classes in the hierarchy.

Implements nnc::ArtifactEntity.

Definition at line 357 of file ArtifactModel.h.

357{ g->visit(this); }

Referenced by TEST(), nnc::ArtifactGeneratorCppCode::visit(), nnc::ArtifactGeneratorCppCode::visit(), nnc::ArtifactGeneratorCppCode::visit(), and nnc::ArtifactGeneratorCppCode::visit().

◆ addStatement()

void nnc::ArtifactBlock::addStatement ( const std::shared_ptr< ArtifactEntity > &  statement)
inline

Definition at line 359 of file ArtifactModel.h.

360 {
361 _statements.push_back(statement);
362 }

Referenced by TEST(), TEST(), and TEST().

◆ bin()

shared_ptr< ArtifactBinaryExpr > nnc::ArtifactBlock::bin ( ArtifactBinOp  op,
std::shared_ptr< ArtifactExpr left,
std::shared_ptr< ArtifactExpr right 
)

Creates a binary operation expression.

Parameters
op
left
right
Returns

Definition at line 97 of file ArtifactModel.cpp.

99{
100 auto bin = make_shared<ArtifactBinaryExpr>(op, left, right);
101 _statements.push_back(bin);
102 return bin;
103}
std::shared_ptr< ArtifactBinaryExpr > bin(ArtifactBinOp op, std::shared_ptr< ArtifactExpr > left, std::shared_ptr< ArtifactExpr > right)
Creates a binary operation expression.

References bin().

Referenced by bin().

◆ brk()

shared_ptr< ArtifactBreak > nnc::ArtifactBlock::brk ( )

Creates a break from a loop instruction.

Returns

Definition at line 60 of file ArtifactModel.cpp.

61{
62 auto brk = make_shared<ArtifactBreak>();
63 _statements.push_back(brk);
64 return brk;
65}
std::shared_ptr< ArtifactBreak > brk()
Creates a break from a loop instruction.

References brk().

Referenced by brk().

◆ call()

shared_ptr< ArtifactFunctionCall > nnc::ArtifactBlock::call ( const std::string &  func_name,
const std::list< std::shared_ptr< ArtifactExpr > > &  param_list,
std::shared_ptr< ArtifactExpr call_on = nullptr,
ArtifactCallType  call_type = ArtifactCallType::obj 
)

Creates a function call.

Parameters
func_name- the function name.
param_list- the parameters which are used for the call.
call_on- optional object on which the function is called (if it is a member function).
call_type- (for member functions only) call through: '.', '->', or '::'.
Returns

Definition at line 45 of file ArtifactModel.cpp.

47{
48 auto func_call = make_shared<ArtifactFunctionCall>(func_name, param_list, call_on, call_type);
49 _statements.push_back(func_call);
50 return func_call;
51}

Referenced by nnc::AclCppOpGenerator::generate(), and nnc::AclCppOpGenerator::visit().

◆ cont()

shared_ptr< ArtifactCont > nnc::ArtifactBlock::cont ( )

Creates a continue in a loop instruction.

Returns

Definition at line 67 of file ArtifactModel.cpp.

68{
69 auto cont = make_shared<ArtifactCont>();
70 _statements.push_back(cont);
71 return cont;
72}
std::shared_ptr< ArtifactCont > cont()
Creates a continue in a loop instruction.

References cont().

Referenced by cont().

◆ forLoop()

shared_ptr< ArtifactForLoop > nnc::ArtifactBlock::forLoop ( std::shared_ptr< ArtifactVariable init = nullptr,
std::shared_ptr< ArtifactExpr cond = nullptr,
std::shared_ptr< ArtifactExpr iter = nullptr 
)

Creates a for loop instruction.

Parameters
init- initialize for loop.
cond- condition to check for stay looping.
iter- change when transiting to the next iteration.
Returns

Definition at line 74 of file ArtifactModel.cpp.

77{
78 auto loop = make_shared<ArtifactForLoop>(init, cond, iter);
79 _statements.push_back(loop);
80 return loop;
81}

◆ getStatements()

const std::list< std::shared_ptr< ArtifactEntity > > & nnc::ArtifactBlock::getStatements ( ) const
inline

Definition at line 364 of file ArtifactModel.h.

364{ return _statements; }

Referenced by nnc::ArtifactGeneratorCppCode::visit(), and nnc::ArtifactGeneratorCppCode::visit().

◆ heapFree()

shared_ptr< ArtifactUnaryExpr > nnc::ArtifactBlock::heapFree ( std::shared_ptr< ArtifactExpr expr)

Creates a heap free operation expression.

Parameters
expr
Returns

Definition at line 112 of file ArtifactModel.cpp.

113{
114 auto heap_del = make_shared<ArtifactUnaryExpr>(ArtifactUnOp::heapFree, expr);
115 _statements.push_back(heap_del);
116 return heap_del;
117}

References nnc::heapFree.

◆ heapNew()

shared_ptr< ArtifactUnaryExpr > nnc::ArtifactBlock::heapNew ( std::shared_ptr< ArtifactExpr expr)

Creates a heap new operation expression.

Parameters
expr
Returns

Definition at line 105 of file ArtifactModel.cpp.

106{
107 auto heap_new = make_shared<ArtifactUnaryExpr>(ArtifactUnOp::heapNew, expr);
108 _statements.push_back(heap_new);
109 return heap_new;
110}

References nnc::heapNew.

◆ ifCond()

shared_ptr< ArtifactIf > nnc::ArtifactBlock::ifCond ( std::shared_ptr< ArtifactExpr cond)

Creates an 'if' blocks.

Parameters
cond- condition expression
Returns

Definition at line 83 of file ArtifactModel.cpp.

84{
85 auto ifb = make_shared<ArtifactIf>(cond);
86 _statements.push_back(ifb);
87 return ifb;
88}

Referenced by nnc::AclCppOpGenerator::generate().

◆ isBlock()

bool nnc::ArtifactBlock::isBlock ( ) const
inlineoverridevirtual

If this entity represents something containing a block of instructions.

Reimplemented from nnc::ArtifactEntity.

Definition at line 355 of file ArtifactModel.h.

355{ return true; }

◆ ret()

shared_ptr< ArtifactRet > nnc::ArtifactBlock::ret ( std::shared_ptr< ArtifactExpr expr)

Creates a return from function statement.

Parameters
expr- value to return in generated code.
Returns

Definition at line 53 of file ArtifactModel.cpp.

54{
55 auto ret = make_shared<ArtifactRet>(expr);
56 _statements.push_back(ret);
57 return ret;
58}
std::shared_ptr< ArtifactRet > ret(std::shared_ptr< ArtifactExpr > expr)
Creates a return from function statement.

References ret().

Referenced by ret().

◆ un()

shared_ptr< ArtifactUnaryExpr > nnc::ArtifactBlock::un ( ArtifactUnOp  op,
std::shared_ptr< ArtifactExpr expr 
)

Creates an unary operation expression.

Parameters
op
expr
Returns

Definition at line 90 of file ArtifactModel.cpp.

91{
92 auto un = make_shared<ArtifactUnaryExpr>(op, expr);
93 _statements.push_back(un);
94 return un;
95}
std::shared_ptr< ArtifactUnaryExpr > un(ArtifactUnOp op, std::shared_ptr< ArtifactExpr > expr)
Creates an unary operation expression.

References un().

Referenced by un().

◆ var()

shared_ptr< ArtifactVariable > nnc::ArtifactBlock::var ( const std::string &  type_name,
const std::string &  var_name,
const std::list< std::shared_ptr< ArtifactExpr > > &  dimensions = {},
const std::list< std::shared_ptr< ArtifactExpr > > &  initializers = {} 
)

Creates a new variable and place it to the block.

Parameters
type_name- the variable type name.
var_name- the varibale name.
dimensions- optional dimensions, if the declared variable is an array.
initializers- optional arguments of the object constructor.
Returns
- the newly created variable.

Definition at line 35 of file ArtifactModel.cpp.

38{
39 auto var = make_shared<ArtifactVariable>(type_name, var_name, dimensions, initializers);
40 _statements.push_back(var);
41 return var;
42}
std::shared_ptr< ArtifactVariable > var(const std::string &type_name, const std::string &var_name, const std::list< std::shared_ptr< ArtifactExpr > > &dimensions={}, const std::list< std::shared_ptr< ArtifactExpr > > &initializers={})
Creates a new variable and place it to the block.

References var().

Referenced by nnc::AclCppOpGenerator::genPadStrideInfo(), nnc::AclCppOpGenerator::genVectorInitializedVar(), var(), and nnc::AclCppOpGenerator::visit().


The documentation for this class was generated from the following files: