Merge pull request #133 from davidgiven/dtrg-mips

Allow constants >INT_MAX in mcg
This commit is contained in:
David Given 2018-09-22 17:30:52 +02:00 committed by GitHub
commit 1b60af4f0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View file

@ -8,6 +8,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <errno.h>
#include "em_arith.h" #include "em_arith.h"
#include "em_label.h" #include "em_label.h"
#include "em.h" #include "em.h"

View file

@ -211,6 +211,19 @@ static void data_block_label(const char* label)
} }
} }
static arith safe_atol(const char* s)
{
arith result;
errno = 0;
result = strtoul(s, NULL, 0);
if (errno == ERANGE)
result = strtol(s, NULL, 0);
if (errno == ERANGE)
fatal("constant '%s' not parseable", s);
return result;
}
static void parse_pseu(void) static void parse_pseu(void)
{ {
switch (em.em_opcode) switch (em.em_opcode)
@ -255,7 +268,7 @@ static void parse_pseu(void)
case ico_ptyp: case ico_ptyp:
case uco_ptyp: case uco_ptyp:
{ {
arith val = atol(em.em_string); arith val = safe_atol(em.em_string);
data_int(val, em.em_size, ro); data_int(val, em.em_size, ro);
data_block_int(val); data_block_int(val);
break; break;
@ -313,7 +326,7 @@ static void parse_pseu(void)
case ico_ptyp: case ico_ptyp:
case uco_ptyp: case uco_ptyp:
{ {
arith val = atol(em.em_string); arith val = safe_atol(em.em_string);
data_int(val, em.em_size, false); data_int(val, em.em_size, false);
break; break;
} }