source: icGREP/icgrep-0.8/icgrep/re_compiler.cpp @ 3972

Last change on this file since 3972 was 3850, checked in by cameron, 5 years ago

icgrep-0.8 distribution

File size: 2.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 "re_compiler.h"
8
9RE_Compiler::RE_Compiler(){}
10
11LLVM_Gen_RetVal RE_Compiler::compile(bool show_compile_time, std::string basis_pattern, std::string gensym_pattern, UTF_Encoding encoding, std::string input_string)
12{
13    RE_Parser parser;
14
15    ParseResult* parse_result = parser.parse_re(input_string);
16
17    RE* parsed_re = 0;
18    if (ParseSuccess* success = dynamic_cast<ParseSuccess*>(parse_result))
19    {
20        parsed_re = success->getRE();
21    }
22    else if (ParseFailure* failure = dynamic_cast<ParseFailure*>(parse_result))
23    {
24        std::cout << failure->getErrorMsg() << std::endl;
25        exit(1);
26    }
27    else
28    {
29        std::cout << "An unexepected parser error has occured!" << std::endl;
30        exit(1);
31    }
32
33    //Print to the terminal the AST that was generated by the parser before adding the UTF encoding:
34    //std::cout << "\n" + Printer_RE::PrintRE(parsed_re) + "\n" << std::endl;
35
36    //Add the UTF encoding.
37    RE* utf_encoded_re = 0;
38    if (encoding.getName().compare("UTF-8") == 0)
39    {
40        UTF8_Encoder utf8_encoder;
41        utf_encoded_re = utf8_encoder.toUTF8(parsed_re);
42    }
43    else
44    {
45        std::cout << "Invalid encoding!" << std::endl;
46        exit(1);
47    }
48
49    //Print to the terminal the AST that was generated by the utf8 encoder.
50    //std::cout << "\n" + Printer_RE::PrintRE(utf_encoded_re) + "\n" << std::endl;
51
52    //Build our list of predefined characters.
53    std::list<CC*> predefined_characters;
54    CC* cc_lf = new CC("lex.cclf", '\n');
55    predefined_characters.push_back(cc_lf);
56
57    CC_Compiler cc_compiler(encoding);
58    std::list<PabloS*> cc_stmtsl = cc_compiler.compile(basis_pattern, gensym_pattern, utf_encoded_re, predefined_characters);
59
60    //Print to the terminal the AST that was generated by the character class compiler.
61    //std::cout << "\n" << "(" << StatementPrinter::Print_CC_PabloStmts(cc_stmtsl) << ")" << "\n" << std::endl;
62
63    Pbix_Compiler pbix_compiler;
64    CodeGenState cg_state = pbix_compiler.compile(utf_encoded_re);
65
66    //Print to the terminal the AST that was generated by the pararallel bit-stream compiler.
67    //std::cout << "\n" << "(" << StatementPrinter::PrintStmts(cg_state) << ")" << "\n" << std::endl;
68
69    LLVM_Generator irgen(basis_pattern, encoding.getBits());
70
71    double timer = 0;
72    if (show_compile_time) timer = getElapsedTime();
73    LLVM_Gen_RetVal retVal = irgen.Generate_LLVMIR(cg_state, cc_stmtsl);
74    if (show_compile_time)
75    {
76        timer = getElapsedTime() - timer;
77        std::cout << "LLVM Compile Time: " << timer <<  " seconds" << std::endl;
78    }
79
80    return retVal;
81}
82
Note: See TracBrowser for help on using the repository browser.