Bug 1499323 - Prepare the check_macroassembler_style python script to accept clang-format rewritting. r=jandem

This commit is contained in:
Nicolas B. Pierron 2018-11-28 15:27:35 +01:00
parent 1b2196f200
commit 6570f1fb9f
20 changed files with 43 additions and 60 deletions

View File

@ -48,6 +48,8 @@ def get_normalized_signatures(signature, fileAnnot=None):
signature = signature.replace(';', ' ')
# Normalize spaces.
signature = re.sub(r'\s+', ' ', signature).strip()
# Remove new-line induced spaces after opening braces.
signature = re.sub(r'\(\s+', '(', signature).strip()
# Match arguments, and keep only the type.
signature = reMatchArg.sub('\g<type>', signature)
# Remove class name
@ -150,39 +152,57 @@ def get_macroassembler_definitions(filename):
with open(filename) as f:
for line in f:
if '//{{{ check_macroassembler_style' in line:
if style_section:
raise 'check_macroassembler_style section already opened.'
style_section = True
braces_depth = 0
elif '//}}} check_macroassembler_style' in line:
style_section = False
if not style_section:
continue
# Remove comments from the processed line.
line = re.sub(r'//.*', '', line)
if line.startswith('{') or line.strip() == "{}":
# Locate and count curly braces.
open_curly_brace = line.find('{')
was_braces_depth = braces_depth
braces_depth = braces_depth + line.count('{') - line.count('}')
# Raise an error if the check_macroassembler_style macro is used
# across namespaces / classes scopes.
if braces_depth < 0:
raise 'check_macroassembler_style annotations are not well scoped.'
# If the current line contains an opening curly brace, check if
# this line combines with the previous one can be identified as a
# MacroAssembler function signature.
if open_curly_brace != -1 and was_braces_depth == 0:
lines = lines + line[:open_curly_brace]
if 'MacroAssembler::' in lines:
signatures.extend(
get_normalized_signatures(lines, fileAnnot))
if line.strip() != "{}": # Empty declaration, no need to declare
# a new code section
code_section = True
continue
if line.startswith('}'):
code_section = False
lines = ''
continue
if code_section:
continue
if len(line.strip()) == 0:
lines = ''
# We do not aggregate any lines if we are scanning lines which are
# in-between a set of curly braces.
if braces_depth > 0:
continue
if was_braces_depth != 0:
line = line[line.rfind('}') + 1:]
# This logic is used to remove template instantiation, static
# variable definitions and function declaration from the next
# function definition.
last_semi_colon = line.rfind(';')
if last_semi_colon != -1:
lines = ''
line = line[last_semi_colon + 1:]
# Aggregate lines of non-braced text, which corresponds to the space
# where we are expecting to find function definitions.
lines = lines + line
# Continue until we have a complete declaration
if '{' not in lines:
continue
# Skip variable declarations
if ')' not in lines:
lines = ''
continue
return signatures
@ -201,14 +221,17 @@ def get_macroassembler_declaration(filename):
continue
line = re.sub(r'//.*', '', line)
if len(line.strip()) == 0:
if len(line.strip()) == 0 or 'public:' in line or 'private:' in line:
lines = ''
continue
lines = lines + line
# Continue until we have a complete declaration
if ';' not in lines:
continue
# Skip variable declarations
# Skip member declarations: which are lines ending with a
# semi-colon without any list of arguments.
if ')' not in lines:
lines = ''
continue

View File

@ -33,7 +33,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
@ -800,7 +799,6 @@ template void MacroAssembler::storeFloat32(FloatRegister src, const Address& des
template void MacroAssembler::storeFloat32(FloatRegister src, const BaseIndex& dest);
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
#ifndef JS_CODEGEN_ARM64

View File

@ -2954,7 +2954,6 @@ MacroAssembler::subFromStackPtr(Register reg)
}
#endif // JS_CODEGEN_ARM64
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
@ -3807,7 +3806,6 @@ MacroAssembler::boundsCheck32PowerOfTwo(Register index, uint32_t length, Label*
}
//}}} check_macroassembler_style
// clang-format on
void
MacroAssembler::memoryBarrierBefore(const Synchronization& sync) {

View File

@ -350,7 +350,6 @@ class MacroAssembler : public MacroAssemblerSpecific
void Push(RegisterOrSP reg);
#endif
// clang-format off
//{{{ check_macroassembler_decl_style
public:
// ===============================================================
@ -2136,7 +2135,6 @@ class MacroAssembler : public MacroAssemblerSpecific
void speculationBarrier() PER_SHARED_ARCH;
//}}} check_macroassembler_decl_style
// clang-format on
public:
// Emits a test of a value against all types in a TypeSet. A scratch
@ -2902,7 +2900,6 @@ class IonHeapMacroAssembler : public MacroAssembler
}
};
// clang-format off
//{{{ check_macroassembler_style
inline uint32_t
MacroAssembler::framePushed() const
@ -2931,7 +2928,6 @@ MacroAssembler::implicitPop(uint32_t bytes)
adjustFrame(-int32_t(bytes));
}
//}}} check_macroassembler_style
// clang-format on
static inline Assembler::DoubleCondition
JSOpToDoubleCondition(JSOp op)

