source: icGREP/icgrep-devel/icgrep/llvm_gen_helper.cpp @ 3935

Last change on this file since 3935 was 3850, checked in by cameron, 5 years ago

icgrep-0.8 distribution

File size: 1.9 KB
Line 
1/*
2 *  Copyright (c) 2014 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#include "llvm_gen_helper.h"
8
9LLVM_Generator_Helper::LLVM_Generator_Helper(){}
10
11int LLVM_Generator_Helper::CarryCount_PabloStatements(std::list<PabloS*> stmts)
12{
13    int retVal = 0;
14
15    std::list<PabloS*>::iterator it;
16    for (it = stmts.begin(); it != stmts.end(); ++it)
17    {
18        retVal += CarryCount_PabloS(*it);
19    }
20
21    return retVal;
22}
23
24int LLVM_Generator_Helper::CarryCount_PabloS(PabloS* stmt)
25{
26    int retVal = 0;
27
28    if (Assign* sm = dynamic_cast<Assign*>(stmt))
29    {
30        retVal = CarryCount_PabloE(sm->getExpr());
31    }
32    else if (While* whl = dynamic_cast<While*>(stmt))
33    {
34        retVal = CarryCount_PabloE(whl->getExpr());
35        retVal += CarryCount_PabloStatements(whl->getPSList());
36    }
37
38    return retVal;
39}
40
41int LLVM_Generator_Helper::CarryCount_PabloE(PabloE* expr)
42{
43    int retVal = 0;
44
45    if (And* pablo_and = dynamic_cast<And*>(expr))
46    {
47        retVal =  CarryCount_PabloE(pablo_and->getExpr1()) + CarryCount_PabloE(pablo_and->getExpr2());
48    }
49    else if (Or* pablo_or = dynamic_cast<Or*>(expr))
50    {
51        retVal = CarryCount_PabloE(pablo_or->getExpr1()) + CarryCount_PabloE(pablo_or->getExpr2());
52    }
53    else if (Not* pablo_not = dynamic_cast<Not*>(expr))
54    {
55        retVal = CarryCount_PabloE(pablo_not->getExpr());
56    }
57    else if (Advance* adv = dynamic_cast<Advance*>(expr))
58    {
59        //Carry queues are needed for advances.
60        retVal = 1 + CarryCount_PabloE(adv->getExpr());
61    }
62    else if(MatchStar* mstar = dynamic_cast<MatchStar*>(expr))
63    {
64        //Carry queues are also needed for MatchStar.
65        retVal = 1 + CarryCount_PabloE(mstar->getExpr1()) + CarryCount_PabloE(mstar->getExpr2());
66    }
67
68    return retVal;
69}
70
71
Note: See TracBrowser for help on using the repository browser.