Browse Source

Implement parsing indirect args; fix immediates.

master
Ben Kurtovic 9 years ago
parent
commit
83f4ab380f
4 changed files with 34 additions and 6 deletions
  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 View File

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


#pragma once #pragma once


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


typedef enum { typedef enum {


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

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

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


// AT_INDEXED // AT_INDEXED
// ASMArgIndexed index; // ASMArgIndexed index;


+ 32
- 2
src/assembler/parse_util.c View 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) 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; 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; return false;


int32_t sval = negative ? uval : -uval; 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. Read in a boolean argument from the given line and store it in *result.
*/ */
DIRECTIVE_PARSE_FUNC(bool, bool) DIRECTIVE_PARSE_FUNC(bool, bool)


+ 1
- 0
src/assembler/parse_util.h View 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_register(ASMArgRegister*, const char*, ssize_t);
bool argparse_condition(ASMArgCondition*, const char*, ssize_t); bool argparse_condition(ASMArgCondition*, const char*, ssize_t);
bool argparse_immediate(ASMArgImmediate*, const char*, ssize_t); bool argparse_immediate(ASMArgImmediate*, const char*, ssize_t);
bool argparse_indirect(ASMArgIndirect*, const char*, ssize_t);


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


Loading…
Cancel
Save