Ignore:
Timestamp:
Dec 22, 2016, 2:35:46 PM (2 years ago)
Author:
nmedfort
Message:

Modified memory alignment mechanism for GetPropertyValueGrepString? + misc. changes.

Location:
icGREP/icgrep-devel/icgrep/UCD
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/UCD/PropertyObjects.cpp

    r5233 r5234  
    88#include "PropertyObjects.h"
    99#include "PropertyObjectTable.h"
    10 #include <sstream>
     10#include <llvm/Support/Casting.h>
    1111#include <algorithm>
    1212#include <assert.h>
    13 #include <llvm/Support/Casting.h>
     13#include <sstream>
    1414
    1515using namespace llvm;
     
    1717namespace UCD {
    1818
     19using PropertyStringStream =
     20    std::basic_stringstream<char, std::char_traits<char>, PropertyStringAllocator>;
     21
    1922std::string canonicalize_value_name(const std::string & prop_or_val) {
    2023    std::locale loc;
    2124    std::stringstream s;
     25
    2226    for (char c : prop_or_val) {
    2327        if ((c != '_') && (c != ' ') && (c != '-')) {
     
    3135    throw std::runtime_error("Property " + value_spec + " unsupported.");
    3236}
    33 const std::string& PropertyObject::GetPropertyValueGrepString() {
     37const PropertyString & PropertyObject::GetPropertyValueGrepString() {
    3438    throw std::runtime_error("Property Value Grep String unsupported.");
    3539}
     
    4448
    4549const UnicodeSet & EnumeratedPropertyObject::GetCodepointSet(const std::string & value_spec) {
    46     int property_enum_val = GetPropertyValueEnumCode(value_spec);
    47     if (property_enum_val == -1) {
    48         throw std::runtime_error("Enumerated Property " + UCD::property_full_name[the_property] +  ": unknown value: " + value_spec);
     50    const int property_enum_val = GetPropertyValueEnumCode(value_spec);
     51    if (property_enum_val < 0) {
     52        throw std::runtime_error("Enumerated Property " + UCD::property_full_name[the_property] + ": unknown value: " + value_spec);
    4953    }
    5054    return GetCodepointSet(property_enum_val);
     
    6367        // has bit i set, i.e., (e >> i) & 1 == 1.
    6468        unsigned basis_count = 1;
    65         while ((1 << basis_count) < independent_enum_count) basis_count++;
     69        while ((1UL << basis_count) < independent_enum_count) {
     70            basis_count++;
     71        }
    6672        for (unsigned i = 0; i < basis_count; i++) {
    6773            enumeration_basis_sets.push_back(UnicodeSet());
    6874            for (unsigned e = 0; e < independent_enum_count; e++) {
    69                 if (((e >> i) & 1) == 0) {
     75                if (((e >> i) & 1UL) == 0) {
    7076                    enumeration_basis_sets[i] = enumeration_basis_sets[i] + *property_value_sets[e];
    7177                }
     
    7682};
    7783
    78 const std::string& EnumeratedPropertyObject::GetPropertyValueGrepString() {
    79     if (!property_value_grep_string.size()) {
     84const PropertyString &EnumeratedPropertyObject::GetPropertyValueGrepString() {
     85    if (LLVM_LIKELY(property_value_grep_string.empty())) {
     86        PropertyStringStream buffer;
    8087        for (unsigned i = 0; i != property_value_full_names.size(); i++) {
    81             property_value_grep_string += canonicalize_value_name(property_value_full_names[i]) + "\n";
     88            buffer << canonicalize_value_name(property_value_full_names[i]) + "\n";
    8289        }
    8390        for (unsigned i = 0; i != property_value_enum_names.size(); i++) {
    84             property_value_grep_string += canonicalize_value_name(property_value_enum_names[i]) + "\n";
     91            buffer << canonicalize_value_name(property_value_enum_names[i]) + "\n";
    8592        }
     93        property_value_grep_string.assign(buffer.str());
    8694    }
    8795    return property_value_grep_string;
     
    137145}
    138146
    139 const std::string& ExtensionPropertyObject::GetPropertyValueGrepString() {
     147const PropertyString & ExtensionPropertyObject::GetPropertyValueGrepString() {
    140148    return property_object_table[base_property]->GetPropertyValueGrepString();
    141149}
     
    164172}
    165173
    166 const std::string& BinaryPropertyObject::GetPropertyValueGrepString() {
    167     if (!property_value_grep_string.size()) {
    168         for (auto iter = Binary_ns::aliases_only_map.begin(), end = Binary_ns::aliases_only_map.end(); iter != end; ++iter) {
    169             property_value_grep_string += iter->first + "\n";
     174const PropertyString & BinaryPropertyObject::GetPropertyValueGrepString() {
     175    if (property_value_grep_string.empty()) {
     176        PropertyStringStream buffer;
     177        for (const auto & prop : Binary_ns::aliases_only_map) {
     178            buffer << std::get<0>(prop) + "\n";
    170179        }
     180        property_value_grep_string.assign(buffer.str());
    171181    }
    172182    return property_value_grep_string;
  • icGREP/icgrep-devel/icgrep/UCD/PropertyObjects.h

    r5206 r5234  
    1414#include <vector>
    1515#include <unordered_map>
     16#include <boost/align/aligned_allocator.hpp>
    1617
    1718namespace UCD {
     19
     20using PropertyStringAllocator = boost::alignment::aligned_allocator<char, 32>;
     21
     22using PropertyString =
     23    std::basic_string<char, std::char_traits<char>, PropertyStringAllocator>;
    1824
    1925std::string canonicalize_value_name(const std::string & prop_or_val);
     
    3238        , UnsupportedProperty
    3339    };
     40
    3441    using iterator = const std::vector<std::string>::const_iterator;
    3542    inline ClassTypeId getClassTypeId() const {
     
    4148    PropertyObject(property_t p, ClassTypeId k) : the_property(p), the_kind(k) {}
    4249    virtual int GetPropertyValueEnumCode(const std::string & value_spec);
    43     virtual const std::string& GetPropertyValueGrepString();
     50    virtual const PropertyString & GetPropertyValueGrepString();
    4451    property_t the_property;
    4552    ClassTypeId the_kind;
     
    8996
    9097    virtual int GetPropertyValueEnumCode(const std::string & value_spec);
    91     virtual const std::string& GetPropertyValueGrepString();
     98    virtual const PropertyString & GetPropertyValueGrepString();
    9299    const UnicodeSet & GetCodepointSet(const std::string & value_spec);
    93100    const UnicodeSet & GetCodepointSet(const int property_enum_val) const;
     
    109116    const std::vector<std::string> & property_value_full_names;  // never changes
    110117    std::unordered_map<std::string, int> & property_value_aliases;
    111     std::string property_value_grep_string;
     118    PropertyString property_value_grep_string;
    112119    bool uninitialized; // full names must be added dynamically.
    113120    const std::vector<const UnicodeSet *> property_value_sets;
     
    139146
    140147    virtual int GetPropertyValueEnumCode(const std::string & value_spec);
    141     virtual const std::string& GetPropertyValueGrepString();
     148    virtual const PropertyString & GetPropertyValueGrepString();
    142149    const UnicodeSet & GetCodepointSet(const std::string & value_spec);
    143150    const UnicodeSet & GetCodepointSet(const int property_enum_val) const;
     
    165172    const UnicodeSet & GetCodepointSet(const std::string & value_spec);
    166173    const UnicodeSet & GetCodepointSet(const int property_enum_val);
    167     virtual const std::string& GetPropertyValueGrepString();
     174    virtual const PropertyString & GetPropertyValueGrepString();
    168175private:
    169176    bool mNoUninitialized;
    170177    UnicodeSet mY;
    171178    UnicodeSet mN;
    172     std::string property_value_grep_string;
     179    PropertyString property_value_grep_string;
    173180};
    174181
  • icGREP/icgrep-devel/icgrep/UCD/resolve_properties.cpp

    r5233 r5234  
    220220}
    221221
    222 const std::string& getPropertyValueGrepString(const std::string & prop) {
    223     auto propName = canonicalize_value_name(prop);
    224     auto propit = alias_map.find(propName);
     222const PropertyString & getPropertyValueGrepString(const std::string & prop) {
     223    auto propit = alias_map.find(canonicalize_value_name(prop));
    225224    if (propit == alias_map.end()) {
    226225        throw UnicodePropertyExpressionError("Expected a property name, but '" + prop + "' found instead");
  • icGREP/icgrep-devel/icgrep/UCD/resolve_properties.h

    r5206 r5234  
    44#include <string>
    55#include <UCD/unicode_set.h>
     6#include <UCD/PropertyObjects.h>
    67
    78namespace re {
     
    1112
    1213namespace UCD {
     14
    1315
    1416class UnicodePropertyExpressionError : public std::exception {
     
    2527std::string resolvePropertyFunction(re::Name * const property);
    2628UCD::UnicodeSet resolveUnicodeSet(re::Name * const name);
    27 const std::string& getPropertyValueGrepString(const std::string & prop);
     29const PropertyString & getPropertyValueGrepString(const std::string & prop);
    2830
    2931}
Note: See TracChangeset for help on using the changeset viewer.