Sfoglia il codice sorgente

Implement parsing indirect args; fix immediates.

master
Ben Kurtovic 9 anni fa
parent
commit
83f4ab380f
4 ha cambiato i file con 34 aggiunte e 6 eliminazioni
  1. +0
    -1
      src/assembler/inst_args.h
  2. +1
    -3
      src/assembler/instructions.c
  3. +32
    -2
      src/assembler/parse_util.c
  4. +1
    -0
      src/assembler/parse_util.h

+ 0
- 1
src/assembler/inst_args.h Vedi File

@@ -3,7 +3,6 @@

#pragma once

#include <stdbool.h>
#include <stdint.h>

typedef enum {


+ 1
- 3
src/assembler/instructions.c Vedi File

@@ -155,9 +155,7 @@ static ASMErrorDesc parse_arg(
DEBUG("parse_arg(): -->%.*s<-- %zu", (int) size, str, size)
USE_PARSER(register, AT_REGISTER, reg)
USE_PARSER(immediate, AT_IMMEDIATE, imm)

// AT_INDIRECT
// ASMArgIndirect indirect;
USE_PARSER(indirect, AT_INDIRECT, indirect)

// AT_INDEXED
// ASMArgIndexed index;


+ 32
- 2
src/assembler/parse_util.c Vedi File

@@ -230,7 +230,7 @@ bool argparse_register(ASMArgRegister *result, const char *arg, ssize_t size)
}

/*
Read in a register argument and store it in *result.
Read in a condition argument and store it in *result.
*/
bool argparse_condition(ASMArgCondition *result, const char *arg, ssize_t size)
{
@@ -283,7 +283,7 @@ bool argparse_immediate(ASMArgImmediate *result, const char *arg, ssize_t size)
}

uint32_t uval;
if (parse_uint32_t(&uval, arg, size) && uval > UINT16_MAX)
if (!parse_uint32_t(&uval, arg, size) || uval > UINT16_MAX)
return false;

int32_t sval = negative ? uval : -uval;
@@ -314,6 +314,36 @@ bool argparse_immediate(ASMArgImmediate *result, const char *arg, ssize_t size)
}

/*
Read in an indirect argument and store it in *result.
*/
bool argparse_indirect(ASMArgIndirect *result, const char *arg, ssize_t size)
{
if (size < 3)
return false;
if (arg[0] != '(' || arg[size - 1] != ')')
return false;
arg++;
size -= 2;

ASMArgRegister reg;
ASMArgImmediate imm;
if (argparse_register(&reg, arg, size)) {
if (reg == REG_BC || reg == REG_DE || reg == REG_HL) {
result->type = AT_REGISTER;
result->addr.reg = reg;
return true;
}
} else if (argparse_immediate(&imm, arg, size)) {
if (imm.mask & IMM_U16) {
result->type = AT_IMMEDIATE;
result->addr.imm = imm;
return true;
}
}
return false;
}

/*
Read in a boolean argument from the given line and store it in *result.
*/
DIRECTIVE_PARSE_FUNC(bool, bool)


+ 1
- 0
src/assembler/parse_util.h Vedi File

@@ -23,6 +23,7 @@ bool parse_bytes(uint8_t**, size_t*, const char*, ssize_t);
bool argparse_register(ASMArgRegister*, const char*, ssize_t);
bool argparse_condition(ASMArgCondition*, const char*, ssize_t);
bool argparse_immediate(ASMArgImmediate*, const char*, ssize_t);
bool argparse_indirect(ASMArgIndirect*, const char*, ssize_t);

/* Preprocessor directive parsers */
bool dparse_bool(bool*, const ASMLine*, const char*);


Caricamento…
Annulla
Salva