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 committed Nov 29, 2018
1 parent 1b2196f commit 6570f1f
Show file tree
Hide file tree
Showing 20 changed files with 43 additions and 60 deletions.
63 changes: 43 additions & 20 deletions config/check_macroassembler_style.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ''
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 +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
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/MacroAssembler-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
namespace js {
namespace jit {

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

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -3807,7 +3806,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
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ class MacroAssembler : public MacroAssemblerSpecific
void Push(RegisterOrSP reg);
#endif

// clang-format off
//{{{ check_macroassembler_decl_style
public:
// ===============================================================
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2902,7 +2900,6 @@ class IonHeapMacroAssembler : public MacroAssembler
}
};

// clang-format off
//{{{ check_macroassembler_style
inline uint32_t
MacroAssembler::framePushed() const
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/arm/MacroAssembler-arm-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

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

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

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

void
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/arm/MacroAssembler-arm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4362,7 +4362,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -6176,7 +6175,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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

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

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

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

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

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -2025,7 +2024,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
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace js {
namespace jit {

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

void
Expand Down Expand Up @@ -1111,7 +1110,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
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,6 @@ MacroAssemblerMIPSShared::asMasm() const
return *static_cast<const MacroAssembler*>(this);
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// MacroAssembler high-level usage.
Expand Down Expand Up @@ -2929,4 +2928,3 @@ MacroAssembler::speculationBarrier()
MOZ_CRASH();
}
//}}} check_macroassembler_style
// clang-format on
2 changes: 0 additions & 2 deletions js/src/jit/mips32/MacroAssembler-mips32-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

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

void
Expand Down Expand Up @@ -1012,7 +1011,6 @@ MacroAssembler::branchTruncateFloat32MaybeModUint32(FloatRegister src, Register
}

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

void
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips32/MacroAssembler-mips32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2109,7 +2109,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}

// clang-format on
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -2968,4 +2967,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

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

void
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions js/src/jit/mips64/MacroAssembler-mips64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1948,7 +1948,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Stack manipulation functions.
Expand Down Expand Up @@ -2760,4 +2759,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
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
namespace js {
namespace jit {

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

Expand Down Expand Up @@ -965,7 +964,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
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ MacroAssembler::subFromStackPtr(Imm32 imm32)
}
}

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// ABI function calls.
Expand Down Expand Up @@ -1039,4 +1038,3 @@ MacroAssembler::wasmAtomicEffectOp64(const wasm::MemoryAccessDesc& access, Atomi
}

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

// clang-format off
//{{{ check_macroassembler_style
// ===============================================================
// Move instructions
Expand Down Expand Up @@ -1332,7 +1331,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
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ MacroAssemblerX86Shared::minMaxFloat32(FloatRegister first, FloatRegister second
bind(&done);
}

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

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

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

void
Expand Down Expand Up @@ -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.
Expand Down
Loading

0 comments on commit 6570f1f

Please sign in to comment.