Skip to content
Permalink
Browse files

Clean up -definelabel and exit code checking (tentative)

  • Loading branch information
Prof9 committed Feb 9, 2020
1 parent e8edb73 commit d0b509b8bf3a583d5be6e92d0a97b3b23635dc4d
Showing with 42 additions and 38 deletions.
  1. +2 −0 CMakeLists.txt
  2. +2 −0 Core/Assembler.h
  3. +6 −23 Main/Tests.cpp
  4. +31 −14 Main/main.cpp
  5. +1 −1 Main/main.h
@@ -130,6 +130,7 @@ add_library(armips STATIC

add_executable(armips-bin
Main/main.cpp
Main/main.h
Main/Tests.cpp
Main/Tests.h
stdafx.cpp
@@ -140,6 +141,7 @@ set_target_properties(armips-bin PROPERTIES OUTPUT_NAME armips)

add_executable(armipstests
Main/main.cpp
Main/main.h
Main/Tests.cpp
Main/Tests.h
stdafx.cpp
@@ -36,6 +36,7 @@ struct ArmipsArguments
std::wstring inputFileName;
std::wstring tempFileName;
std::wstring symFileName;
bool useAbsoluteFileNames;

// memory mode
std::shared_ptr<AssemblerFile> memoryFile;
@@ -47,6 +48,7 @@ struct ArmipsArguments
errorOnWarning = false;
silent = false;
errorsResult = nullptr;
useAbsoluteFileNames = true;
}
};

@@ -150,6 +150,7 @@ bool TestRunner::executeTest(const std::wstring& dir, const std::wstring& testNa
int retVal = 0;
bool checkRetVal = false;
bool result = true;
StringList params;

if (fileExists(L"commandLine.txt"))
{
@@ -158,24 +159,12 @@ bool TestRunner::executeTest(const std::wstring& dir, const std::wstring& testNa
std::wstring command = f.readLine();
f.close();

StringList argv = splitStringIntoStringList(command,L' ',true);
params = splitStringIntoStringList(command,L' ',true);
checkRetVal = true;

// first word is error code, rest is arguments
expectedRetVal = std::stoi(argv[0]);
retVal = parseArguments(argv,args,1,false);

// if exit code is already nonzero, we would abort here
if (retVal != 0)
{
if (retVal != expectedRetVal)
{
errorString += formatString(L"Exit code did not match while parsing arguments: expected %S, got %S\n",expectedRetVal,retVal);
result = false;
}
// already checked exit code
checkRetVal = false;
}
expectedRetVal = std::stoi(params[0]);
params.erase(params.begin());
}
else
{
@@ -185,16 +174,10 @@ bool TestRunner::executeTest(const std::wstring& dir, const std::wstring& testNa

args.errorsResult = &errors;
args.silent = true;
args.useAbsoluteFileNames = false;

// may or may not be supposed to cause errors
if (runArmips(args) == false)
{
retVal = 1;
}
else
{
retVal = 0;
}
retVal = parseAndRunArmips(params, args);

if (checkRetVal && retVal != expectedRetVal)
{
@@ -13,6 +13,8 @@
#define ARMIPSNAME "ARMIPS"
#endif

static bool parseArguments(StringList& arguments, ArmipsArguments& parameters);

void printUsage(std::wstring executableName)
{
Logger::printLine(L"%s Assembler v%d.%d.%d (%s %s) by Kingcom",
@@ -37,8 +39,6 @@ int wmain(int argc, wchar_t* argv[])
{
std::setlocale(LC_CTYPE,"");

ArmipsArguments parameters;

#ifdef ARMIPS_TESTS
std::wstring name;

@@ -49,22 +49,39 @@ int wmain(int argc, wchar_t* argv[])
#endif

StringList arguments = getStringListFromArray(argv,argc);
int retval = parseArguments(arguments,parameters,1);
if (retval) return retval;
ArmipsArguments parameters;

bool result = runArmips(parameters);
return parseAndRunArmips(arguments, parameters);
}

int parseAndRunArmips(StringList& arguments, ArmipsArguments& parameters)
{
bool result;

result = parseArguments(arguments, parameters);
if (result == false)
{
Logger::printLine(L"Aborting.");
if (!parameters.silent)
Logger::printLine(L"Cannot parse arguments; aborting.");

return 1;
}

result = runArmips(parameters);
if (result == false)
{
if (!parameters.silent)
Logger::printLine(L"Aborting.");

return 1;
}

return 0;
}

int parseArguments(StringList& arguments, ArmipsArguments& parameters, size_t argpos, bool absolute)
static bool parseArguments(StringList& arguments, ArmipsArguments& parameters)
{
size_t argpos = 0;
bool readflags = true;
while (argpos < arguments.size())
{
@@ -128,7 +145,7 @@ int parseArguments(StringList& arguments, ArmipsArguments& parameters, size_t ar
{
Logger::printError(Logger::Error, L"Invalid definelabel value '%s'\n", arguments[argpos + 2]);
printUsage(arguments[0]);
return 1;
return false;
}
def.value = value;

@@ -137,7 +154,7 @@ int parseArguments(StringList& arguments, ArmipsArguments& parameters, size_t ar
} else {
Logger::printError(Logger::Error, L"Invalid command line argument '%s'\n", arguments[argpos]);
printUsage(arguments[0]);
return 1;
return false;
}
} else {
// only allow one input filename
@@ -148,7 +165,7 @@ int parseArguments(StringList& arguments, ArmipsArguments& parameters, size_t ar
} else {
Logger::printError(Logger::Error, L"Multiple input assembly files specified\n");
printUsage(arguments[0]);
return 1;
return false;
}
}
}
@@ -160,19 +177,19 @@ int parseArguments(StringList& arguments, ArmipsArguments& parameters, size_t ar
Logger::printError(Logger::Error, L"Missing input assembly file\n");

printUsage(arguments[0]);
return 1;
return false;
}

// turn input filename into an absolute path
if (absolute && isAbsolutePath(parameters.inputFileName) == false)
if (parameters.useAbsoluteFileNames && isAbsolutePath(parameters.inputFileName) == false)
parameters.inputFileName = formatString(L"%s/%s", getCurrentDirectory(), parameters.inputFileName);

if (fileExists(parameters.inputFileName) == false)
{
Logger::printError(Logger::Error, L"File '%s' not found\n", parameters.inputFileName);
return 1;
return false;
}
return 0;
return true;
}

#ifndef _WIN32
@@ -1,4 +1,4 @@
#pragma once
#include "Core/Assembler.h"

int parseArguments(StringList& arguments, ArmipsArguments& parameters, size_t argpos, bool absolute = true);
int parseAndRunArmips(StringList& arguments, ArmipsArguments& parameters);

0 comments on commit d0b509b

Please sign in to comment.
You can’t perform that action at this time.