source: icGREP/icgrep-devel/icgrep/pablo/symbol_generator.cpp @ 4410

Last change on this file since 4410 was 4410, checked in by nmedfort, 5 years ago

Changes to support 3-operand form for all instructions. CSE disabled but partially redundant now.

File size: 1002 bytes
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 <pablo/symbol_generator.h>
8#include <pablo/pe_string.h>
9
10namespace pablo {
11
12SymbolGenerator::SymbolGenerator()
13: mPrefixMap()
14{
15
16}
17
18String * SymbolGenerator::get(const std::string name) {
19    auto f = mStringMap.find(name);
20    String * result;
21    if (f == mStringMap.end()) {
22        result = makeString(name);
23        mStringMap.insert(std::make_pair(std::move(name), result));
24    }
25    else {
26        result = f->second;
27    }
28    return result;
29}
30
31String * SymbolGenerator::make(const std::string prefix) {
32    auto f = mPrefixMap.find(prefix);
33    unsigned count = 0;
34    if (f == mPrefixMap.end()) {
35        mPrefixMap.insert(std::make_pair(prefix, 1));
36        return get(prefix);
37    }
38    else {
39        count = f->second++;
40        return get(prefix + std::to_string(count));
41    }
42}
43
44
45}
Note: See TracBrowser for help on using the repository browser.