Deleted Added
sdiff udiff text old ( 8452:3f2c329e9046 ) new ( 8453:82fc1267d3bb )
full compact
1# Copyright (c) 2009 The Hewlett-Packard Development Company
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 37 unchanged lines hidden (view full) ---

46 sm_file = sm_file.strip()
47 if not sm_file:
48 continue
49 if sm_file.startswith("#"):
50 continue
51 yield sm_file
52
53class SLICC(Grammar):
54 def __init__(self, protocol, **kwargs):
55 self.decl_list_vec = []
56 self.protocol = protocol
57 self.symtab = SymbolTable(self)
58
59 def codeFormatter(self, *args, **kwargs):
60 code = code_formatter(*args, **kwargs)
61 code['protocol'] = self.protocol
62 return code
63
64 def parse(self, filename):
65 try:
66 decl_list = self.parse_file(filename)
67 except ParseError, e:
68 sys.exit(str(e))
69 self.decl_list_vec.append(decl_list)
70
71 def _load(self, *filenames):
72 filenames = list(filenames)
73 while filenames:
74 f = filenames.pop(0)
75 if isinstance(f, (list, tuple)):
76 filenames[0:0] = list(f)
77 continue
78
79 yield f
80 if f.endswith(".slicc"):
81 dirname,basename = os.path.split(f)
82 filenames[0:0] = [ os.path.join(dirname, x) \
83 for x in read_slicc(f)]
84 else:
85 assert f.endswith(".sm")
86 self.parse(f)
87
88 def load(self, *filenames, **kwargs):
89 verbose = kwargs.pop("verbose", False)
90 if kwargs:
91 raise TypeError
92
93 gen = self._load(*filenames)
94 if verbose:
95 return gen
96 else:
97 # Run out the generator if we don't want the verbosity
98 for foo in gen:
99 pass
100
101 def findMachines(self):
102 for decl_list in self.decl_list_vec:
103 decl_list.findMachines()
104
105 def generate(self):
106 for decl_list in self.decl_list_vec:
107 decl_list.generate()
108
109 def writeCodeFiles(self, code_path):
110 util.makeDir(code_path)
111 self.symtab.writeCodeFiles(code_path)
112
113 def writeHTMLFiles(self, code_path):
114 util.makeDir(code_path)
115 self.symtab.writeHTMLFiles(code_path)
116
117 def files(self):
118 f = set([
119 'MachineType.cc',
120 'MachineType.hh',
121 'Types.hh' ])
122
123 for decl_list in self.decl_list_vec:

--- 611 unchanged lines hidden ---