Use clipp for arg parsing
This commit is contained in:
		
							
								
								
									
										7024
									
								
								include/clipp.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										7024
									
								
								include/clipp.hpp
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| @@ -8,12 +8,14 @@ | ||||
| class Wassembler | ||||
| { | ||||
| private: | ||||
| 	Configuration config; | ||||
| 	Execute::VirtualMachine vm; | ||||
|  | ||||
| 	bool LoadLinesFromFile(std::string const & filePath, std::vector<std::string> & lines) const; | ||||
| 	bool LoadTokens(std::vector<std::string> const & lines, std::vector<Token::Token> & tokens) const; | ||||
|  | ||||
| public: | ||||
| 	void SetMemorySize(unsigned const size); | ||||
| 	bool LoadFromFile(std::string const & filePath); | ||||
|  | ||||
| 	void Run(); | ||||
|   | ||||
							
								
								
									
										17
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								src/main.cpp
									
									
									
									
									
								
							| @@ -1,16 +1,27 @@ | ||||
| #include <clipp.hpp> | ||||
| #include <cstdio> | ||||
| #include <iostream> | ||||
| #include <wassembler.hpp> | ||||
|  | ||||
| int main(int argc, char ** argv) | ||||
| { | ||||
| 	if (argc != 2) | ||||
| 	std::string inputFile; | ||||
| 	unsigned memorySize = 1024; | ||||
|  | ||||
| 	auto cli = ( | ||||
| 		clipp::value("input wasm file").set(inputFile), | ||||
| 		clipp::option("-m", "--memory-size") & clipp::value("memory size", memorySize) | ||||
| 	); | ||||
|  | ||||
| 	if (!clipp::parse(argc, argv, cli)) | ||||
| 	{ | ||||
| 		std::printf("Usage: %s [filename.wasm]\n", argv[0]); | ||||
| 		std::cout << clipp::make_man_page(cli, argv[0]); | ||||
| 		return 1; | ||||
| 	} | ||||
|  | ||||
| 	Wassembler wassembler; | ||||
| 	if (!wassembler.LoadFromFile(argv[1])) | ||||
| 	wassembler.SetMemorySize(memorySize); | ||||
| 	if (!wassembler.LoadFromFile(inputFile)) | ||||
| 	{ | ||||
| 		exit(1); | ||||
| 	} | ||||
|   | ||||
| @@ -79,6 +79,11 @@ bool Wassembler::LoadTokens(std::vector<std::string> const & lines, std::vector< | ||||
| 	return !(syntaxError || tokenizationError); | ||||
| } | ||||
|  | ||||
| void Wassembler::SetMemorySize(unsigned const size) | ||||
| { | ||||
| 	config.memorySize = size; | ||||
| } | ||||
|  | ||||
| bool Wassembler::LoadFromFile(std::string const & filePath) | ||||
| { | ||||
| 	std::vector<std::string> lines; | ||||
| @@ -108,8 +113,6 @@ bool Wassembler::LoadFromFile(std::string const & filePath) | ||||
| 	} | ||||
|  | ||||
| 	vm.LoadCode(std::move(codePtr)); | ||||
|  | ||||
| 	Configuration config; | ||||
| 	vm.LoadConfiguration(config); | ||||
|  | ||||
| 	return true; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user