Skip to content

Commit

Permalink
DSPTool: Factor out assembly file retrieval
Browse files Browse the repository at this point in the history
Keeps the retrieval behavior isolated and lessens the amount of
variables within PerformAssembly's scope.
  • Loading branch information
lioncash committed Jun 22, 2018
1 parent 77f6e50 commit f62dffa
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions Source/DSPTool/DSPTool.cpp
Expand Up @@ -2,7 +2,11 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.

#include "Common/Common.h"
#include <string>
#include <utility>
#include <vector>

#include "Common/CommonTypes.h"
#include "Common/FileUtil.h"
#include "Common/StringUtil.h"
#include "Core/DSP/DSPCodeUtil.h"
Expand Down Expand Up @@ -235,6 +239,23 @@ static bool PerformDisassembly(const std::string& input_name, const std::string&
return true;
}

static std::vector<std::string> GetAssemblerFiles(const std::string& source)
{
std::vector<std::string> files;
std::size_t last_pos = 0;
std::size_t pos = 0;

while ((pos = source.find('\n', last_pos)) != std::string::npos)
{
std::string temp = source.substr(last_pos, pos - last_pos);
if (!temp.empty())
files.push_back(std::move(temp));
last_pos = pos + 1;
}

return files;
}

static bool PerformAssembly(const std::string& input_name, const std::string& output_name,
const std::string& output_header_name, bool multiple, bool force,
bool output_size)
Expand All @@ -250,34 +271,23 @@ static bool PerformAssembly(const std::string& input_name, const std::string& ou
{
if (multiple)
{
source.append("\n");

// When specifying a list of files we must compile a header
// (we can't assemble multiple files to one binary)
// since we checked it before, we assume output_header_name isn't empty
int lines;
std::vector<u16>* codes;
std::vector<std::string> files;
std::string header, currentSource;
size_t lastPos = 0, pos = 0;

source.append("\n");

while ((pos = source.find('\n', lastPos)) != std::string::npos)
{
std::string temp = source.substr(lastPos, pos - lastPos);
if (!temp.empty())
files.push_back(temp);
lastPos = pos + 1;
}

lines = (int)files.size();
std::string header;
std::string currentSource;
const std::vector<std::string> files = GetAssemblerFiles(source);

int lines = static_cast<int>(files.size());
if (lines == 0)
{
printf("ERROR: Must specify at least one file\n");
return false;
}

codes = new std::vector<u16>[lines];
std::vector<u16>* codes = new std::vector<u16>[lines];

for (int i = 0; i < lines; i++)
{
Expand Down

0 comments on commit f62dffa

Please sign in to comment.