source: icGREP/icgrep-devel/icgrep/re/re_range.cpp @ 5816

Last change on this file since 5816 was 5814, checked in by cameron, 18 months ago

Parsing of byte CCs

File size: 1.2 KB
Line 
1/*
2 *  Copyright (c) 2017 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 <re/re_range.h>
8#include <re/re_cc.h>
9#include <re/re_name.h>
10#include <llvm/Support/Casting.h>
11#include <llvm/Support/ErrorHandling.h>
12
13using namespace llvm;
14
15namespace re {
16
17RE * makeRange(RE * lo, RE * hi) {
18    if (isa<CC>(lo) && isa<CC>(hi)) {
19        if (!((dyn_cast<CC>(lo)->count() == 1) && (dyn_cast<CC>(hi)->count() == 1)))
20            llvm::report_fatal_error("invalid range operand");
21        auto lo_val = dyn_cast<CC>(lo)->front().first;
22        auto hi_val = dyn_cast<CC>(hi)->front().first;
23        return makeCC(lo_val, hi_val, dyn_cast<CC>(hi)->getAlphabet());
24    }
25    else if (isa<Name>(lo) && (cast<Name>(lo)->getDefinition() != nullptr)) {
26        return makeRange(cast<Name>(lo)->getDefinition(), hi);
27    }
28    else if (isa<Name>(hi) && (cast<Name>(hi)->getDefinition() != nullptr)) {
29        return makeRange(lo, cast<Name>(hi)->getDefinition());
30    }
31    else if (lo == hi) { // TODO: general check for equality, not just instance equality
32        return lo;
33    }
34    return new Range(lo, hi);
35}
36   
37}
Note: See TracBrowser for help on using the repository browser.