summaryrefslogtreecommitdiff
path: root/tools/standalone_miri/main.cpp
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2018-05-19 08:09:14 +0800
committerJohn Hodge <tpg@mutabah.net>2018-05-19 08:09:14 +0800
commitaada4f2fe9be2f9bfadb4ef6ba057f36b9860aa8 (patch)
treeb62d2e8f707518eec23a1cfe3fde239d16b15650 /tools/standalone_miri/main.cpp
parent1320ff65f1fcce3cbd492eaf6f300ac81e2f8ae3 (diff)
downloadmrust-aada4f2fe9be2f9bfadb4ef6ba057f36b9860aa8.tar.gz
Standalone MIRI - Pass argv to the target
Diffstat (limited to 'tools/standalone_miri/main.cpp')
-rw-r--r--tools/standalone_miri/main.cpp46
1 files changed, 44 insertions, 2 deletions
diff --git a/tools/standalone_miri/main.cpp b/tools/standalone_miri/main.cpp
index 2011edfa..1755a9d7 100644
--- a/tools/standalone_miri/main.cpp
+++ b/tools/standalone_miri/main.cpp
@@ -14,10 +14,15 @@ struct ProgramOptions
{
::std::string infile;
//TODO: Architecture file
+ //::std::string archname;
//TODO: Loadable FFI descriptions
+ //::std::vector<const char*> ffi_api_files;
//TODO: Logfile
+ //::std::string logfile;
+ ::std::vector<const char*> args;
int parse(int argc, const char* argv[]);
+ void show_help(const char* prog) const;
};
int main(int argc, const char* argv[])
@@ -38,8 +43,19 @@ int main(int argc, const char* argv[])
argv_ty.wrappers.push_back(TypeWrapper { TypeWrapper::Ty::Pointer, 0 });
argv_ty.wrappers.push_back(TypeWrapper { TypeWrapper::Ty::Pointer, 0 });
auto val_argv = Value(argv_ty);
- val_argc.write_isize(0, 0);
+
+ // Create argc/argv based on input arguments
+ val_argc.write_isize(0, 1 + opts.args.size());
+ auto argv_alloc = Allocation::new_alloc((1 + opts.args.size()) * POINTER_SIZE);
+ argv_alloc->write_usize(0 * POINTER_SIZE, 0);
+ argv_alloc->relocations.push_back({ 0 * POINTER_SIZE, RelocationPtr::new_ffi(FFIPointer { "", (void*)(opts.infile.c_str()), opts.infile.size() + 1 }) });
+ for(size_t i = 0; i < opts.args.size(); i ++)
+ {
+ argv_alloc->write_usize((1 + i) * POINTER_SIZE, 0);
+ argv_alloc->relocations.push_back({ (1 + i) * POINTER_SIZE, RelocationPtr::new_ffi({ "", (void*)(opts.args[0]), ::std::strlen(opts.args[0]) + 1 }) });
+ }
val_argv.write_usize(0, 0);
+ val_argv.allocation->relocations.push_back({ 0 * POINTER_SIZE, RelocationPtr::new_alloc(argv_alloc) });
try
{
@@ -85,16 +101,37 @@ int ProgramOptions::parse(int argc, const char* argv[])
}
else
{
- // TODO: Too many free arguments
+ this->args.push_back(arg);
}
}
else if( arg[1] != '-' )
{
// Short
+ if( arg[2] != '\0' ) {
+ // Error?
+ }
+ switch(arg[1])
+ {
+ case 'h':
+ this->show_help(argv[0]);
+ exit(0);
+ default:
+ // TODO: Error
+ break;
+ }
}
else if( arg[2] != '\0' )
{
// Long
+ if( ::std::strcmp(arg, "--help") == 0 ) {
+ this->show_help(argv[0]);
+ exit(0);
+ }
+ //else if( ::std::strcmp(arg, "--api") == 0 ) {
+ //}
+ else {
+ // TODO: Error
+ }
}
else
{
@@ -103,3 +140,8 @@ int ProgramOptions::parse(int argc, const char* argv[])
}
return 0;
}
+
+void ProgramOptions::show_help(const char* prog) const
+{
+ ::std::cout << "USAGE: " << prog << " <infile> <... args>" << ::std::endl;
+}