2016-12-28 20:32:00 +00:00
|
|
|
// ACME - a crossassembler for producing 6502/65c02/65816/65ce02 code.
|
2020-04-28 16:02:09 +00:00
|
|
|
// Copyright (C) 1998-2020 Marco Baye
|
2014-06-02 00:47:46 +00:00
|
|
|
// Have a look at "acme.c" for further info
|
|
|
|
//
|
2014-12-22 00:47:52 +00:00
|
|
|
// type system stuff
|
2014-06-02 00:47:46 +00:00
|
|
|
#include "typesystem.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include "alu.h"
|
|
|
|
#include "global.h"
|
|
|
|
|
|
|
|
|
2020-05-06 12:27:32 +00:00
|
|
|
static boolean in_address_block = FALSE;
|
|
|
|
static boolean in_address_statement = FALSE;
|
2014-06-02 00:47:46 +00:00
|
|
|
|
|
|
|
// Functions
|
|
|
|
|
2020-05-06 12:27:32 +00:00
|
|
|
// return whether explicit symbol definitions should force "address" mode
|
|
|
|
boolean typesystem_says_address(void)
|
2014-06-02 00:47:46 +00:00
|
|
|
{
|
2020-05-06 12:27:32 +00:00
|
|
|
return in_address_block || in_address_statement;
|
2014-06-02 00:47:46 +00:00
|
|
|
}
|
|
|
|
|
2020-05-06 12:27:32 +00:00
|
|
|
// parse a block while forcing address mode
|
2014-06-02 00:47:46 +00:00
|
|
|
void typesystem_force_address_block(void)
|
|
|
|
{
|
2020-05-06 12:27:32 +00:00
|
|
|
boolean buffer = in_address_block;
|
2014-06-02 00:47:46 +00:00
|
|
|
|
|
|
|
in_address_block = TRUE;
|
|
|
|
Parse_optional_block();
|
|
|
|
in_address_block = buffer;
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:27:32 +00:00
|
|
|
// force address mode on or off for the next statement
|
|
|
|
void typesystem_force_address_statement(boolean value)
|
2014-06-02 00:47:46 +00:00
|
|
|
{
|
|
|
|
in_address_statement = value;
|
|
|
|
}
|
|
|
|
|
2020-05-06 12:27:32 +00:00
|
|
|
// warn if result is not integer
|
2020-04-28 16:02:09 +00:00
|
|
|
void typesystem_want_imm(struct number *result)
|
2014-06-02 00:47:46 +00:00
|
|
|
{
|
2017-10-29 23:29:07 +00:00
|
|
|
if (!config.warn_on_type_mismatch)
|
2014-06-02 00:47:46 +00:00
|
|
|
return;
|
2020-04-28 16:02:09 +00:00
|
|
|
|
|
|
|
if (!(result->flags & NUMBER_IS_DEFINED))
|
2014-06-02 00:47:46 +00:00
|
|
|
return;
|
2020-04-28 16:02:09 +00:00
|
|
|
|
2015-06-14 23:16:23 +00:00
|
|
|
if (result->addr_refs != 0) {
|
2014-06-02 00:47:46 +00:00
|
|
|
Throw_warning("Wrong type - expected integer.");
|
2015-06-14 23:16:23 +00:00
|
|
|
//printf("refcount should be 0, but is %d\n", result->addr_refs);
|
|
|
|
}
|
2014-06-02 00:47:46 +00:00
|
|
|
}
|
2020-05-06 12:27:32 +00:00
|
|
|
// warn if result is not address
|
2020-04-28 16:02:09 +00:00
|
|
|
void typesystem_want_addr(struct number *result)
|
2014-06-02 00:47:46 +00:00
|
|
|
{
|
2017-10-29 23:29:07 +00:00
|
|
|
if (!config.warn_on_type_mismatch)
|
2014-06-02 00:47:46 +00:00
|
|
|
return;
|
2020-04-28 16:02:09 +00:00
|
|
|
|
|
|
|
if (!(result->flags & NUMBER_IS_DEFINED))
|
2014-06-02 00:47:46 +00:00
|
|
|
return;
|
2020-04-28 16:02:09 +00:00
|
|
|
|
2015-06-14 23:16:23 +00:00
|
|
|
if (result->addr_refs != 1) {
|
2014-06-02 00:47:46 +00:00
|
|
|
Throw_warning("Wrong type - expected address.");
|
2015-06-14 23:16:23 +00:00
|
|
|
//printf("refcount should be 1, but is %d\n", result->addr_refs);
|
|
|
|
}
|
2014-06-02 00:47:46 +00:00
|
|
|
}
|