def syntax_parse(argdata, inputfilename, bsvdefines, bsvpath): global globalfilename globalfilename = inputfilename data = bsvpreprocess.preprocess(inputfilename, argdata + '\n', bsvdefines, bsvpath) lexer = lex.lex(errorlog=lex.NullLogger()) parserdir=scripthome+'/syntax' if not os.path.isdir(parserdir): os.makedirs(parserdir) if not (parserdir in sys.path): sys.path.append(parserdir) parser = yacc.yacc(optimize=1,errorlog=yacc.NullLogger(),outputdir=parserdir,debugfile=parserdir+'/parser.out') if noisyFlag: print 'Parsing:', inputfilename if parseDebugFlag: return parser.parse(data,debug=1) return parser.parse(data)
for f in options.bsvfile: abspaths[os.path.basename(f)] = f makef = open(options.output, "w") makef.write("# BSV dependences\n") makef.write("BSVDEFINES = %s\n" % " ".join(["-D %s" % d for d in options.bsvdefine])) makef.write("BSVPATH = %s\n" % ":".join(bsvpath)) makef.write("\n") makef.write("OBJMAKEFILE_DEP = %s\n" % " ".join(["$(wildcard %s/*.bsv)" % path for path in bsvpath])) makef.write("\n") for bsvfilename in options.bsvfile: vf = open(bsvfilename, "r") basename = os.path.basename(bsvfilename) (name, ext) = os.path.splitext(basename) source = vf.read() preprocess = bsvpreprocess.preprocess(bsvfilename, source, options.bsvdefine, bsvpath) packages = [] includes = [] synthesizedModules = [] synthesize = False for line in preprocess.split("\n"): # print 'bsvdepend: %s' % line m = re.match('//`include "([^"]+)"', line) m1 = re.match("//`include(.*)", line) if m: iname = m.group(1) if iname in abspaths: iname = abspaths[iname] else: iname = "obj/%s" % iname # print 'm:', m.group(1), iname
def bsvDependencies(bsvfile, allBsv=False, bluespecdir=None, argbsvpath=[], bsvdefine=[]): """Return the list of dependencies [(NAME,BSVFILENAME,PACKAGES,INCLUDES,SYNTHESIZEDMODULES)] of BSVFILE, adding the list BSVPATH to the directories to explore for dependencies. The boolean ALLBSV will generate entries for all BSV files on path. The string BLUESPECDIR will add the Prelude of Bsv in packages. The BSVDEFINE argument is passed to the preprocessor. """ bsvpath = [] for p in argbsvpath: ps = p.split(':') bsvpath.extend(ps) bsvpackages = getBsvPackages(bluespecdir) project_packages = {} if allBsv: for d in bsvpath: for bsvfilename in glob.glob('%s/*.bsv' % d): package_name = os.path.basename(bsvfilename) if bsvfilename not in bsvfile and package_name not in project_packages: bsvfile.append(bsvfilename) project_packages[package_name] = bsvfilename abspaths = {} for f in bsvfile: abspaths[os.path.basename(f)] = f for d in bsvpath: for f in glob.glob('%s/*' % d): abspaths[os.path.basename(f)] = f generated = [] for bsvfilename in bsvfile: vf = open(bsvfilename, 'r') basename = os.path.basename(bsvfilename) (name, ext) = os.path.splitext(basename) source = vf.read() preprocess = bsvpreprocess.preprocess(bsvfilename, source, bsvdefine, bsvpath) packages = [] includes = [] synthesizedModules = [] synthesize = False for line in preprocess.split('\n'): m = re.match('//`include "([^\"]+)"', line) m1 = re.match('//`include(.*)', line) if m: iname = m.group(1) if iname in abspaths: iname = abspaths[iname] else: iname = 'obj/%s' % iname includes.append(iname) elif m1: sys.stderr.write('bsvdepend %s: unhandled `include %s\n' % (bsvfilename, m1.group(1))) if re.match('^//', line): continue m = re.match('import ([A-Za-z0-9_]+)\w*', line) if m: pkg = m.group(1) if pkg not in packages and pkg not in bsvpackages: packages.append(pkg) if synthesize: m = re.match('\s*module\s+([A-Za-z0-9_]+)', line) if m: synthesizedModules.append(m.group(1)) else: sys.stderr.write('bsvdepend: in %s expecting module: %s\n' % (bsvfilename, line)) synth = line.find('(* synthesize *)') attr = line.find('(* ') if synth >= 0: synthesize = True elif attr >= 0: pass # no change to synthesize else: synthesize = False pass generated.append((bsvfilename,packages,includes,synthesizedModules)) vf.close() return (generated,bsvpath)
def bsvDependencies(bsvfile, allBsv=False, bluespecdir=None, argbsvpath=[], bsvdefine=[]): """Return the list of dependencies [(NAME,BSVFILENAME,PACKAGES,INCLUDES,SYNTHESIZEDMODULES)] of BSVFILE, adding the list BSVPATH to the directories to explore for dependencies. The boolean ALLBSV will generate entries for all BSV files on path. The string BLUESPECDIR will add the Prelude of Bsv in packages. The BSVDEFINE argument is passed to the preprocessor. """ bsvpath = [] for p in argbsvpath: ps = p.split(':') bsvpath.extend(ps) bsvpackages = getBsvPackages(bluespecdir) if allBsv: for d in bsvpath: for bsvfilename in glob.glob('%s/*.bsv' % d): if bsvfilename not in bsvfile: bsvfile.append(bsvfilename) abspaths = {} for f in bsvfile: abspaths[os.path.basename(f)] = f for d in bsvpath: for f in glob.glob('%s/*' % d): abspaths[os.path.basename(f)] = f generated = [] for bsvfilename in bsvfile: vf = open(bsvfilename, 'r') basename = os.path.basename(bsvfilename) (name, ext) = os.path.splitext(basename) source = vf.read() preprocess = bsvpreprocess.preprocess(bsvfilename, source, bsvdefine, bsvpath) packages = [] includes = [] synthesizedModules = [] synthesize = False for line in preprocess.split('\n'): m = re.match('//`include "([^\"]+)"', line) m1 = re.match('//`include(.*)', line) if m: iname = m.group(1) if iname in abspaths: iname = abspaths[iname] else: iname = 'obj/%s' % iname includes.append(iname) elif m1: sys.stderr.write('bsvdepend %s: unhandled `include %s\n' % (bsvfilename, m1.group(1))) if re.match('^//', line): continue m = re.match('import ([A-Za-z0-9_]+)\w*', line) if m: pkg = m.group(1) if pkg not in packages and pkg not in bsvpackages: packages.append(pkg) if synthesize: m = re.match('\s*module\s+([A-Za-z0-9_]+)', line) if m: synthesizedModules.append(m.group(1)) else: sys.stderr.write('bsvdepend: in %s expecting module: %s\n' % (bsvfilename, line)) synth = line.find('(* synthesize *)') attr = line.find('(* ') if synth >= 0: synthesize = True elif attr >= 0: pass # no change to synthesize else: synthesize = False pass generated.append((bsvfilename,packages,includes,synthesizedModules)) vf.close() return (generated,bsvpath)