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

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

Added pablo Prototype to compiler. All Calls must be given one instead of a Name.

File size: 1.6 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)
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
14}
15
16PabloFunction::PabloFunction(std::string && name, const unsigned numOfParameters, const unsigned numOfResults)
17: Prototype(ClassTypeId::Function, std::move(name), numOfParameters, numOfResults, 0)
18, mEntryBlock(PabloBlock::Create(mSymbolTable))
19, mParameters(reinterpret_cast<Var **>(mAllocator.allocate(sizeof(Var *) * numOfParameters)))
20, mResults(reinterpret_cast<Assign **>(mAllocator.allocate(sizeof(Assign *) * numOfResults))) {
21    std::memset(mParameters, 0, sizeof(Var *) * numOfParameters);
22    std::memset(mResults, 0, sizeof(Assign *) * numOfResults);
23}
24
25void PabloFunction::throwInvalidParameterIndex(const unsigned index) const {
26    throw std::runtime_error(
27                "Invalid parameter index " +
28                std::to_string(index) + " of " + std::to_string(getNumOfParameters()) +
29                " in function " + getName()->to_string());
30}
31
32void PabloFunction::throwInvalidResultIndex(const unsigned index) const {
33    throw std::runtime_error(
34                "Invalid result index " +
35                std::to_string(index) + " of " + std::to_string(getNumOfResults()) +
36                " in function " + getName()->to_string());
37}
38
39
40}
Note: See TracBrowser for help on using the repository browser.