| 11303 | } |
| 11304 | |
| 11305 | BfInlineAsmStatement* BfReducer::CreateInlineAsmStatement(BfAstNode* asmNode) |
| 11306 | { |
| 11307 | auto asmToken = BfNodeDynCast<BfTokenNode>(asmNode); |
| 11308 | auto nextNode = mVisitorPos.GetNext(); |
| 11309 | auto blockNode = BfNodeDynCast<BfInlineAsmStatement>(nextNode); |
| 11310 | if (blockNode == NULL) |
| 11311 | return (BfInlineAsmStatement*)Fail("Expected inline assembly block", asmNode); |
| 11312 | |
| 11313 | ReplaceNode(asmToken, blockNode); |
| 11314 | |
| 11315 | BfInlineAsmStatement* asmStatement = (BfInlineAsmStatement*)blockNode; |
| 11316 | |
| 11317 | { |
| 11318 | auto processInstrNodes = [&](const Array<BfAstNode*>& nodes) -> BfInlineAsmInstruction* |
| 11319 | { |
| 11320 | int nodeCount = (int)nodes.size(); |
| 11321 | int curNodeIdx = 0; |
| 11322 | |
| 11323 | auto instNode = mAlloc->Alloc<BfInlineAsmInstruction>(); |
| 11324 | //instNode->mSource = asmStatement->mSource; |
| 11325 | int srcStart = nodes.front()->GetSrcStart(); |
| 11326 | int srcEnd = nodes.back()->GetSrcEnd(); |
| 11327 | instNode->Init(srcStart, srcStart, srcEnd); |
| 11328 | |
| 11329 | auto replaceWithLower = [](String& s) |
| 11330 | { |
| 11331 | std::transform(s.begin(), s.end(), s.begin(), ::tolower); |
| 11332 | }; |
| 11333 | |
| 11334 | auto readIdent = [&](String& outStr, bool forceLowerCase, const StringImpl& errorExpectation, bool peekOnly) -> bool |
| 11335 | { |
| 11336 | if (curNodeIdx >= nodeCount) |
| 11337 | { |
| 11338 | if (!peekOnly) |
| 11339 | Fail(StrFormat("Expected %s", errorExpectation.c_str()), instNode); |
| 11340 | return false; |
| 11341 | } |
| 11342 | BfAstNode* curNode = nodes[curNodeIdx]; |
| 11343 | if (!peekOnly) |
| 11344 | ++curNodeIdx; |
| 11345 | if (!BfNodeDynCast<BfIdentifierNode>(curNode)) |
| 11346 | { |
| 11347 | if (!peekOnly) |
| 11348 | Fail(StrFormat("Found \"%s\", expected %s", NodeToString(curNode).c_str(), errorExpectation.c_str()), instNode); |
| 11349 | return false; |
| 11350 | } |
| 11351 | |
| 11352 | outStr = NodeToString(curNode); |
| 11353 | if (forceLowerCase) |
| 11354 | replaceWithLower(outStr); |
| 11355 | return true; |
| 11356 | }; |
| 11357 | auto readToken = [&](BfToken tokenType, const StringImpl& errorExpectation, bool peekOnly) -> bool |
| 11358 | { |
| 11359 | if (curNodeIdx >= nodeCount) |
| 11360 | { |
| 11361 | if (!peekOnly) |
| 11362 | Fail(StrFormat("Expected %s", errorExpectation.c_str()), instNode); |
nothing calls this directly
no test coverage detected