2020-10-08 11:47:49 +03:00
|
|
|
#include "chibild.h"
|
2020-10-02 07:28:26 +03:00
|
|
|
#include "llvm/Option/ArgList.h"
|
|
|
|
|
2020-09-29 09:05:29 +03:00
|
|
|
#include <iostream>
|
|
|
|
|
2020-10-02 10:47:51 +03:00
|
|
|
using llvm::opt::InputArgList;
|
2020-10-02 07:28:26 +03:00
|
|
|
|
2020-10-02 10:47:51 +03:00
|
|
|
Config config;
|
2020-10-09 16:29:25 +03:00
|
|
|
SymbolTable symbol_table;
|
2020-10-02 07:28:26 +03:00
|
|
|
|
2020-10-04 12:00:33 +03:00
|
|
|
//
|
|
|
|
// Command-line option processing
|
|
|
|
//
|
|
|
|
|
2020-10-02 07:28:26 +03:00
|
|
|
// Create enum with OPT_xxx values for each option in Options.td
|
|
|
|
enum {
|
|
|
|
OPT_INVALID = 0,
|
|
|
|
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
|
|
|
|
#include "options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
2020-10-02 10:47:51 +03:00
|
|
|
// Create prefix string literals used in Options.td
|
|
|
|
#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
|
|
|
|
#include "options.inc"
|
|
|
|
#undef PREFIX
|
|
|
|
|
|
|
|
// Create table mapping all options defined in Options.td
|
|
|
|
static const llvm::opt::OptTable::Info opt_info[] = {
|
|
|
|
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
|
|
|
|
{X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
|
|
|
|
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
|
|
|
|
#include "options.inc"
|
|
|
|
#undef OPTION
|
|
|
|
};
|
|
|
|
|
|
|
|
class MyOptTable : llvm::opt::OptTable {
|
|
|
|
public:
|
|
|
|
MyOptTable() : OptTable(opt_info) {}
|
|
|
|
InputArgList parse(int argc, char **argv);
|
|
|
|
};
|
|
|
|
|
|
|
|
InputArgList MyOptTable::parse(int argc, char **argv) {
|
|
|
|
unsigned missingIndex;
|
|
|
|
unsigned missingCount;
|
|
|
|
SmallVector<const char *, 256> vec(argv, argv + argc);
|
|
|
|
|
|
|
|
InputArgList args = this->ParseArgs(vec, missingIndex, missingCount);
|
|
|
|
if (missingCount)
|
|
|
|
error(Twine(args.getArgString(missingIndex)) + ": missing argument");
|
|
|
|
|
|
|
|
for (auto *arg : args.filtered(OPT_UNKNOWN))
|
|
|
|
error("unknown argument '" + arg->getAsString(args) + "'");
|
|
|
|
return args;
|
|
|
|
}
|
|
|
|
|
2020-10-04 12:00:33 +03:00
|
|
|
//
|
|
|
|
// Main
|
|
|
|
//
|
|
|
|
|
2020-09-29 09:05:29 +03:00
|
|
|
int main(int argc, char **argv) {
|
2020-10-02 10:47:51 +03:00
|
|
|
MyOptTable opt_table;
|
2020-10-09 15:10:12 +03:00
|
|
|
InputArgList args = opt_table.parse(argc - 1, argv + 1);
|
2020-10-02 10:47:51 +03:00
|
|
|
|
2020-10-04 12:00:33 +03:00
|
|
|
if (auto *arg = args.getLastArg(OPT_o))
|
|
|
|
config.output = arg->getValue();
|
|
|
|
else
|
|
|
|
error("-o option is missing");
|
|
|
|
|
2020-10-09 14:47:45 +03:00
|
|
|
std::vector<ObjectFile *> files;
|
|
|
|
|
|
|
|
for (auto *arg : args) {
|
|
|
|
switch (arg->getOption().getID()) {
|
|
|
|
case OPT_INPUT: {
|
|
|
|
MemoryBufferRef mb = readFile(arg->getValue());
|
|
|
|
files.push_back(new ObjectFile(mb));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-09 15:10:12 +03:00
|
|
|
for (ObjectFile *file : files)
|
|
|
|
file->parse();
|
|
|
|
|
2020-10-04 12:00:33 +03:00
|
|
|
write();
|
2020-09-29 09:05:29 +03:00
|
|
|
return 0;
|
|
|
|
}
|