aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2019-08-22 13:06:15 -0400
committerKevin O'Connor <kevin@koconnor.net>2019-08-22 13:06:44 -0400
commitff7be3e0261e844c81ae1d4c3f016c0b9dd75b77 (patch)
tree180ff9c6f78854223e498b50d5d7074542ff5271
parent7d014933cea167043b0347e8d49f0fa36762c45a (diff)
downloadkutter-ff7be3e0261e844c81ae1d4c3f016c0b9dd75b77.tar.gz
kutter-ff7be3e0261e844c81ae1d4c3f016c0b9dd75b77.tar.xz
kutter-ff7be3e0261e844c81ae1d4c3f016c0b9dd75b77.zip
ctr: Encode negative integers in normal hex notation
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--scripts/buildcommands.py18
-rw-r--r--src/ctr.h3
2 files changed, 6 insertions, 15 deletions
diff --git a/scripts/buildcommands.py b/scripts/buildcommands.py
index 956554b2..ef438e0f 100644
--- a/scripts/buildcommands.py
+++ b/scripts/buildcommands.py
@@ -84,11 +84,10 @@ class HandleEnumerations:
enums[name] = value
def decl_enumeration(self, req):
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):
enum, name, value, count = req.split()[1:]
- vc = (decode_integer(value), decode_integer(count))
- self.add_enumeration(enum, name, vc)
+ self.add_enumeration(enum, name, (int(value, 0), int(count, 0)))
def decl_static_str(self, req):
msg = req.split(None, 1)[1]
if msg not in self.static_strings:
@@ -120,15 +119,6 @@ Handlers.append(HandlerEnumerations)
# 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
class HandleConstants:
def __init__(self):
@@ -143,7 +133,7 @@ class HandleConstants:
self.constants[name] = value
def decl_constant(self, req):
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):
name, value = req.split(None, 2)[1:]
value = value.strip()
@@ -217,7 +207,7 @@ class Handle_arm_irq:
self.ctr_dispatch = { 'DECL_ARMCM_IRQ': self.decl_armcm_irq }
def decl_armcm_irq(self, req):
func, num = req.split()[1:]
- num = decode_integer(num)
+ num = int(num, 0)
if num in self.irqs and self.irqs[num] != func:
error("Conflicting IRQ definition %d (old %s new %s)"
% (num, self.irqs[num], func))
diff --git a/src/ctr.h b/src/ctr.h
index b5b56ee2..4032e268 100644
--- a/src/ctr.h
+++ b/src/ctr.h
@@ -16,7 +16,8 @@
// Macro to encode an integer for use with DECL_CTR_INT()
#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) { \
' ', (VALUE) < 0 ? '-' : '+', '0', 'x', \
_CTR_INT((VALUE),28), _CTR_INT((VALUE),24), \