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

Last change on this file since 4133 was 4086, checked in by cameron, 5 years ago

Support for Pablo if-statements; use for utf-8 scope streams

File size: 2.4 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 (If* ifstmt = dynamic_cast<If*>(stmt)) {
33        retVal = CarryCount_PabloE(ifstmt->getExpr());
34        retVal += CarryCount_PabloStatements(ifstmt->getPSList());
35        // If there is more than one internal carry, we create a stored
36        // accumulator value that Ors together all the carries, so add 1
37        // to the carry count.
38        if (retVal > 1) retVal++;
39    }
40    else if (While* whl = dynamic_cast<While*>(stmt))
41    {
42        retVal = CarryCount_PabloE(whl->getExpr());
43        retVal += CarryCount_PabloStatements(whl->getPSList());
44    }
45
46    return retVal;
47}
48
49int LLVM_Generator_Helper::CarryCount_PabloE(PabloE* expr)
50{
51    int retVal = 0;
52
53    if (And* pablo_and = dynamic_cast<And*>(expr))
54    {
55        retVal =  CarryCount_PabloE(pablo_and->getExpr1()) + CarryCount_PabloE(pablo_and->getExpr2());
56    }
57    else if (Or* pablo_or = dynamic_cast<Or*>(expr))
58    {
59        retVal = CarryCount_PabloE(pablo_or->getExpr1()) + CarryCount_PabloE(pablo_or->getExpr2());
60    }
61    else if (Not* pablo_not = dynamic_cast<Not*>(expr))
62    {
63        retVal = CarryCount_PabloE(pablo_not->getExpr());
64    }
65    else if (Advance* adv = dynamic_cast<Advance*>(expr))
66    {
67        //Carry queues are needed for advances.
68        retVal = 1 + CarryCount_PabloE(adv->getExpr());
69    }
70    else if(MatchStar* mstar = dynamic_cast<MatchStar*>(expr))
71    {
72        //Carry queues are also needed for MatchStar.
73        retVal = 1 + CarryCount_PabloE(mstar->getExpr1()) + CarryCount_PabloE(mstar->getExpr2());
74    }
75    else if (ScanThru* sthru = dynamic_cast<ScanThru*>(expr))
76    {
77        retVal = 1 + CarryCount_PabloE(sthru->getScanFrom()) + CarryCount_PabloE(sthru->getScanThru());
78    }
79
80    return retVal;
81}
82
83
Note: See TracBrowser for help on using the repository browser.