Skip to content

Commit

Permalink
Bug 1499323 - Prepare the check_macroassembler_style python script to…
Browse files Browse the repository at this point in the history
… accept clang-format rewritting. r=jandem
  • Loading branch information
nbp authored and ehsan committed Dec 13, 2018
1 parent 2918626 commit 62843b6
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 61 deletions.
64 changes: 43 additions & 21 deletions config/check_macroassembler_style.py
Expand Up @@ -50,6 +50,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
Expand Down Expand Up @@ -145,44 +147,61 @@ def get_macroassembler_definitions(filename):
return []

style_section = False
code_section = False
lines = ''
signatures = []
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 = ''
continue
lines = lines + line
# Continue until we have a complete declaration
if '{' not in 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
# Skip variable declarations
if ')' not in lines:
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 = ''
continue
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

return signatures

Expand All @@ -201,14 +220,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
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/MacroAssembler-inl.h
Expand Up @@ -32,7 +32,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -772,7 +771,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
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/MacroAssembler.cpp
Expand Up @@ -2849,7 +2849,6 @@ MacroAssembler::subFromStackPtr(Register reg)
}
#endif // JS_CODEGEN_ARM64

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -3721,7 +3720,6 @@ MacroAssembler::boundsCheck32PowerOfTwo(Register index, uint32_t length, Label*
}

//}}} check_macroassembler_style
// clang-format on

void
MacroAssembler::memoryBarrierBefore(const Synchronization& sync) {
Expand Down
4 changes: 0 additions & 4 deletions js/src/jit/MacroAssembler.h
Expand Up @@ -411,7 +411,6 @@ class MacroAssembler : public MacroAssemblerSpecific
void Push(RegisterOrSP reg);
#endif

// clang-format off
//{{{ check_macroassembler_decl_style
public:
// ===============================================================
Expand Down Expand Up @@ -2019,7 +2018,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
Expand Down Expand Up @@ -2684,7 +2682,6 @@ class MacroAssembler : public MacroAssemblerSpecific
Vector<ObjectGroup*, 0, SystemAllocPolicy> pendingObjectGroupReadBarriers_;
};

// clang-format off
//{{{ check_macroassembler_style
inline uint32_t
MacroAssembler::framePushed() const
Expand Down Expand Up @@ -2713,7 +2710,6 @@ MacroAssembler::implicitPop(uint32_t bytes)
adjustFrame(-int32_t(bytes));
}
//}}} check_macroassembler_style
// clang-format on

static inline Assembler::DoubleCondition
JSOpToDoubleCondition(JSOp op)
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/arm/MacroAssembler-arm-inl.h
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style

void
Expand Down Expand Up @@ -2319,7 +2318,6 @@ MacroAssembler::wasmBoundsCheck(Condition cond, Register index, Address boundsCh
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

void
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/arm/MacroAssembler-arm.cpp
Expand Up @@ -4205,7 +4205,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
ma_sub(imm32, sp, scratch);
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -5834,7 +5833,6 @@ MacroAssembler::speculationBarrier()
}

//}}} check_macroassembler_style
// clang-format on

void
MacroAssemblerARM::wasmTruncateToInt32(FloatRegister input, Register output, MIRType fromType,
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/arm64/MacroAssembler-arm64-inl.h
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style

void
Expand Down Expand Up @@ -1984,7 +1983,6 @@ MacroAssembler::wasmBoundsCheck(Condition cond, Register index, Address boundsCh
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

void
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/arm64/MacroAssembler-arm64.cpp
Expand Up @@ -412,7 +412,6 @@ MacroAssembler::Push(RegisterOrSP reg)
adjustFrame(sizeof(intptr_t));
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -1874,7 +1873,6 @@ MacroAssembler::speculationBarrier()
}

//}}} check_macroassembler_style
// clang-format off

} // namespace jit
} // namespace js
2 changes: 0 additions & 2 deletions js/src/jit/mips-shared/MacroAssembler-mips-shared-inl.h
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style

