diff --git a/src/app/test/genblend.h b/src/app/test/genblend.h index f5be442..15da545 100644 --- a/src/app/test/genblend.h +++ b/src/app/test/genblend.h @@ -5,8 +5,8 @@ // Zlib - See LICENSE.md file in the package. // [Guard] -#ifndef _GENBLEND_H -#define _GENBLEND_H +#ifndef _APP_TEST_GENBLEND_H +#define _APP_TEST_GENBLEND_H // [Dependencies] #include @@ -175,4 +175,4 @@ static void blend(asmjit::host::Compiler& c) { } // asmgen namespace // [Guard] -#endif // _GENBLEND_H +#endif // _APP_TEST_GENBLEND_H diff --git a/src/app/test/genopcode.h b/src/app/test/genopcode.h index 7ae4b0b..b07cd38 100644 --- a/src/app/test/genopcode.h +++ b/src/app/test/genopcode.h @@ -5,8 +5,8 @@ // Zlib - See LICENSE.md file in the package. // [Guard] -#ifndef _GENOPCODE_H -#define _GENOPCODE_H +#ifndef _APP_TEST_GENOPCODE_H +#define _APP_TEST_GENOPCODE_H // [Dependencies] #include @@ -2307,4 +2307,4 @@ static void opcode(asmjit::host::Assembler& a) { } // asmgen namespace // [Guard] -#endif // _GENOPCODE_H +#endif // _APP_TEST_GENOPCODE_H diff --git a/src/app/test/testx86.cpp b/src/app/test/testx86.cpp index 010ad84..cf944cb 100644 --- a/src/app/test/testx86.cpp +++ b/src/app/test/testx86.cpp @@ -975,7 +975,7 @@ struct X86Test_AllocStack : public X86Test { // Fill stack by sequence [0, 1, 2, 3 ... 255]. c.xor_(i, i); - + c.bind(L_1); c.mov(stack.clone().setIndex(i, 0), i.r8()); c.inc(i); @@ -985,7 +985,7 @@ struct X86Test_AllocStack : public X86Test { // Sum sequence in stack. c.xor_(i, i); c.xor_(a, a); - + c.bind(L_2); c.movzx(b, stack.clone().setIndex(i, 0)); c.add(a, b); @@ -1709,7 +1709,7 @@ X86TestSuite::X86TestSuite() : ADD_TEST(X86Test_AllocStack); ADD_TEST(X86Test_AllocMemcpy); ADD_TEST(X86Test_AllocBlend); - + // Call. ADD_TEST(X86Test_CallBase); ADD_TEST(X86Test_CallFast); diff --git a/src/asmjit/base/context.cpp b/src/asmjit/base/context.cpp index 5e13c13..80885d0 100644 --- a/src/asmjit/base/context.cpp +++ b/src/asmjit/base/context.cpp @@ -186,7 +186,7 @@ Error BaseContext::resolveCellOffsets() { uint32_t stackAlignment = 0; if (stackCell != NULL) - stackAlignment = stackCell->getAlignment(); + stackAlignment = stackCell->getAlignment(); uint32_t pos64 = 0; uint32_t pos32 = pos64 + _mem64ByteVarsUsed * 64; @@ -200,7 +200,7 @@ Error BaseContext::resolveCellOffsets() { uint32_t gapAlignment = stackAlignment; uint32_t gapSize = 0; - + if (gapAlignment) IntUtil::deltaTo(stackPos, gapAlignment); stackPos += gapSize; @@ -301,7 +301,7 @@ Error BaseContext::removeUnreachableCode() { void BaseContext::cleanup() { VarData** array = _contextVd.getData(); size_t length = _contextVd.getLength(); - + for (size_t i = 0; i < length; i++) { VarData* vd = array[i]; vd->resetContextId(); diff --git a/src/asmjit/base/context_p.h b/src/asmjit/base/context_p.h index 7d38ef4..c82aa9a 100644 --- a/src/asmjit/base/context_p.h +++ b/src/asmjit/base/context_p.h @@ -5,8 +5,8 @@ // Zlib - See LICENSE.md file in the package. // [Guard] -#ifndef _ASMJIT_BASE_CONTEXT_H -#define _ASMJIT_BASE_CONTEXT_H +#ifndef _ASMJIT_BASE_CONTEXT_P_H +#define _ASMJIT_BASE_CONTEXT_P_H // [Dependencies - AsmJit] #include "../base/compiler.h" @@ -251,4 +251,4 @@ struct BaseContext { #include "../base/apiend.h" // [Guard] -#endif // _ASMJIT_BASE_CONTEXT_H +#endif // _ASMJIT_BASE_CONTEXT_P_H diff --git a/src/asmjit/contrib/winremoteruntime.h b/src/asmjit/contrib/winremoteruntime.h index c65eaae..ea41753 100644 --- a/src/asmjit/contrib/winremoteruntime.h +++ b/src/asmjit/contrib/winremoteruntime.h @@ -56,7 +56,7 @@ struct WinRemoteRuntime : public BaseRuntime { //! @brief Process. HANDLE _hProcess; - + //! @brief Virtual memory manager. VirtualMemoryManager _memoryManager; }; diff --git a/src/asmjit/x86/x86assembler.h b/src/asmjit/x86/x86assembler.h index d90de12..16ba531 100644 --- a/src/asmjit/x86/x86assembler.h +++ b/src/asmjit/x86/x86assembler.h @@ -250,7 +250,7 @@ namespace x86x64 { //! to create invalid instruction (for example mov [eax], [eax], //! because such overload doesn't exist. //! -//! Each call to an assembler intrinsic function emits instruction directly +//! Each call to an assembler intrinsic function emits instruction directly //! to the binary stream. There are also runtime checks that prevent invalid //! code to be emitted. It will assert in debug mode and put the @ref Assembler //! instance to an error state in production mode. diff --git a/src/asmjit/x86/x86compiler.cpp b/src/asmjit/x86/x86compiler.cpp index 20e1d63..d82d025 100644 --- a/src/asmjit/x86/x86compiler.cpp +++ b/src/asmjit/x86/x86compiler.cpp @@ -443,7 +443,7 @@ Error X86X64Compiler::setArg(uint32_t argIndex, BaseVar& var) { Error X86X64Compiler::_newVar(BaseVar* var, uint32_t vType, const char* name) { ASMJIT_ASSERT(vType < kVarTypeCount); - + vType = _targetVarMapping[vType]; const VarInfo& vInfo = _varInfo[vType]; diff --git a/src/asmjit/x86/x86context.cpp b/src/asmjit/x86/x86context.cpp index bfe191a..c5f7ec2 100644 --- a/src/asmjit/x86/x86context.cpp +++ b/src/asmjit/x86/x86context.cpp @@ -1910,7 +1910,7 @@ _NextGroup: uint32_t inReg = special[i].inReg; uint32_t outReg = special[i].outReg; uint32_t c; - + if (static_cast(op)->isGp()) c = kRegClassGp; else diff --git a/src/asmjit/x86/x86defs.h b/src/asmjit/x86/x86defs.h index 3a87d9e..5507ec9 100644 --- a/src/asmjit/x86/x86defs.h +++ b/src/asmjit/x86/x86defs.h @@ -11,10 +11,10 @@ // [Dependencies - AsmJit] #include "../base/assembler.h" #include "../base/assert.h" -#include "../base/defs.h" -#include "../base/vectypes.h" #include "../base/compiler.h" +#include "../base/defs.h" #include "../base/intutil.h" +#include "../base/vectypes.h" // [Api-Begin] #include "../base/apibegin.h" @@ -2543,7 +2543,7 @@ struct Mem : public BaseMem { _init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex, _getGpdFlags(reinterpret_cast(base)) - + (kMemVSibXmm << kMemVSibIndex) + + (kMemVSibXmm << kMemVSibIndex) + (shift << kMemShiftIndex), _OP_ID(base)); _vmem.index = _OP_ID(index); @@ -2555,7 +2555,7 @@ struct Mem : public BaseMem { _init_packed_op_sz_b0_b1_id(kOperandTypeMem, size, kMemTypeBaseIndex, _getGpdFlags(reinterpret_cast(base)) - + (kMemVSibYmm << kMemVSibIndex) + + (kMemVSibYmm << kMemVSibIndex) + (shift << kMemShiftIndex), _OP_ID(base)); _vmem.index = _OP_ID(index); diff --git a/src/asmjit/x86/x86func.cpp b/src/asmjit/x86/x86func.cpp index 79a90e5..f5d43ce 100644 --- a/src/asmjit/x86/x86func.cpp +++ b/src/asmjit/x86/x86func.cpp @@ -195,7 +195,7 @@ static uint32_t X86X64FuncDecl_initConv(X86X64FuncDecl* self, uint32_t arch, uin } #undef R -static Error X86X64FuncDecl_initFunc(X86X64FuncDecl* self, uint32_t arch, +static Error X86X64FuncDecl_initFunc(X86X64FuncDecl* self, uint32_t arch, uint32_t ret, const uint32_t* argList, uint32_t argCount) { ASMJIT_ASSERT(argCount <= kFuncArgCount); diff --git a/tools/src-sanity.js b/tools/src-sanity.js index e309a37..0374abc 100644 --- a/tools/src-sanity.js +++ b/tools/src-sanity.js @@ -15,17 +15,19 @@ var filesToSanitize = (function() { var fullName = path.normalize(path.join(dir, baseName)); var stat = fs.lstatSync(fullName); - if (stat.isSymbolicLink()) + if (stat.isSymbolicLink()) { continue; + } if (stat.isDirectory()) { - listPrivate(subarray, path.join(dir, baseName), displayDir + baseName, accept); + subarray = listPrivate(subarray, + path.join(dir, baseName), displayDir ? displayDir + "/" + baseName : baseName, accept); continue; } if (stat.isFile()) { if (accept(baseName)) - array.push({ name: fullName, display: displayDir + baseName }); + array.push({ name: fullName, display: displayDir ? displayDir + "/" + baseName : baseName }); continue; } } @@ -38,6 +40,19 @@ var filesToSanitize = (function() { }; })(); +/** + * Inject data into string. + */ +var inject = function(s, start, end, what) { + assert(start <= s.length); + assert(end <= s.length); + + return s.substr(0, start) + what + s.substr(end); +}; + +/** + * Is the extension c++ header file? + */ var isCppHeaderExt = function(ext) { return ext === ".h" || ext === ".hh" || @@ -45,6 +60,9 @@ var isCppHeaderExt = function(ext) { ext === ".hxx" ; }; +/** + * Is the extension c++ source file? + */ var isCppSourceExt = function(ext) { return ext === ".c" || ext === ".cc" || @@ -66,7 +84,10 @@ var filesToAccept = function(name) { ext === ".mm" ; }; -var sanitySpaces = function(data) { +/** + * Sanity spaces. + */ +var sanitySpaces = function(data, name) { // Remove carriage return. data = data.replace(/\r\n/g, "\n"); // Remove spaces before the end of the line. @@ -77,12 +98,109 @@ var sanitySpaces = function(data) { return data; }; -var sanityHeaderGuards = function(data) { +/** + * Sanity header guards. + */ +var sanityHeaderGuards = (function() { + var parseGuardName = function(data, i) { + var m = data.substr(i).match(/[\w][\d\w]*/); + return m ? m[0] : null; + }; - return data; -}; + var makeGuardName = function(name) { + // Remove leading '/' or '\'. + if (/^[\\\/]/.test(name)) + name = name.substr(1); + return "_" + name.toUpperCase().replace(/[\/\\\.-]/g, "_"); + }; -var sanityIncludeOrder = function(data, directive) { + var directiveMarks = [ + "#ifndef ", + "#endif // ", + "#define " + ]; + + var directiveNames = [ + "#ifndef ", + "#endif ", + "#define " + ]; + + return function(data, name) { + var i = 0; + var nl = true; + + var guard = "// " + "[Guard]" + "\n"; + var nFound = 0; + + while (i < data.length) { + if (nl && data.substr(i, guard.length) === guard) { + i += guard.length; + nFound++; + + if (i >= data.length) + break; + + for (var j = 0; j < directiveMarks.length; ) { + var m = directiveMarks[j]; + if (data.substr(i, m.length) === m && data.charAt(i + m.length) === '_') { + i += directiveMarks[j].length; + + var oldGuardName = parseGuardName(data, i); + var newGuardName; + + if (oldGuardName) { + console.log(oldGuardName); + var startPosition = i; + var endPosition = i + oldGuardName.length; + + newGuardName = makeGuardName(name); + if (oldGuardName !== newGuardName) { + console.log(name + ": " + directiveNames[j] + newGuardName); + data = inject(data, startPosition, endPosition, newGuardName); + + i += newGuardName.length; + i = data.indexOf('\n', i); + + if (i === -1) { + // Terminates the loop. + i = data.length; + j = 9999; + nl = false; + break; + } + else { + i++; + } + } + } + j += 2; + } + // Don't process '#define' directive if previous '#ifndef' wasn't matched. + else { + if (++j == 2) + break; + } + } + } + else { + nl = data.charAt(i) === '\n'; + i++; + } + } + + if (nFound & 1) { + console.log(name + ": Odd number of guards found: " + nFound); + } + + return data; + }; +})(); + +/** + * Sanity #include order. + */ +var sanityIncludeOrder = function(data, name, directive) { var i = 0; var nl = true; @@ -92,7 +210,7 @@ var sanityIncludeOrder = function(data, directive) { var replacement; while (i < data.length) { - if (nl && data.indexOf(directive, i) === i) { + if (nl && data.substr(i, directive.length) === directive) { var iLocal = i if (startPosition === -1) { @@ -105,7 +223,7 @@ var sanityIncludeOrder = function(data, directive) { list.push(data.substring(iLocal, i)); break; } - if (data[i] === '\n') { + if (data.charAt(i) === '\n') { list.push(data.substring(iLocal, i)); i++; break; @@ -118,13 +236,10 @@ var sanityIncludeOrder = function(data, directive) { if (list.length > 1) { list.sort(); - replacement = list.join("\n"); - assert(replacement.length == endPosition - startPosition - 1); + replacement = list.join("\n") + "\n"; - data = data.substring(0, startPosition) + - replacement + - "\n" + - data.substring(endPosition); + assert(replacement.length == endPosition - startPosition); + data = inject(data, startPosition, endPosition, replacement); } startPosition = -1; @@ -135,7 +250,7 @@ var sanityIncludeOrder = function(data, directive) { i++; } else { - nl = data[i] === '\n'; + nl = data.charAt(i) === '\n'; i++; } } @@ -143,32 +258,34 @@ var sanityIncludeOrder = function(data, directive) { return data; }; +/** + * Sanity the given data of file. + */ var sanity = function(data, name) { var ext = path.extname(name).toLowerCase(); // Sanity spaces. - data = sanitySpaces(data); + data = sanitySpaces(data, name); - // Fix C/C++ header guards. + // Fix C/C++ header guards and sort '#include' files. if (isCppHeaderExt(ext)) { - data = sanityHeaderGuards(data); - } - - // Sort #include files. - if (isCppHeaderExt(ext) || isCppSourceExt(ext)) { - data = sanityIncludeOrder(data, "#include"); + data = sanityHeaderGuards(data, name); + data = sanityIncludeOrder(data, name, "#include"); } return data; }; +/** + * Entry. + */ var main = function(dir) { filesToSanitize(dir, filesToAccept).forEach(function(file) { var oldData = fs.readFileSync(file.name, "utf8"); var newData = sanity(oldData, file.display); if (oldData !== newData) { - console.log("Sanitizing: " + file.display); + console.log(file.display + ": Writing..."); fs.writeFileSync(file.name, newData, "utf8"); } });