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

Last change on this file since 5239 was 5238, checked in by cameron, 3 years ago

IR_Gen subdirectory for all IR generation utility functions

File size: 1.7 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 <pablo/symbol_generator.h>
8#include <pablo/pe_string.h>
9#include <pablo/pe_integer.h>
10#include <IR_Gen/idisa_builder.h>
11
12namespace pablo {
13
14String * SymbolGenerator::get(const std::string name, IDISA::IDISA_Builder * builder) {
15    if (LLVM_UNLIKELY(name.length() == 0)) {
16        throw std::runtime_error("symbol name cannot be 0-length");
17    }
18    auto f = mStringMap.find(name);
19    String * result = nullptr;
20    if (f == mStringMap.end()) {
21        result = new (mAllocator) String(builder->getInt8PtrTy(), name, mAllocator);
22        assert (result);
23        mStringMap.insert(std::make_pair(std::move(name), result));
24    }
25    else {
26        result = f->second;
27    }
28    return result;
29}
30
31Integer * SymbolGenerator::getInteger(const integer_t value, IDISA::IDISA_Builder * builder) {
32    auto f = mIntegerMap.find(value);
33    Integer * result;
34    if (f == mIntegerMap.end()) {
35        result = new (mAllocator) Integer(value, builder->getSizeTy(), mAllocator);
36        assert (result->value() == value);
37        mIntegerMap.insert(std::make_pair(value, result));
38    } else {
39        result = f->second;
40    }
41    return result;
42}
43
44String * SymbolGenerator::make(const std::string prefix, IDISA::IDISA_Builder * builder) {
45    auto f = mPrefixMap.find(prefix);
46    if (f == mPrefixMap.end()) {
47        mPrefixMap.insert(std::make_pair(prefix, 1));
48        return get(prefix, builder);
49    } else {
50        const unsigned count = f->second++;
51        return get(prefix + '_' + std::to_string(count), builder);
52    }
53}
54
55}
Note: See TracBrowser for help on using the repository browser.