Ignore:
Timestamp:
Oct 4, 2014, 1:14:35 PM (5 years ago)
Author:
nmedfort
Message:

First stage of code generator revamp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/cc/cc_compiler.cpp

    r4209 r4210  
    3030#include <re/re_seq.h>
    3131#include <re/re_rep.h>
     32#include <re/re_name.h>
    3233
    3334#include <utility>
     
    4647namespace cc {
    4748
    48 CC_Compiler::CC_Compiler(const Encoding encoding, const std::string basis_pattern, const std::string gensym_pattern)
    49 : mEncoding(encoding)
     49CC_Compiler::CC_Compiler(CodeGenState & cg, const Encoding encoding, const std::string basis_pattern, const std::string gensym_pattern)
     50: mCG(cg)
     51, mEncoding(encoding)
    5052, mGenSymPattern(gensym_pattern)
    5153, mGenSymCounter(0)
     
    6264}
    6365
    64 
    65 void CC_Compiler::add_predefined(std::string key_value, Expression* mapped_value)
    66 {
     66void CC_Compiler::compile(const REMap & re_map) {
     67    process_re_map(re_map);
     68    for (auto i =  re_map.rbegin(); i != re_map.rend(); ++i) {
     69        //This is specifically for the utf8 multibyte character classes.
     70        if (Seq * seq = dyn_cast<Seq>(i->second)) {
     71            if (seq->getType() == Seq::Type::Byte) {
     72                auto j = seq->begin();
     73                while (true) {
     74                    Name * name = dyn_cast<Name>(*j);
     75                    assert (name);
     76                    CharClass * cc_mask = makeCharClass(name->getName());
     77                    if (++j != seq->end()) {
     78                        mCG.push_back(makeAssign(mCG.symgen("marker"), makeAdvance(cc_mask)));
     79                    }
     80                    else {
     81                        mCG.push_back(makeAssign(seq->getName(), cc_mask));
     82                        break;
     83                    }
     84                }
     85            }
     86        }
     87    }
     88}
     89
     90inline void CC_Compiler::add_predefined(std::string key_value, Expression* mapped_value) {
    6791    mCommon_Expression_Map.insert(make_pair(key_value, mapped_value));
    6892}
     
    7195{   
    7296    //Add the new mapping to the list of pablo statements:
    73     mStmtsl.push_back(makeAssign(varname, expr->pablo_expr));
     97    mCG.push_back(makeAssign(varname, expr->pablo_expr));
    7498
    7599    //Add the new mapping to the common expression map:
     
    92116        return add_assignment(mGenSymPattern + std::to_string(++mGenSymCounter), expr);
    93117    }
    94 }
    95 
    96 CC_Compiler::List CC_Compiler::get_compiled()
    97 {
    98     return mStmtsl;
    99 }
    100 
    101 void CC_Compiler::compile_from_map(const REMap &re_map)
    102 {
    103     process_re_map(re_map);
    104118}
    105119
Note: See TracChangeset for help on using the changeset viewer.