source: icGREP/icgrep-devel/icgrep/pablo/function.cpp @ 5082

Last change on this file since 5082 was 4870, checked in by nmedfort, 4 years ago

Bug fix for Multiplexing. Added ability to set the body of a If/While? node after creation.

File size: 1.7 KB
Line 
1#include "function.h"
2#include <pablo/codegenstate.h>
3#include <cstring>
4
5namespace pablo {
6
7Prototype::Prototype(const PabloAST::ClassTypeId type, std::string && name, const unsigned numOfParameters, const unsigned numOfResults, void * functionPtr)
8: PabloAST(type)
9, mName(GlobalSymbolGenerator.get(name, false))
10, mNumOfParameters(numOfParameters)
11, mNumOfResults(numOfResults)
12, mFunctionPtr(functionPtr) {
13
14}
15
16PabloFunction::PabloFunction(std::string && name, const unsigned numOfParameters, const unsigned numOfResults)
17: Prototype(ClassTypeId::Function, std::move(name), numOfParameters, numOfResults, nullptr)
18, mSymbolTable(new SymbolGenerator())
19, mEntryBlock(PabloBlock::Create(*this))
20, mParameters(reinterpret_cast<Var **>(mAllocator.allocate(sizeof(Var *) * numOfParameters)))
21, mResults(reinterpret_cast<Assign **>(mAllocator.allocate(sizeof(Assign *) * numOfResults))) {
22    std::memset(mParameters, 0, sizeof(Var *) * numOfParameters);
23    std::memset(mResults, 0, sizeof(Assign *) * numOfResults);
24}
25
26void PabloFunction::throwInvalidParameterIndex(const unsigned index) const {
27    throw std::runtime_error(
28                "Invalid parameter index " +
29                std::to_string(index) + " of " + std::to_string(getNumOfParameters()) +
30                " in function " + getName()->to_string());
31}
32
33void PabloFunction::throwInvalidResultIndex(const unsigned index) const {
34    throw std::runtime_error(
35                "Invalid result index " +
36                std::to_string(index) + " of " + std::to_string(getNumOfResults()) +
37                " in function " + getName()->to_string());
38}
39
40void PabloFunction::operator delete(void * ptr) {
41    PabloFunction * f = static_cast<PabloFunction *>(ptr);
42    delete f->mSymbolTable;
43    f->mSymbolTable = nullptr;
44}
45
46}
Note: See TracBrowser for help on using the repository browser.