# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import argparse
import filecmp
import fnmatch
import os
import datetime
import json
+parser = argparse.ArgumentParser()
+parser.add_argument('input_file', nargs='*', help='Input JS files which builtins generated from')
+parser.add_argument('--input-directory', help='All JS files will be used as input from this directory.')
+parser.add_argument('--output', help='path to output cpp or h file')
+args = parser.parse_args()
+
copyrightText = """ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
functionHeadRegExp = re.compile(r"function\s+\w+\s*\(.*?\)", re.MULTILINE | re.S)
functionNameRegExp = re.compile(r"function\s+(\w+)\s*\(", re.MULTILINE | re.S)
-functionParameterFinder = re.compile(r"^function\s+(?:\w+)\s*\(((?:\s*\w+)?\s*(?:\s*,\s*\w+)*)?\)", re.MULTILINE | re.S)
+functionParameterFinder = re.compile(r"^function\s+(?:\w+)\s*\(((?:\s*\w+)?\s*(?:\s*,\s*\w+)*)?\s*\)", re.MULTILINE | re.S)
multilineCommentRegExp = re.compile(r"\/\*.*?\*\/", re.MULTILINE | re.S)
singleLineCommentRegExp = re.compile(r"\/\/.*?\n", re.MULTILINE | re.S)
return mangledName
builtins = []
+copyrights = []
+(output_base, _) = os.path.splitext(args.output)
-baseName = sys.argv[-1]
-builtin_definitions = sys.argv[1:-1]
-(output_base, _) = os.path.splitext(sys.argv[-1])
+if args.input_directory:
+ for file in os.listdir(args.input_directory):
+ args.input_file.append(os.path.join(args.input_directory, file))
-copyrights = []
-for file in builtin_definitions:
+for file in args.input_file:
if fnmatch.fnmatch(file, '*.js'):
(baseName, functions, objectCopyrights) = generateCode(file)
copyrights.extend(objectCopyrights)
builtinsImplementation.write("const int s_%sLength = %d;\n\n" % (codeReference, sourceLength + 1)) # + 1 for \n
builtinsImplementation.write("""
-FunctionExecutable* createBuiltinExecutable(VM& vm, UnlinkedFunctionExecutable* unlinkedExecutable, const SourceCode& source)
-{
- unsigned lineCount = unlinkedExecutable->lineCount();
- unsigned startColumn = 1;
- unsigned sourceLength = unlinkedExecutable->sourceLength();
- bool endColumnIsOnStartLine = !lineCount;
- unsigned endColumnExcludingBraces = unlinkedExecutable->unlinkedBodyEndColumn() + (endColumnIsOnStartLine ? 0 : 1);
- unsigned startOffset = unlinkedExecutable->startOffset();
- unsigned startOffsetExcludingOpenBrace = startOffset + 1;
- unsigned endOffsetExcludingCloseBrace = startOffset + sourceLength - 1;
- SourceCode bodySource(source.provider(), startOffsetExcludingOpenBrace, endOffsetExcludingCloseBrace, 0, startColumn);
- return FunctionExecutable::create(vm, bodySource, unlinkedExecutable, 0, lineCount, startColumn, endColumnExcludingBraces, false);
-}
-
#define JSC_DEFINE_BUILTIN_GENERATOR(codeName, functionName, argumentCount) \\
FunctionExecutable* codeName##Generator(VM& vm) \\
{ \\
- return createBuiltinExecutable(vm, vm.builtinExecutables()->codeName##Executable(), vm.builtinExecutables()->codeName##Source()); \\
+ return vm.builtinExecutables()->codeName##Executable()->link(vm, vm.builtinExecutables()->codeName##Source()); \\
}
JSC_FOREACH_BUILTIN(JSC_DEFINE_BUILTIN_GENERATOR)
builtinsImplementation.close()
if (not os.path.exists(output_base + ".h")) or (not filecmp.cmp(output_base + ".h.tmp", output_base + ".h", shallow=False)):
+ if (os.path.exists(output_base + ".h")):
+ os.remove(output_base + ".h")
os.rename(output_base + ".h.tmp", output_base + ".h")
else:
os.remove(output_base + ".h.tmp")
if (not os.path.exists(output_base + ".cpp")) or (not filecmp.cmp(output_base + ".cpp.tmp", output_base + ".cpp", shallow=False)):
+ if (os.path.exists(output_base + ".cpp")):
+ os.remove(output_base + ".cpp")
os.rename(output_base + ".cpp.tmp", output_base + ".cpp")
else:
os.remove(output_base + ".cpp.tmp")