ctr: Encode negative integers in normal hex notation

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2019-08-22 13:06:15 -04:00
parent 7d014933ce
commit ff7be3e026
2 changed files with 6 additions and 15 deletions

View File

@ -84,11 +84,10 @@ class HandleEnumerations:
enums[name] = value enums[name] = value
def decl_enumeration(self, req): def decl_enumeration(self, req):
enum, name, value = req.split()[1:] enum, name, value = req.split()[1:]
self.add_enumeration(enum, name, decode_integer(value)) self.add_enumeration(enum, name, int(value, 0))
def decl_enumeration_range(self, req): def decl_enumeration_range(self, req):
enum, name, value, count = req.split()[1:] enum, name, value, count = req.split()[1:]
vc = (decode_integer(value), decode_integer(count)) self.add_enumeration(enum, name, (int(value, 0), int(count, 0)))
self.add_enumeration(enum, name, vc)
def decl_static_str(self, req): def decl_static_str(self, req):
msg = req.split(None, 1)[1] msg = req.split(None, 1)[1]
if msg not in self.static_strings: if msg not in self.static_strings:
@ -120,15 +119,6 @@ Handlers.append(HandlerEnumerations)
# Constants # Constants
###################################################################### ######################################################################
def decode_integer(value):
value = value.strip()
if len(value) != 11 or value[0] not in '-+' or value[1:3] != '0x':
error("Invalid encoded integer '%s'" % (value,))
out = int(value[1:], 0)
if value[0] == '-':
out -= 1<<32
return out
# Allow adding build time constants to the data dictionary # Allow adding build time constants to the data dictionary
class HandleConstants: class HandleConstants:
def __init__(self): def __init__(self):
@ -143,7 +133,7 @@ class HandleConstants:
self.constants[name] = value self.constants[name] = value
def decl_constant(self, req): def decl_constant(self, req):
name, value = req.split()[1:] name, value = req.split()[1:]
self.set_value(name, decode_integer(value)) self.set_value(name, int(value, 0))
def decl_constant_str(self, req): def decl_constant_str(self, req):
name, value = req.split(None, 2)[1:] name, value = req.split(None, 2)[1:]
value = value.strip() value = value.strip()
@ -217,7 +207,7 @@ class Handle_arm_irq:
self.ctr_dispatch = { 'DECL_ARMCM_IRQ': self.decl_armcm_irq } self.ctr_dispatch = { 'DECL_ARMCM_IRQ': self.decl_armcm_irq }
def decl_armcm_irq(self, req): def decl_armcm_irq(self, req):
func, num = req.split()[1:] func, num = req.split()[1:]
num = decode_integer(num) num = int(num, 0)
if num in self.irqs and self.irqs[num] != func: if num in self.irqs and self.irqs[num] != func:
error("Conflicting IRQ definition %d (old %s new %s)" error("Conflicting IRQ definition %d (old %s new %s)"
% (num, self.irqs[num], func)) % (num, self.irqs[num], func))

View File

@ -16,7 +16,8 @@
// Macro to encode an integer for use with DECL_CTR_INT() // Macro to encode an integer for use with DECL_CTR_INT()
#define _CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0') #define _CTR_HEX(H) ((H) > 9 ? (H) - 10 + 'A' : (H) + '0')
#define _CTR_INT(V, S) _CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f) #define _CTR_SHIFT(V, S) _CTR_HEX(((uint32_t)(V) >> (S)) & 0x0f)
#define _CTR_INT(V, S) ((V) < 0 ? _CTR_SHIFT(-(V), (S)) : _CTR_SHIFT((V), (S)))
#define CTR_INT(VALUE) { \ #define CTR_INT(VALUE) { \
' ', (VALUE) < 0 ? '-' : '+', '0', 'x', \ ' ', (VALUE) < 0 ? '-' : '+', '0', 'x', \
_CTR_INT((VALUE),28), _CTR_INT((VALUE),24), \ _CTR_INT((VALUE),28), _CTR_INT((VALUE),24), \