#!/usr/bin/env python# Copyright 2014 the V8 project authors. All rights reserved.# Use of this source code is governed by a BSD-style license that can be# found in the LICENSE file."""This program either generates the parser files for Torque, generatingthe source and header files directly in V8's src directory."""importsubprocessimportsysimportrefromsubprocessimportPopen,PIPEiflen(sys.argv)<2orlen(sys.argv)>3:print"invalid number of arguments"sys.exit(-1)use_stdout=Trueiflen(sys.argv)==3andsys.argv[1]=='-i':use_stdout=Falsefilename=sys.argv[len(sys.argv)-1]withopen(filename,'r')ascontent_file:content=content_file.read()p=Popen(['clang-format','-assume-filename=.ts'],stdin=PIPE,stdout=PIPE,stderr=PIPE)output,err=p.communicate(content)rc=p.returncodeif(rc<>0):sys.exit(rc);ifuse_stdout:printoutputelse:output_file=open(filename,'w')output_file.write(output);output_file.close()