View File

@ -12,7 +12,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
void
@ -2335,7 +2334,6 @@ MacroAssembler::clampIntToUint8(Register reg)
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
void

View File

@ -4362,7 +4362,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
@ -6176,7 +6175,6 @@ MacroAssembler::speculationBarrier()
}
//}}} check_macroassembler_style
// clang-format on
void
MacroAssemblerARM::wasmTruncateToInt32(FloatRegister input, Register output, MIRType fromType,

View File

@ -12,7 +12,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
void
@ -1982,7 +1981,6 @@ MacroAssembler::clampIntToUint8(Register reg)
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
void

View File

@ -413,7 +413,6 @@ MacroAssembler::Push(RegisterOrSP reg)
adjustFrame(sizeof(intptr_t));
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
@ -2025,7 +2024,6 @@ MacroAssembler::speculationBarrier()
}
//}}} check_macroassembler_style
// clang-format off
} // namespace jit
} // namespace js

View File

@ -12,7 +12,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
void
@ -1111,7 +1110,6 @@ MacroAssembler::clampIntToUint8(Register reg)
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
} // namespace jit

View File

@ -1439,7 +1439,6 @@ MacroAssemblerMIPSShared::asMasm() const
return *static_cast<const MacroAssembler*>(this);
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
@ -2929,4 +2928,3 @@ MacroAssembler::speculationBarrier()
MOZ_CRASH();
}
//}}} check_macroassembler_style
// clang-format on

View File

@ -14,7 +14,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
void
@ -1012,7 +1011,6 @@ MacroAssembler::branchTruncateFloat32MaybeModUint32(FloatRegister src, Register
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
void

View File

@ -2109,7 +2109,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}
// clang-format on
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
@ -2968,4 +2967,3 @@ MacroAssembler::convertUInt64ToDouble(Register64 src, FloatRegister dest, Regist
}
//}}} check_macroassembler_style
// clang-format on

View File

@ -14,7 +14,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
void
@ -759,7 +758,6 @@ MacroAssembler::branchTruncateFloat32MaybeModUint32(FloatRegister src, Register
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
// The specializations for cmpPtrSet are outside the braces because check_macroassembler_style can't yet

View File

@ -1948,7 +1948,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
@ -2760,4 +2759,3 @@ MacroAssembler::convertUInt64ToFloat32(Register64 src_, FloatRegister dest, Regi
}
//}}} check_macroassembler_style
// clang-format on

View File

@ -14,7 +14,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
@ -965,7 +964,6 @@ MacroAssembler::truncateDoubleToUInt64(Address src, Address dest, Register temp,
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
void

View File

@ -303,7 +303,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// ABI function calls.
@ -1039,4 +1038,3 @@ MacroAssembler::wasmAtomicEffectOp64(const wasm::MemoryAccessDesc& access, Atomi
}
//}}} check_macroassembler_style
// clang-format on

View File

@ -12,7 +12,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Move instructions
@ -1332,7 +1331,6 @@ MacroAssembler::clampIntToUint8(Register reg)
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
} // namespace jit

View File

@ -270,7 +270,6 @@ MacroAssemblerX86Shared::minMaxFloat32(FloatRegister first, FloatRegister second
bind(&done);
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
@ -1674,4 +1673,3 @@ MacroAssembler::speculationBarrier()
}
//}}} check_macroassembler_style
// clang-format on

View File

@ -14,7 +14,6 @@
namespace js {
namespace jit {
// clang-format off
//{{{ check_macroassembler_style
void
@ -1183,7 +1182,6 @@ MacroAssembler::truncateDoubleToUInt64(Address src, Address dest, Register temp,
}
//}}} check_macroassembler_style
// clang-format on
// ===============================================================
// Note: this function clobbers the source register.

View File

@ -302,7 +302,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}
// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// ABI function calls.
@ -1282,5 +1281,4 @@ MacroAssembler::convertInt64ToFloat32(Register64 input, FloatRegister output)
}
//}}} check_macroassembler_style
// clang-format on