OLD | NEW |
1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// | 1 //===- subzero/src/llvm2ice.cpp - Driver for testing ----------------------===// |
2 // | 2 // |
3 // The Subzero Code Generator | 3 // The Subzero Code Generator |
4 // | 4 // |
5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
7 // | 7 // |
8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
9 // | 9 // |
10 // This file defines a driver that uses LLVM capabilities to parse a | 10 // This file defines a driver that uses LLVM capabilities to parse a |
11 // bitcode file and build the LLVM IR, and then convert the LLVM basic | 11 // bitcode file and build the LLVM IR, and then convert the LLVM basic |
12 // blocks, instructions, and operands into their Subzero equivalents. | 12 // blocks, instructions, and operands into their Subzero equivalents. |
13 // | 13 // |
14 //===----------------------------------------------------------------------===// | 14 //===----------------------------------------------------------------------===// |
15 | 15 |
16 #include "IceCfg.h" | 16 #include "IceCfg.h" |
| 17 #include "IceClFlags.h" |
17 #include "IceConverter.h" | 18 #include "IceConverter.h" |
18 #include "IceDefs.h" | 19 #include "IceDefs.h" |
19 #include "IceTargetLowering.h" | 20 #include "IceTargetLowering.h" |
20 #include "IceTypes.h" | 21 #include "IceTypes.h" |
| 22 #include "PNaClTranslator.h" |
21 | 23 |
22 #include "llvm/IR/Constant.h" | |
23 #include "llvm/IR/Constants.h" | 24 #include "llvm/IR/Constants.h" |
24 #include "llvm/IR/LLVMContext.h" | 25 #include "llvm/IR/LLVMContext.h" |
25 #include "llvm/IR/Module.h" | 26 #include "llvm/IR/Module.h" |
26 #include "llvm/IRReader/IRReader.h" | 27 #include "llvm/IRReader/IRReader.h" |
27 #include "llvm/Support/CommandLine.h" | 28 #include "llvm/Support/CommandLine.h" |
28 #include "llvm/Support/raw_os_ostream.h" | 29 #include "llvm/Support/raw_os_ostream.h" |
29 #include "llvm/Support/SourceMgr.h" | 30 #include "llvm/Support/SourceMgr.h" |
30 | 31 |
31 #include <fstream> | 32 #include <fstream> |
32 #include <iostream> | 33 #include <iostream> |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 Os->SetUnbuffered(); | 122 Os->SetUnbuffered(); |
122 std::ofstream Lfs; | 123 std::ofstream Lfs; |
123 if (LogFilename != "-") { | 124 if (LogFilename != "-") { |
124 Lfs.open(LogFilename.c_str(), std::ofstream::out); | 125 Lfs.open(LogFilename.c_str(), std::ofstream::out); |
125 } | 126 } |
126 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); | 127 raw_os_ostream *Ls = new raw_os_ostream(LogFilename == "-" ? std::cout : Lfs); |
127 Ls->SetUnbuffered(); | 128 Ls->SetUnbuffered(); |
128 | 129 |
129 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); | 130 Ice::GlobalContext Ctx(Ls, Os, VMask, TargetArch, OptLevel, TestPrefix); |
130 | 131 |
| 132 Ice::ClFlags Flags; |
| 133 Flags.DisableInternal = DisableInternal; |
| 134 Flags.SubzeroTimingEnabled = SubzeroTimingEnabled; |
| 135 Flags.DisableTranslation = DisableTranslation; |
| 136 |
131 if (BuildOnRead) { | 137 if (BuildOnRead) { |
132 std::cerr << "Direct build from bitcode not implemented yet!\n"; | 138 Ice::PNaClTranslator Translator(&Ctx, Flags); |
133 return 1; | 139 Translator.translate(IRFilename); |
| 140 return Translator.getExitStatus(); |
134 } else { | 141 } else { |
135 // Parse the input LLVM IR file into a module. | 142 // Parse the input LLVM IR file into a module. |
136 SMDiagnostic Err; | 143 SMDiagnostic Err; |
137 Ice::Timer T; | 144 Ice::Timer T; |
138 Module *Mod = | 145 Module *Mod = |
139 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); | 146 NaClParseIRFile(IRFilename, InputFileFormat, Err, getGlobalContext()); |
140 | 147 |
141 if (SubzeroTimingEnabled) { | 148 if (SubzeroTimingEnabled) { |
142 std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec() | 149 std::cerr << "[Subzero timing] IR Parsing: " << T.getElapsedSec() |
143 << " sec\n"; | 150 << " sec\n"; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 } | 189 } |
183 } else { | 190 } else { |
184 llvm_unreachable("Unhandled global initializer"); | 191 llvm_unreachable("Unhandled global initializer"); |
185 } | 192 } |
186 | 193 |
187 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer, | 194 GlobalLowering->lower(Name, Align, IsInternal, IsConst, IsZeroInitializer, |
188 NumElements, Data, DisableTranslation); | 195 NumElements, Data, DisableTranslation); |
189 } | 196 } |
190 GlobalLowering.reset(); | 197 GlobalLowering.reset(); |
191 | 198 |
192 Ice::Converter Converter(&Ctx, DisableInternal, SubzeroTimingEnabled, | 199 Ice::Converter Converter(&Ctx, Flags); |
193 DisableTranslation); | |
194 return Converter.convertToIce(Mod); | 200 return Converter.convertToIce(Mod); |
195 } | 201 } |
196 } | 202 } |
OLD | NEW |