void Parser::addEquation(const Token& startToken, const std::wstring& name, const std::wstring& value) { // parse value string TextFile f; f.openMemory(value); FileTokenizer tok; tok.init(&f); TokenizerPosition start = tok.getPosition(); while (tok.atEnd() == false) { const Token& token = tok.nextToken(); if (token.type == TokenType::Identifier && token.getStringValue() == name) { printError(startToken,L"Recursive enum definition for \"%s\" not allowed",name); return; } } // extract tokens TokenizerPosition end = tok.getPosition(); std::vector<Token> tokens = tok.getTokens(start, end); size_t index = Tokenizer::addEquValue(tokens); for (FileEntry& entry : entries) entry.tokenizer->resetLookaheadCheckMarks(); // register equation Global.symbolTable.addEquation(name, Global.FileInfo.FileNum, Global.Section, index); }
CAssemblerCommand* Parser::parseString(const std::wstring& text) { TextFile file; file.openMemory(text); return parseFile(file,true); }
bool runArmips(ArmipsArguments& arguments) { // initialize and reset global data Global.Radix = 10; Global.Revalidate = true; Global.Section = 0; Global.nocash = false; Global.IncludeNestingLevel = 0; Global.MacroNestingLevel = 0; Global.FileInfo.FileCount = 0; Global.FileInfo.TotalLineCount = 0; Global.DebugMessages = 0; Global.relativeInclude = false; Global.validationPasses = 0; Global.multiThreading = true; Arch = &InvalidArchitecture; Tokenizer::clearEquValues(); Logger::clear(); Global.symData.clear(); Global.Table.clear(); Global.symbolTable.clear(); Global.tempData.clear(); Global.FileInfo.FileList.clear(); Global.FileInfo.FileCount = 0; Global.FileInfo.TotalLineCount = 0; Global.FileInfo.LineNumber = 0; Global.FileInfo.FileNum = 0; Arm.clear(); // process arguments Parser parser; Logger::setSilent(arguments.silent); Logger::setErrorOnWarning(arguments.errorOnWarning); if (!arguments.symFileName.empty()) Global.symData.setNocashSymFileName(arguments.symFileName,arguments.symFileVersion); if (!arguments.tempFileName.empty()) Global.tempData.setFileName(arguments.tempFileName); Token token; for (size_t i = 0; i < arguments.equList.size(); i++) { parser.addEquation(token,arguments.equList[i].name, arguments.equList[i].value); } Global.symbolTable.addLabels(arguments.labels); if (Logger::hasError()) return false; // run assembler TextFile input; switch (arguments.mode) { case ArmipsMode::FILE: Global.memoryMode = false; if (input.open(arguments.inputFileName,TextFile::Read) == false) { Logger::printError(Logger::Error,L"Could not open file"); return false; } break; case ArmipsMode::MEMORY: Global.memoryMode = true; Global.memoryFile = arguments.memoryFile; input.openMemory(arguments.content); break; } CAssemblerCommand* content = parser.parseFile(input); bool result = !Logger::hasError(); if (result == true && content != nullptr) result = encodeAssembly(content); else if (g_fileManager->hasOpenFile()) { if (!Global.memoryMode) Logger::printError(Logger::Warning,L"File not closed"); g_fileManager->closeFile(); } // return errors if (arguments.errorsResult != NULL) { StringList errors = Logger::getErrors(); for (size_t i = 0; i < errors.size(); i++) arguments.errorsResult->push_back(errors[i]); } return result; }