all repos — mgba @ 819062a9a587785547a25c73f1169ee33bc522e1

mGBA Game Boy Advance Emulator

Debugger: Add segment parsing
Jeffrey Pfau jeffrey@endrift.com
Tue, 23 Aug 2016 12:17:39 -0700
commit

819062a9a587785547a25c73f1169ee33bc522e1

parent

02419521335e8f58add9446f2a8fa6016d4f79bc

4 files changed, 52 insertions(+), 13 deletions(-)

jump to
M src/debugger/cli-debugger.csrc/debugger/cli-debugger.c

@@ -428,36 +428,49 @@ }

return current; } -static uint32_t _lookupIdentifier(struct mDebugger* debugger, const char* name, struct CLIDebugVector* dv) { +static void _lookupIdentifier(struct mDebugger* debugger, const char* name, struct CLIDebugVector* dv) { struct CLIDebugger* cliDebugger = (struct CLIDebugger*) debugger; if (cliDebugger->system) { uint32_t value = cliDebugger->system->lookupPlatformIdentifier(cliDebugger->system, name, dv); if (dv->type != CLIDV_ERROR_TYPE) { - return value; + dv->intValue = value; + return; } dv->type = CLIDV_INT_TYPE; value = cliDebugger->system->lookupIdentifier(cliDebugger->system, name, dv); if (dv->type != CLIDV_ERROR_TYPE) { - return value; + dv->intValue = value; + return; } } dv->type = CLIDV_ERROR_TYPE; - return 0; } -static uint32_t _evaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, struct CLIDebugVector* dv) { +static void _evaluateParseTree(struct mDebugger* debugger, struct ParseTree* tree, struct CLIDebugVector* dv) { + int32_t lhs, rhs; switch (tree->token.type) { case TOKEN_UINT_TYPE: - return tree->token.uintValue; + dv->intValue = tree->token.uintValue; + break; + case TOKEN_SEGMENT_TYPE: + _evaluateParseTree(debugger, tree->lhs, dv); + dv->segmentValue = dv->intValue; + _evaluateParseTree(debugger, tree->rhs, dv); + break; case TOKEN_OPERATOR_TYPE: - return _performOperation(tree->token.operatorValue, _evaluateParseTree(debugger, tree->lhs, dv), _evaluateParseTree(debugger, tree->rhs, dv), dv); + _evaluateParseTree(debugger, tree->lhs, dv); + lhs = dv->intValue; + _evaluateParseTree(debugger, tree->rhs, dv); + rhs = dv->intValue; + dv->intValue = _performOperation(tree->token.operatorValue, lhs, rhs, dv); + break; case TOKEN_IDENTIFIER_TYPE: - return _lookupIdentifier(debugger, tree->token.identifierValue, dv); + _lookupIdentifier(debugger, tree->token.identifierValue, dv); + break; case TOKEN_ERROR_TYPE: default: dv->type = CLIDV_ERROR_TYPE; } - return 0; } struct CLIDebugVector* CLIDVParse(struct CLIDebugger* debugger, const char* string, size_t length) {

@@ -465,7 +478,7 @@ if (!string || length < 1) {

return 0; } - struct CLIDebugVector dvTemp = { .type = CLIDV_INT_TYPE }; + struct CLIDebugVector dvTemp = { .type = CLIDV_INT_TYPE, .segmentValue = -1 }; struct LexVector lv = { .next = 0 }; size_t adjusted = lexExpression(&lv, string, length);

@@ -479,7 +492,7 @@ parseLexedExpression(&tree, &lv);

if (tree.token.type == TOKEN_ERROR_TYPE) { dvTemp.type = CLIDV_ERROR_TYPE; } else { - dvTemp.intValue = _evaluateParseTree(&debugger->d, &tree, &dvTemp); + _evaluateParseTree(&debugger->d, &tree, &dvTemp); } parseFree(tree.lhs);
M src/debugger/cli-debugger.hsrc/debugger/cli-debugger.h

@@ -20,11 +20,14 @@ struct CLIDebugVector* next;

enum CLIDVType { CLIDV_ERROR_TYPE, CLIDV_INT_TYPE, - CLIDV_CHAR_TYPE + CLIDV_CHAR_TYPE, } type; union { - int32_t intValue; char* charValue; + struct { + int32_t intValue; + int segmentValue; + }; }; };
M src/debugger/parser.csrc/debugger/parser.c

@@ -222,6 +222,17 @@ lv->token.uintValue = next;

lv = _lexOperator(lv, token); state = LEX_ROOT; break; + case ':': + lv->token.type = TOKEN_SEGMENT_TYPE; + lv->token.uintValue = next; + lvNext = malloc(sizeof(struct LexVector)); + lvNext->next = lv->next; + lvNext->token.type = TOKEN_UINT_TYPE; + lv->next = lvNext; + lv = lvNext; + next = 0; + state = LEX_EXPECT_HEX; + break; case ')': lv->token.type = TOKEN_UINT_TYPE; lv->token.uintValue = next;

@@ -353,6 +364,17 @@ lv = lv->next;

} else { tree->token.type = TOKEN_ERROR_TYPE; return 0; + } + break; + case TOKEN_SEGMENT_TYPE: + tree->lhs = _parseTreeCreate(); + tree->lhs->token.type = TOKEN_UINT_TYPE; + tree->lhs->token.uintValue = lv->token.uintValue; + tree->rhs = _parseTreeCreate(); + tree->token.type = TOKEN_SEGMENT_TYPE; + lv = _parseExpression(tree->rhs, lv->next, precedence, openParens); + if (tree->token.type == TOKEN_ERROR_TYPE) { + tree->token.type = TOKEN_ERROR_TYPE; } break; case TOKEN_OPEN_PAREN_TYPE:
M src/debugger/parser.hsrc/debugger/parser.h

@@ -36,6 +36,7 @@ TOKEN_IDENTIFIER_TYPE,

TOKEN_OPERATOR_TYPE, TOKEN_OPEN_PAREN_TYPE, TOKEN_CLOSE_PAREN_TYPE, + TOKEN_SEGMENT_TYPE, } type; union { uint32_t uintValue;