source: icGREP/icgrep-devel/icgrep/symboltable.cpp @ 5101

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

Clean out using boost namespaces

File size: 2.5 KB
Line 
1/*
2 *  Copyright (c) 2015 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 <string>
8#include <iostream>
9#include <fstream>
10
11#include "toolchain.h"
12#include "utf_encoding.h"
13#include "pablo/pablo_compiler.h"
14#include <llvm/IR/Function.h>
15#include <llvm/IR/Type.h>
16#include <llvm/IR/Module.h>
17#include <llvm/ExecutionEngine/ExecutionEngine.h>
18#include <llvm/ExecutionEngine/MCJIT.h>
19#include <llvm/IRReader/IRReader.h>
20#include <llvm/Support/SourceMgr.h>
21#include <llvm/Support/CommandLine.h>
22#include <llvm/Support/Debug.h>
23#include <llvm/Support/TargetSelect.h>
24#include <llvm/Support/Host.h>
25#include <llvm/IR/Verifier.h>
26#include <IDISA/idisa_target.h>
27#include <kernels/symboltablepipeline.h>
28
29// mmap system
30#include <boost/filesystem.hpp>
31#include <boost/iostreams/device/mapped_file.hpp>
32
33typedef void (*SymTableFunctionType)(char * byte_data, size_t filesize);
34
35static cl::list<std::string> files(cl::Positional, cl::desc("<input file ...>"), cl::ZeroOrMore);
36
37void process(const std::string & fileName, SymTableFunctionType function) {
38    const boost::filesystem::path filePath(fileName);
39    if (exists(filePath) && !is_directory(filePath)) {
40        size_t fileSize = file_size(filePath);
41        if (fileSize > 0) {
42            boost::iostreams::mapped_file file;
43            file.open(fileName, boost::iostreams::mapped_file::priv, fileSize, 0);
44            char * data = file.data();
45            assert (data);
46            function(data, fileSize);
47            file.close();
48        }
49    }
50}
51
52
53int main(int argc, char *argv[]) {
54
55    Module * M = new Module("symboltable", getGlobalContext());
56
57    IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
58
59    kernel::SymbolTableBuilder pipelineBuilder(M, idb);
60
61    pipelineBuilder.createKernels();
62
63    llvm::Function * main_IR = pipelineBuilder.ExecuteKernels();
64    if (LLVM_UNLIKELY(main_IR == nullptr)) {
65        throw std::runtime_error("No LLVM function created!");
66    }
67    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
68    verifyModule(*M, &dbgs());
69    engine->finalizeObject();
70
71    SymTableFunctionType function = reinterpret_cast<SymTableFunctionType>(engine->getPointerToFunction(main_IR));
72    if (LLVM_UNLIKELY(function == nullptr)) {
73        throw std::runtime_error("filed to compile LLVM function!");
74    }
75
76    for (std::string file : files) {
77        process(file, function);
78    }
79
80    delete engine;
81    delete idb;
82    return 0;
83}
Note: See TracBrowser for help on using the repository browser.