Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 9c2130f

Browse files
committed
Merge branch 'one-stop-shop' into incoming
2 parents 2a516dc + 1ae34a9 commit 9c2130f

File tree

4 files changed

+42
-7
lines changed

4 files changed

+42
-7
lines changed

tools/opt/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
77
IPA
88
IPO
99
IRReader
10+
Linker
1011
# @LOCALMOD-BEGIN
1112
NaClAnalysis
1213
NaClBitWriter

tools/opt/LLVMBuild.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@
1919
type = Tool
2020
name = opt
2121
parent = Tools
22-
required_libraries = NaClBitWriter NaClTransforms NaClAnalysis MinSFITransforms AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Scalar ObjCARC Passes all-targets
22+
required_libraries = NaClBitWriter NaClTransforms NaClAnalysis MinSFITransforms AsmParser BitReader BitWriter CodeGen IRReader IPO Instrumentation Linker Scalar ObjCARC Passes all-targets

tools/opt/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
LEVEL := ../..
1111
TOOLNAME := opt
12-
LINK_COMPONENTS := naclbitwriter nacltransforms naclanalysis minsfitransforms jsbackend bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen passes
12+
LINK_COMPONENTS := naclbitwriter nacltransforms naclanalysis minsfitransforms jsbackend bitreader bitwriter asmparser irreader instrumentation scalaropts objcarcopts ipo vectorize all-targets codegen passes linker
1313

1414
# Support plugins.
1515
NO_DEAD_STRIP := 1

tools/opt/opt.cpp

+39-5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "llvm/IR/Verifier.h"
3535
#include "llvm/IRReader/IRReader.h"
3636
#include "llvm/InitializePasses.h"
37+
#include "llvm/Linker/Linker.h"
3738
#include "llvm/LinkAllIR.h"
3839
#include "llvm/LinkAllPasses.h"
3940
#include "llvm/MC/SubtargetFeature.h"
@@ -76,9 +77,9 @@ static cl::opt<std::string> PassPipeline(
7677

7778
// Other command line options...
7879
//
79-
static cl::opt<std::string>
80-
InputFilename(cl::Positional, cl::desc("<input bitcode file>"),
81-
cl::init("-"), cl::value_desc("filename"));
80+
static cl::list<std::string> // XXX EMSCRIPTEN: support multiple input files, link them
81+
InputFilenames(cl::Positional, cl::ZeroOrMore,
82+
cl::desc("<input bitcode files>"));
8283

8384
static cl::opt<std::string>
8485
OutputFilename("o", cl::desc("Override output filename"),
@@ -462,7 +463,40 @@ int main(int argc, char **argv) {
462463
SMDiagnostic Err;
463464

464465
// Load the input module...
465-
std::unique_ptr<Module> M = parseIRFile(InputFilename, Err, Context);
466+
std::unique_ptr<Module> M;
467+
468+
// XXX EMSCRIPTEN: support for multiple files
469+
if (InputFilenames.size() == 0)
470+
M = parseIRFile("-", Err, Context);
471+
else if (InputFilenames.size() == 1)
472+
M = parseIRFile(InputFilenames[0], Err, Context);
473+
else {
474+
// link them in
475+
M = nullptr;
476+
std::unique_ptr<Linker> L;
477+
478+
for (unsigned i = 0; i < InputFilenames.size(); ++i) {
479+
std::unique_ptr<Module> MM = parseIRFile(InputFilenames[i], Err, Context);
480+
if (!MM.get()) {
481+
errs() << argv[0] << ": error loading file '" <<InputFilenames[i]<< "'\n";
482+
return 1;
483+
}
484+
485+
if (!NoVerify && verifyModule(*MM, &errs())) {
486+
errs() << argv[0] << ": " << InputFilenames[i]
487+
<< ": error: input module is broken!\n";
488+
return 1;
489+
}
490+
491+
if (i == 0) {
492+
M.swap(MM);
493+
L = make_unique<Linker>(M.get());
494+
} else {
495+
if (L->linkInModule(MM.get()))
496+
return 1;
497+
}
498+
}
499+
}
466500

467501
if (!M) {
468502
Err.print(argv[0], errs());
@@ -477,7 +511,7 @@ int main(int argc, char **argv) {
477511
// pass pipelines. Otherwise we can crash on broken code during
478512
// doInitialization().
479513
if (!NoVerify && verifyModule(*M, &errs())) {
480-
errs() << argv[0] << ": " << InputFilename
514+
errs() << argv[0] << ": "
481515
<< ": error: input module is broken!\n";
482516
return 1;
483517
}

0 commit comments

Comments
 (0)