void
Expand Down Expand Up @@ -1102,7 +1101,6 @@ MacroAssembler::clampIntToUint8(Register reg)
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

} // namespace jit
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips-shared/MacroAssembler-mips-shared.cpp
Expand Up @@ -1471,7 +1471,6 @@ MacroAssemblerMIPSShared::asMasm() const
return *static_cast<const MacroAssembler*>(this);
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -2848,4 +2847,3 @@ MacroAssembler::atomicEffectOpJS(Scalar::Type arrayType, const Synchronization&
}

//}}} check_macroassembler_style
// clang-format on
2 changes: 0 additions & 2 deletions js/src/jit/mips32/MacroAssembler-mips32-inl.h
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style

void
Expand Down Expand Up @@ -1019,7 +1018,6 @@ MacroAssembler::wasmBoundsCheck(Condition cond, Register index, Address boundsCh
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

void
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips32/MacroAssembler-mips32.cpp
Expand Up @@ -2116,7 +2116,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
asMasm().subPtr(imm32, StackPointer);
}

// clang-format on
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -2938,4 +2937,3 @@ MacroAssembler::convertUInt64ToDouble(Register64 src, FloatRegister dest, Regist
}

//}}} check_macroassembler_style
// clang-format on
2 changes: 0 additions & 2 deletions js/src/jit/mips64/MacroAssembler-mips64-inl.h
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style

void
Expand Down Expand Up @@ -773,7 +772,6 @@ MacroAssembler::wasmBoundsCheck(Condition cond, Register index, Address boundsCh
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

// The specializations for cmpPtrSet are outside the braces because check_macroassembler_style can't yet
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips64/MacroAssembler-mips64.cpp
Expand Up @@ -1990,7 +1990,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
asMasm().subPtr(imm32, StackPointer);
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -2769,4 +2768,3 @@ MacroAssembler::convertUInt64ToFloat32(Register64 src_, FloatRegister dest, Regi
}

//}}} check_macroassembler_style
// clang-format on
2 changes: 0 additions & 2 deletions js/src/jit/x64/MacroAssembler-x64-inl.h
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================

Expand Down Expand Up @@ -956,7 +955,6 @@ MacroAssembler::truncateDoubleToUInt64(Address src, Address dest, Register temp,
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

void
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/x64/MacroAssembler-x64.cpp
Expand Up @@ -291,7 +291,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// ABI function calls.
Expand Down Expand Up @@ -1065,4 +1064,3 @@ MacroAssembler::atomicEffectOp64(const Synchronization&, AtomicOp op, Register64
}

//}}} check_macroassembler_style
// clang-format on
2 changes: 0 additions & 2 deletions js/src/jit/x86-shared/MacroAssembler-x86-shared-inl.h
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Move instructions
Expand Down Expand Up @@ -1313,7 +1312,6 @@ MacroAssembler::clampIntToUint8(Register reg)
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

} // namespace jit
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/x86-shared/MacroAssembler-x86-shared.cpp
Expand Up @@ -266,7 +266,6 @@ MacroAssemblerX86Shared::minMaxFloat32(FloatRegister first, FloatRegister second
bind(&done);
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -1432,4 +1431,3 @@ MacroAssembler::speculationBarrier()
}

//}}} check_macroassembler_style
// clang-format on
2 changes: 0 additions & 2 deletions js/src/jit/x86/MacroAssembler-x86-inl.h
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

// clang-format off
//{{{ check_macroassembler_style

void
Expand Down Expand Up @@ -1182,7 +1181,6 @@ MacroAssembler::wasmBoundsCheck(Condition cond, Register index, Address boundsCh
}

//}}} check_macroassembler_style
// clang-format on
// ===============================================================

// Note: this function clobbers the source register.
Expand Down

0 comments on commit 62843b6

Please sign in to comment.