From d628150b7ceb31ff2aad170365bda652733e10ad Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Mon, 27 Jul 2020 20:54:27 +0200 Subject: asm-i386: tried to fix assignment --- ecomp-c/asm-i386.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/ecomp-c/asm-i386.c b/ecomp-c/asm-i386.c index ef3dba1..a79d03e 100644 --- a/ecomp-c/asm-i386.c +++ b/ecomp-c/asm-i386.c @@ -1462,6 +1462,7 @@ static OpcodeInfo *parseAssignment( void ) OpcodeInfo *opcode_info; OperandInfo *operand_info; Symbol *symbol; + ExpressionNode *node; opcode_info = Allocate( sizeof( OpcodeInfo ) ); opcode_info->addr = 0; @@ -1479,6 +1480,11 @@ static OpcodeInfo *parseAssignment( void ) } } symbol->defined = 1; + + node = create_expression_node( ); + node->type = EXPRESSION_NODE_TYPE_VAR; + node->symbol = symbol; + sym = getSym( ); Expect( S_equals ); @@ -1491,14 +1497,6 @@ static OpcodeInfo *parseAssignment( void ) append_operand( opcode_info, operand_info ); - /* TODO: symbols are only label, adresses for now, so we - * abuse it to store constants, we could also do lazy - * evaluation */ - /* TODO: make an assignment node, cannot evaluate here without - * current ORG and LC! - * symbol->addr = evaluateExpression( node ); - */ - return opcode_info; } @@ -1822,6 +1820,10 @@ static int compute_addresses( OpcodeInfo *opcode_info ) fprintf( stderr, "ORG/LC set to $%X\n", LC ); } break; + + case OPCODE_PSEUDO_ASSIGN: + opcode->operand->node->left->symbol->addr = evaluateExpression( opcode->operand->node->right, ORG, LC ); + break; case OPCODE_PSEUDO_DD: case OPCODE_PSEUDO_DW: @@ -1915,12 +1917,12 @@ static void generate_code( OpcodeInfo *opcode_info ) fputs( "labels:\n", stderr ); print_labels( symbol ); } - check_for_undefined_labels( symbol ); has_to_relocate = patchup_addresses( opcode_info, ORG ); } while( has_to_relocate ); compute_addresses( opcode_info ); pass++; + check_for_undefined_labels( symbol ); if( DEBUG_PARSER ) { fprintf( stderr, "-- pass %d\n", pass ); fputs( "code:\n", stderr ); @@ -2137,6 +2139,8 @@ static void emit_opcode( OpcodeInfo *opcode_info ) case OPCODE_RET: Emit( "%c", 0xC3 ); break; + case OPCODE_PSEUDO_ASSIGN: + break; default: Abort( "Opcode '%s' has not been implemented when generating binary", opcodename[opcode_info->opcode] ); -- cgit v1.2.3-54-g00ecf