source: icGREP/icgrep-devel/icgrep/cc_codegenobject.cpp @ 3998

Last change on this file since 3998 was 3984, checked in by cameron, 5 years ago

Eliminate INT2STRING in favor of std::to_string

File size: 1.8 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/*
8 *  Copyright © 2014 International Characters.
9 *  This software is licensed to the public under the Open Software License 3.0.
10 *  icgrep is a trademark of International Characters.
11 */
12
13#include "cc_codegenobject.h"
14
15CC_CodeGenObject::CC_CodeGenObject(std::string gensym_pattern)
16{
17    mGenSym_Template = gensym_pattern;
18    mGenSymCounter = 0;
19}
20
21void CC_CodeGenObject::add_predefined(std::string key_value, Expression* mapped_value)
22{
23    mCommon_Expression_Map.insert(make_pair(key_value, mapped_value));
24}
25
26Expression* CC_CodeGenObject::add_assignment(std::string varname, Expression* expr)
27{   
28    //Add the new mapping to the list of pablo statements:
29    mStmtsl.push_back(new Assign(varname, expr->pablo_expr));
30
31    //Add the new mapping to the common expression map:
32    std::string key_value = expr->expr_string;
33    Expression* mapped_value = new Expression();
34    mapped_value->expr_string = varname;
35    mapped_value->pablo_expr = new Var(varname);
36
37    std::pair<std::map<std::string, Expression*>::iterator, bool> ret = mCommon_Expression_Map.insert(make_pair(key_value, mapped_value));
38
39    return ret.first->second;
40}
41
42Expression* CC_CodeGenObject::expr_to_variable(Expression* expr)
43{
44    if (mCommon_Expression_Map.count(expr->expr_string) > 0)
45    {
46        std::map<std::string, Expression*>::iterator itGet = mCommon_Expression_Map.find(expr->expr_string);
47        return itGet->second;
48    }
49    else
50    {
51        mGenSymCounter++;
52        std::string sym = mGenSym_Template + std::to_string(mGenSymCounter);
53        return add_assignment(sym, expr);
54    }
55}
56
57std::list<PabloS*> CC_CodeGenObject::get_stmtsl()
58{
59    return mStmtsl;
60}
61
62
Note: See TracBrowser for help on using the repository browser.