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

Last change on this file since 4991 was 4991, checked in by nmedfort, 4 years ago

Symbol table work and untested kernel instatiate method for multiple input streams

File size: 3.9 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>
32using namespace boost::iostreams;
33using namespace boost::filesystem;
34
35typedef void (*SymTableFunctionType)(char * byte_data, size_t filesize);
36
37static cl::list<std::string> files(cl::Positional, cl::desc("<input file ...>"), cl::OneOrMore);
38
39void process(const std::string & fileName, SymTableFunctionType function) {
40    const path filePath(fileName);
41    if (exists(filePath) && !is_directory(filePath)) {
42        size_t fileSize = file_size(filePath);
43        if (fileSize > 0) {
44            mapped_file file;
45            file.open(fileName, mapped_file::priv, fileSize, 0);
46            char * data = file.data();
47            assert (data);
48            function(data, fileSize);
49            file.close();
50        }
51    }
52}
53
54
55int main(int argc, char *argv[]) {
56    StringMap<cl::Option*> Map;
57    cl::getRegisteredOptions(Map);
58    Map["time-passes"]->setHiddenFlag(cl::Hidden);
59    Map["disable-spill-fusing"]->setHiddenFlag(cl::Hidden);
60    Map["enable-misched"]->setHiddenFlag(cl::Hidden);
61    Map["enable-tbaa"]->setHiddenFlag(cl::Hidden);
62    Map["exhaustive-register-search"]->setHiddenFlag(cl::Hidden);
63    Map["join-liveintervals"]->setHiddenFlag(cl::Hidden);
64    Map["limit-float-precision"]->setHiddenFlag(cl::Hidden);
65    Map["mc-x86-disable-arith-relaxation"]->setHiddenFlag(cl::Hidden);
66    Map["limit-float-precision"]->setHiddenFlag(cl::Hidden);
67    Map["print-after-all"]->setHiddenFlag(cl::Hidden);
68    Map["print-before-all"]->setHiddenFlag(cl::Hidden);
69    Map["print-machineinstrs"]->setHiddenFlag(cl::Hidden);
70    Map["regalloc"]->setHiddenFlag(cl::Hidden);
71    Map["rng-seed"]->setHiddenFlag(cl::Hidden);
72    Map["stackmap-version"]->setHiddenFlag(cl::Hidden);
73    Map["x86-asm-syntax"]->setHiddenFlag(cl::Hidden);
74    Map["verify-debug-info"]->setHiddenFlag(cl::Hidden);
75    Map["verify-dom-info"]->setHiddenFlag(cl::Hidden);
76    Map["verify-loop-info"]->setHiddenFlag(cl::Hidden);
77    Map["verify-regalloc"]->setHiddenFlag(cl::Hidden);
78    Map["verify-scev"]->setHiddenFlag(cl::Hidden);
79    Map["x86-recip-refinement-steps"]->setHiddenFlag(cl::Hidden);
80    Map["rewrite-map-file"]->setHiddenFlag(cl::Hidden);
81
82    cl::ParseCommandLineOptions(argc, argv);
83
84    Module * M = new Module("symboltable", getGlobalContext());
85
86    IDISA::IDISA_Builder * idb = GetIDISA_Builder(M);
87
88    kernel::SymbolTableBuilder pipelineBuilder(M, idb);
89
90    pipelineBuilder.createKernels();
91
92    llvm::Function * main_IR = pipelineBuilder.ExecuteKernels();
93    if (LLVM_UNLIKELY(main_IR == nullptr)) {
94        throw std::runtime_error("No LLVM function created!");
95    }
96    llvm::ExecutionEngine * engine = JIT_to_ExecutionEngine(M);
97    verifyModule(*M, &dbgs());
98    engine->finalizeObject();
99
100    SymTableFunctionType function = reinterpret_cast<SymTableFunctionType>(engine->getPointerToFunction(main_IR));
101    if (LLVM_UNLIKELY(function == nullptr)) {
102        throw std::runtime_error("filed to compile LLVM function!");
103    }
104
105    for (std::string file : files) {
106        process(file, function);
107    }
108
109    delete engine;
110    delete idb;
111    return 0;
112}
Note: See TracBrowser for help on using the repository browser.