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

Last change on this file since 4687 was 4684, checked in by nmedfort, 4 years ago

First attempt to intergrate 'generate_predefined_ucd_functions' into build process.

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, const unsigned requiredStateSpace, void * functionPtr)
8: PabloAST(type)
9, mName(new String(name, false)) // <-- Should there be a global pool to assert that no two prototypes have the same name?
10, mNumOfParameters(numOfParameters)
11, mNumOfResults(numOfResults)
12, mRequiredStateSpace(requiredStateSpace)
13, mFunctionPtr(functionPtr) {
14
15}
16
17PabloFunction::PabloFunction(std::string && name, const unsigned numOfParameters, const unsigned numOfResults)
18: Prototype(ClassTypeId::Function, std::move(name), numOfParameters, numOfResults, 0, nullptr)
19, mEntryBlock(PabloBlock::Create(mSymbolTable))
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
40
41}
Note: See TracBrowser for help on using the repository browser.