summaryrefslogtreecommitdiff
path: root/py/emitinlinethumb.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/emitinlinethumb.c')
-rw-r--r--py/emitinlinethumb.c70
1 files changed, 41 insertions, 29 deletions
diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c
index 47ed14321..1faeccbd2 100644
--- a/py/emitinlinethumb.c
+++ b/py/emitinlinethumb.c
@@ -39,14 +39,14 @@ typedef enum {
// define rules with a compile function
#define DEF_RULE(rule, comp, kind, ...) PN_##rule,
#define DEF_RULE_NC(rule, kind, ...)
-#include "py/grammar.h"
+ #include "py/grammar.h"
#undef DEF_RULE
#undef DEF_RULE_NC
PN_const_object, // special node for a constant, generic Python object
// define rules without a compile function
#define DEF_RULE(rule, comp, kind, ...)
#define DEF_RULE_NC(rule, kind, ...) PN_##rule,
-#include "py/grammar.h"
+ #include "py/grammar.h"
#undef DEF_RULE
#undef DEF_RULE_NC
} pn_kind_t;
@@ -131,7 +131,9 @@ STATIC bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num
return true;
}
-typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t;
+typedef struct _reg_name_t { byte reg;
+ byte name[3];
+} reg_name_t;
STATIC const reg_name_t reg_name_table[] = {
{0, "r0\0"},
{1, "r1\0"},
@@ -157,7 +159,9 @@ STATIC const reg_name_t reg_name_table[] = {
};
#define MAX_SPECIAL_REGISTER_NAME_LENGTH 7
-typedef struct _special_reg_name_t { byte reg; char name[MAX_SPECIAL_REGISTER_NAME_LENGTH + 1]; } special_reg_name_t;
+typedef struct _special_reg_name_t { byte reg;
+ char name[MAX_SPECIAL_REGISTER_NAME_LENGTH + 1];
+} special_reg_name_t;
STATIC const special_reg_name_t special_reg_name_table[] = {
{5, "IPSR"},
{17, "BASEPRI"},
@@ -226,8 +230,8 @@ STATIC mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_pars
}
if (regno > 31) {
emit_inline_thumb_error_exc(emit,
- mp_obj_new_exception_msg_varg(&mp_type_SyntaxError,
- translate("'%s' expects at most r%d"), op, 31));
+ mp_obj_new_exception_msg_varg(&mp_type_SyntaxError,
+ translate("'%s' expects at most r%d"), op, 31));
return 0;
} else {
return regno;
@@ -235,7 +239,7 @@ STATIC mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_pars
}
malformed:
emit_inline_thumb_error_exc(emit,
- mp_obj_new_exception_msg_varg(&mp_type_SyntaxError,
+ mp_obj_new_exception_msg_varg(&mp_type_SyntaxError,
translate("'%s' expects an FPU register"), op));
return 0;
}
@@ -248,7 +252,7 @@ STATIC mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_par
goto bad_arg;
}
- mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
+ mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn;
assert(MP_PARSE_NODE_STRUCT_NUM_NODES(pns) == 1); // should always be
pn = pns->nodes[0];
@@ -258,10 +262,10 @@ STATIC mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_par
// set with one element
reglist |= 1 << get_arg_reg(emit, op, pn, 15);
} else if (MP_PARSE_NODE_IS_STRUCT(pn)) {
- pns = (mp_parse_node_struct_t*)pn;
+ pns = (mp_parse_node_struct_t *)pn;
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_dictorsetmaker) {
assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should succeed
- mp_parse_node_struct_t *pns1 = (mp_parse_node_struct_t*)pns->nodes[1];
+ mp_parse_node_struct_t *pns1 = (mp_parse_node_struct_t *)pns->nodes[1];
if (MP_PARSE_NODE_STRUCT_KIND(pns1) == PN_dictorsetmaker_list) {
// set with multiple elements
@@ -311,11 +315,11 @@ STATIC bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_
if (!MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_bracket)) {
goto bad_arg;
}
- mp_parse_node_struct_t *pns = (mp_parse_node_struct_t*)pn;
+ mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn;
if (!MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_testlist_comp)) {
goto bad_arg;
}
- pns = (mp_parse_node_struct_t*)pns->nodes[0];
+ pns = (mp_parse_node_struct_t *)pns->nodes[0];
if (MP_PARSE_NODE_STRUCT_NUM_NODES(pns) != 2) {
goto bad_arg;
}
@@ -347,7 +351,9 @@ STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_
return 0;
}
-typedef struct _cc_name_t { byte cc; byte name[2]; } cc_name_t;
+typedef struct _cc_name_t { byte cc;
+ byte name[2];
+} cc_name_t;
STATIC const cc_name_t cc_name_table[] = {
{ ASM_THUMB_CC_EQ, "eq" },
{ ASM_THUMB_CC_NE, "ne" },
@@ -365,7 +371,9 @@ STATIC const cc_name_t cc_name_table[] = {
{ ASM_THUMB_CC_LE, "le" },
};
-typedef struct _format_4_op_t { byte op; char name[3]; } format_4_op_t;
+typedef struct _format_4_op_t { byte op;
+ char name[3];
+} format_4_op_t;
#define X(x) (((x) >> 4) & 0xff) // only need 1 byte to distinguish these ops
STATIC const format_4_op_t format_4_op_table[] = {
{ X(ASM_THUMB_FORMAT_4_EOR), "eor" },
@@ -387,7 +395,9 @@ STATIC const format_4_op_t format_4_op_table[] = {
#undef X
// name is actually a qstr, which should fit in 16 bits
-typedef struct _format_9_10_op_t { uint16_t op; uint16_t name; } format_9_10_op_t;
+typedef struct _format_9_10_op_t { uint16_t op;
+ uint16_t name;
+} format_9_10_op_t;
#define X(x) (x)
STATIC const format_9_10_op_t format_9_10_op_table[] = {
{ X(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER), MP_QSTR_ldr },
@@ -401,7 +411,9 @@ STATIC const format_9_10_op_t format_9_10_op_table[] = {
#if MICROPY_EMIT_INLINE_THUMB_FLOAT
// actual opcodes are: 0xee00 | op.hi_nibble, 0x0a00 | op.lo_nibble
-typedef struct _format_vfp_op_t { byte op; char name[3]; } format_vfp_op_t;
+typedef struct _format_vfp_op_t { byte op;
+ char name[3];
+} format_vfp_op_t;
STATIC const format_vfp_op_t format_vfp_op_table[] = {
{ 0x30, "add" },
{ 0x34, "sub" },
@@ -425,7 +437,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
// "subs", RLO, RLO, I3, asm_thumb_subs_reg_reg_i3
size_t op_len;
- const char *op_str = (const char*)qstr_data(op, &op_len);
+ const char *op_str = (const char *)qstr_data(op, &op_len);
#if MICROPY_EMIT_INLINE_THUMB_FLOAT
if (op_str[0] == 'v') {
@@ -434,7 +446,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
mp_uint_t op_code = 0x0ac0, op_code_hi;
if (op == MP_QSTR_vcmp) {
op_code_hi = 0xeeb4;
- op_vfp_twoargs:;
+ op_vfp_twoargs:;
mp_uint_t vd = get_arg_vfpreg(emit, op_str, pn_args[0]);
mp_uint_t vm = get_arg_vfpreg(emit, op_str, pn_args[1]);
asm_thumb_op32(&emit->as,
@@ -485,7 +497,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
0x0a10 | (r_arm << 12) | ((vm & 1) << 7));
} else if (op == MP_QSTR_vldr) {
op_code_hi = 0xed90;
- op_vldr_vstr:;
+ op_vldr_vstr:;
mp_uint_t vd = get_arg_vfpreg(emit, op_str, pn_args[0]);
mp_parse_node_t pn_base, pn_offset;
if (get_arg_addr(emit, op_str, pn_args[1], &pn_base, &pn_offset)) {
@@ -547,8 +559,8 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
mp_uint_t r = get_arg_reg(emit, op_str, pn_args[0], 15);
asm_thumb_op16(&emit->as, 0x4700 | (r << 3));
} else if (op_str[0] == 'b' && (op_len == 3
- || (op_len == 5 && op_str[3] == '_'
- && (op_str[4] == 'n' || (ARMV7M && op_str[4] == 'w'))))) {
+ || (op_len == 5 && op_str[3] == '_'
+ && (op_str[4] == 'n' || (ARMV7M && op_str[4] == 'w'))))) {
mp_uint_t cc = -1;
for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(cc_name_table); i++) {
if (op_str[1] == cc_name_table[i].name[0] && op_str[2] == cc_name_table[i].name[1]) {
@@ -637,7 +649,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
op_code_hi = 0xfab0;
op_code = 0xf080;
mp_uint_t rd, rm;
- op_clz_rbit:
+ op_clz_rbit:
rd = get_arg_reg(emit, op_str, pn_args[0], 15);
rm = get_arg_reg(emit, op_str, pn_args[1], 15);
asm_thumb_op32(&emit->as, op_code_hi | rm, op_code | (rd << 8) | rm);
@@ -645,7 +657,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
op_code_hi = 0xfa90;
op_code = 0xf0a0;
goto op_clz_rbit;
- } else if (ARMV7M && op == MP_QSTR_mrs){
+ } else if (ARMV7M && op == MP_QSTR_mrs) {
mp_uint_t reg_dest = get_arg_reg(emit, op_str, pn_args[0], 12);
mp_uint_t reg_src = get_arg_special_reg(emit, op_str, pn_args[1]);
asm_thumb_op32(&emit->as, 0xf3ef, 0x8000 | (reg_dest << 8) | reg_src);
@@ -653,7 +665,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
if (op == MP_QSTR_and_) {
op_code = ASM_THUMB_FORMAT_4_AND;
mp_uint_t reg_dest, reg_src;
- op_format_4:
+ op_format_4:
reg_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
reg_src = get_arg_reg(emit, op_str, pn_args[1], 7);
asm_thumb_format_4(&emit->as, op_code, reg_dest, reg_src);
@@ -674,7 +686,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
if (op == MP_QSTR_mov) {
op_code = ASM_THUMB_FORMAT_3_MOV;
mp_uint_t rlo_dest, i8_src;
- op_format_3:
+ op_format_3:
rlo_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
i8_src = get_arg_i(emit, op_str, pn_args[1], 0xff);
asm_thumb_format_3(&emit->as, op_code, rlo_dest, i8_src);
@@ -690,7 +702,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
} else if (ARMV7M && op == MP_QSTR_movw) {
op_code = ASM_THUMB_OP_MOVW;
mp_uint_t reg_dest;
- op_movw_movt:
+ op_movw_movt:
reg_dest = get_arg_reg(emit, op_str, pn_args[0], 15);
int i_src = get_arg_i(emit, op_str, pn_args[1], 0xffff);
asm_thumb_mov_reg_i16(&emit->as, op_code, reg_dest, i_src);
@@ -743,7 +755,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
if (op == MP_QSTR_lsl) {
op_code = ASM_THUMB_FORMAT_1_LSL;
mp_uint_t rlo_dest, rlo_src, i5;
- op_format_1:
+ op_format_1:
rlo_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
rlo_src = get_arg_reg(emit, op_str, pn_args[1], 7);
i5 = get_arg_i(emit, op_str, pn_args[2], 0x1f);
@@ -757,7 +769,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
} else if (op == MP_QSTR_add) {
op_code = ASM_THUMB_FORMAT_2_ADD;
mp_uint_t rlo_dest, rlo_src;
- op_format_2:
+ op_format_2:
rlo_dest = get_arg_reg(emit, op_str, pn_args[0], 7);
rlo_src = get_arg_reg(emit, op_str, pn_args[1], 7);
int src_b;
@@ -772,7 +784,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
} else if (ARMV7M && op == MP_QSTR_sdiv) {
op_code = 0xfb90; // sdiv high part
mp_uint_t rd, rn, rm;
- op_sdiv_udiv:
+ op_sdiv_udiv:
rd = get_arg_reg(emit, op_str, pn_args[0], 15);
rn = get_arg_reg(emit, op_str, pn_args[1], 15);
rm = get_arg_reg(emit, op_str, pn_args[2], 15);