OpenCores
URL https://opencores.org/ocsvn/ssbcc/ssbcc/trunk

Subversion Repositories ssbcc

[/] [ssbcc/] [trunk/] [ssbcc] - Blame information for rev 3

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 sinclairrf
#!/usr/bin/python2.7
2
 
3
################################################################################
4
#
5
# Copyright 2012, Sinclair R.F., Inc.
6
#
7
# Build an SSBCC system.
8
#
9
################################################################################
10
 
11
import math
12
import os
13
import re
14
import sys
15
import tempfile
16
 
17
from ssbccUtil import *;
18
from ssbccConfig import SSBCCconfig;
19
 
20
################################################################################
21
#
22
# Surround the program with a try ... except clause
23
#
24
################################################################################
25
 
26
try:
27
 
28
  ################################################################################
29
  #
30
  # Parse the command line arguments
31
  #
32
  ################################################################################
33
 
34
  #
35
  # Construct the command-line argument list parser
36
  #
37
 
38
  def validateFile(filename):
39
    if filename == '-':
40
      filename = '/dev/stdin';
41
    try:
42
      return file(filename,'r');
43
    except:
44
      raise SSBCCException('Error opening "%s"' % filename);
45
 
46
  import argparse
47
  argListParser = argparse.ArgumentParser(description='SSBCC system builder');
48
  argListParser.add_argument('-D', metavar='symbol', type=str, action='append', help='Define symbol');
49
  argListParser.add_argument('-G', metavar='parameter_name=value', type=str, action='append', help='Override parameter value');
50
  argListParser.add_argument('-I', metavar='include_dir', type=str, action='append', help='Add search directory for included files and peripherals');
51 3 sinclairrf
  argListParser.add_argument('-M', metavar='macropath', action='append', help='Macro search path');
52 2 sinclairrf
  argListParser.add_argument('-P', metavar='peripheral_name[="parameters"]', type=str, action='append', help='Add peripheral');
53
  argListParser.add_argument('-o', metavar='outCoreName', type=str, help='output core name');
54
  argListParser.add_argument('-q', action='store_true', help='quiet');
55
  argListParser.add_argument('--define-clog2', action='store_true', help='define clog2 instead of using built-in $clog2');
56
  argListParser.add_argument('--display-opcode', action='store_true', help='add 3-letter decode of opcode (for trace viewer)');
57 3 sinclairrf
  argListParser.add_argument('--rand-instr-mem', action='store_true', help='fill unused instruction memory with random values');
58
  argListParser.add_argument('--synth-instr-mem', type=str, help='synthesis constraint for instruction memory');
59 2 sinclairrf
  argListParser.add_argument('--verilator-tracing-on', action='store_true', help='show all signals in verilator waveform files');
60
  argListParser.add_argument('filename', metavar='filename', type=validateFile, help='SSBCC configuration file');
61
  argList = argListParser.parse_args();
62
 
63
  #
64
  # Set the command-line dependent configuration parameters.
65
  #
66
 
67
  config = SSBCCconfig();
68
 
69
  config.Set('define_clog2',argList.define_clog2);
70 3 sinclairrf
  config.Set('rand_instr_mem',argList.rand_instr_mem);
71 2 sinclairrf
  config.Set('verilator_tracing_on',argList.verilator_tracing_on);
72
 
73
  if argList.display_opcode:
74
    config.functions['display_opcode'] = True;
75
 
76
  if argList.D:
77
    for symbol in argList.D:
78
      config.AddSymbol(symbol);
79
 
80 3 sinclairrf
  if argList.I:
81
    for pathString in argList.I:
82
      if not os.path.isdir(pathString):
83
        raise SSBCCException('Bad path string:  "%s"' % pathString);
84
      config.AppendIncludePath(pathString);
85
      config.InsertPeripheralPath(pathString);
86
 
87 2 sinclairrf
  if argList.o:
88
    config.Set('outCoreName',argList.o);
89
  else:
90
    config.Set('outCoreName',os.path.splitext(os.path.basename(argList.filename.name))[0]);
91
 
92 3 sinclairrf
  if argList.synth_instr_mem:
93
    config.Set('synth_instr_mem',argList.synth_instr_mem);
94
  else:
95
    config.Set('synth_instr_mem',None);
96
 
97 2 sinclairrf
  #
98
  # Read the configuration file into a line-by-line buffer.
99 3 sinclairrf
  # Note:  argList.filename is a file handle, so no paths will be searched by
100
  #        LoadFile.  This is ensured by setting config to None.
101 2 sinclairrf
  #
102
 
103
  filename = argList.filename.name;
104 3 sinclairrf
  configList = LoadFile(argList.filename,None);
105 2 sinclairrf
  ifstack = list();
106
 
107
  configListStack = list();
108
 
109
  #
110
  # Read the configuration file.
111
  #
112
 
113
  bufLine = "";
114
  compiler = [];
115
  user_header = list();
116
  while configList or configListStack:
117
    # If the current file has ended, then proceed to the next file.
118
    if not configList:
119
      if not len(bufLine) == 0:
120
        raise SSBCCException('Malformed configuration command at the end of %s' % filename);
121
      if ifstack:
122
        raise SSBCCException('%d unmatched conditional(s) at end of %s' % (len(ifstack),filename,));
123
      (filename,configList,ifstack) = configListStack.pop();
124
      continue;
125
    # Get the next line to process and its line number.
126
    (tmpLine,ixLine) = configList.pop(0);
127
    # Use the start line of a sequence of lines for error messages.
128
    if not bufLine:
129
      loc = '%s:%d' % (filename,ixLine,);
130
    # Merge continuation lines.
131
    bufLine += tmpLine;
132
    if bufLine and bufLine[-1] == '\\':
133
      bufLine = bufLine[:-1];
134
      continue;
135
    line = bufLine;
136
    bufLine = "";
137
    # Reject blank and comment lines
138
    if re.match(r'\s*(#.*)?$',line):
139
      pass;
140
    # .ELSE
141
    elif re.match(r'\s*\.ELSE\b',line):
142
      if not ifstack:
143
        raise SSBCCException('unmatched ".ELSE" at %s' % loc);
144
      ifstack[-1] = not ifstack[-1];
145
    # .ENDIF
146
    elif re.match(r'\s*\.ENDIF\b',line):
147
      if not ifstack:
148
        raise SSBCCException('unmatched ".ENDIF" at %s' % loc);
149
      ifstack.pop();
150
    # .IFDEF conditional
151
    elif re.match(r'\s*\.IFDEF\b',line):
152
      cmd = re.findall(r'\s*\.IFDEF\s+(\w+)\s*$',line);
153
      if not cmd:
154
        raise SSBCCException('Malformed ".IFDEF" configuration command on %s' % loc);
155
      cmd = cmd[0];
156
      ifstack.append(config.IsSymbol(cmd));
157
    # .IFNDEF conditional
158
    elif re.match(r'\s*\.IFNDEF\b',line):
159
      cmd = re.findall(r'\s*\.IFNDEF\s+(\w+)\s*$',line);
160
      if not cmd:
161
        raise SSBCCException('Malformed ".IFNDEF" configuration command on %s' % loc);
162
      cmd = cmd[0];
163
      ifstack.append(not config.IsSymbol(cmd));
164
    elif re.match(r'\s*.INCLUDE\b',line):
165
      cmd = re.findall(r'\s*\.INCLUDE\s+(\S+)\s*$',line);
166
      if not cmd:
167
        raise SSBCCException('Malformed ".INCLUDE" configuration command on %s' % loc);
168
      configListStack.append((filename,configList,ifstack,));
169
      filename = cmd[0];
170 3 sinclairrf
      configList = LoadFile(filename,config);
171 2 sinclairrf
      ifstack = list();
172
    # Consume configuration commands disabled by conditionals
173
    elif ifstack and not ifstack[-1]:
174
      pass;
175
    # ARCHITECTURE
176
    elif re.match(r'\s*ARCHITECTURE\b',line):
177
      if config.Exists('architecture'):
178
        raise SSBCCException('ARCHITECTURE already specified before %s' % loc);
179
      cmd = re.findall(r'\s*ARCHITECTURE\s+(\S+)\s+(\S+)$',line);
180
      if not cmd:
181
        raise SSBCCException('Malformed ARCHITECTURE configuration command at %s: "%s"' % (loc,line,));
182
      cmd = cmd[0];
183
      config.Set('architecture',cmd[0]);
184
      config.Set('hdl',cmd[1]);
185
      config.Set('corepath',os.path.join(sys.path[0],config.Get('architecture')));
186
      if not os.path.isdir(config.Get('corepath')):
187
        raise SSBCCException('Architecture "%s" does not exist at %s' % (cmd,loc,));
188
      config.InsertPeripheralPath(os.path.join(config.Get('corepath'),'peripherals'));
189
      # TODO -- move these assignments into an object
190
      config.Set('data_width',8);
191
    # ASSEMBLY language for processor code
192
    elif re.match(r'\s*ASSEMBLY\b',line):
193
      cmd = re.findall(r'\s*ASSEMBLY\s+(\S.*)',line);
194
      compiler = ('asm',cmd[0],);
195
    # COMBINE
196
    elif re.match(r'\s*COMBINE\b',line):
197
      config.ProcessCombine(loc,line);
198
    # CONSTANTS
199
    elif re.match(r'\s*CONSTANT\b',line):
200
      if not config.Exists('architecture'):
201
        raise SSBCCException('"CONSTANT"s cannot be defined before the "ARCHITECTURE" is defined at %s' % loc);
202
      cmd = re.findall(r'\s*CONSTANT\s+(C_\w+)\s+(\w+)\s*$',line);
203
      if not cmd:
204
        raise SSBCCException('Malformed "CONSTANT" configuration command on %s: "%s"' % (loc,line,));
205
      cmd = cmd[0];
206
      config.AddConstant(cmd[0],cmd[1],loc);
207
    # DATA_STACK
208
    elif re.match(r'\s*DATA_STACK\b',line):
209
      if config.Exists('data_stack'):
210
        raise SSBCCException('DATA_STACK already defined before %s' % loc);
211
      cmd = re.findall(r'\s*DATA_STACK\s+([1-9]\d*)',line);
212
      if not cmd:
213
        raise SSBCCException('Malformed "DATA_STACK" configuration command on %s: "%s"' % (loc,line,));
214
      x = int(cmd[0]);
215
      if math.modf(math.log(x,2))[0] != 0:
216
        raise SSBCCException('DATA_STACK must be set to a power of 2, not %d, at %s' % (x,loc,));
217
      if x < 8:
218
        raise SSBCCException('DATA_STACK must be at least 8, not %d, at %s' % (x,loc,));
219
      config.Set('data_stack',int(cmd[0]));
220
    # INPORT
221
    elif re.match(r'\s*INPORT\b',line):
222
      if not config.Exists('architecture'):
223
        raise SSBCCException('"INPORT"s cannot be defined before the "ARCHITECTURE" is defined at %s' % loc);
224
      config.ProcessInport(loc,line);
225
    # INSTRUCTION
226
    elif re.match(r'\s*INSTRUCTION\b',line):
227
      if config.Exists('nInstructions'):
228
        raise SSBCCException('INSTRUCTION already specified before %s' % loc);
229
      cmd = re.findall(r'\s*INSTRUCTION\s+([1-9]\d*\*?[1-9]?\d*)\s*$',line);
230
      if not cmd:
231
        raise SSBCCException('Malformed "INSTRUCTION" configuration command at %s: "%s"' % (loc,line,));
232
      config.SetMemoryBlock('nInstructions',cmd[0],(loc,line,));
233
    # INVERT_RESET
234
    elif re.match(r'\s*INVERT_RESET\s*$',line):
235
      if (config.Exists('invertReset')):
236
        raise SSBCCException('INVERT_RESET already specified before %s' % loc);
237
      config.Set('invertReset',True);
238
    # LOCALPARM
239
    elif re.match(r'\s*LOCALPARAM\b',line):
240
      cmd = re.findall(r'\s*LOCALPARAM\s+(L_\w+)\s+(\S+)$',line);
241
      if (not cmd) or (len(cmd[0]) != 2):
242
        raise SSBCCException('Malformed LOCALPARAM configuration command at %s: "%s"' % (loc,line,));
243
      cmd = cmd[0];
244
      config.AddParameter(cmd[0],cmd[1],loc);
245
    # MEMORY
246
    elif re.match(r'\s*MEMORY\b',line):
247
      if not config.Exists('architecture'):
248
        raise SSBCCException('"MEMORY"s cannot be defined before the "ARCHITECTURE" is defined at %s' % loc);
249
      # TODO -- make the maximum number of memories architecture dependent
250
      if config.NMemories() >= 4:
251
        raise SSBCCException('Program is limited to 4 memories');
252
      cmd = re.findall(r'\s*MEMORY\s+(RAM|ROM)\s+([A-Za-z]\w*)\s+(\d+)\s*$',line);
253
      if (not cmd) or (len(cmd[0]) != 3):
254
        raise SSBCCException('Malformed MEMORY configuration command at %s: "%s"' % (loc,line,));
255
      config.AddMemory(cmd[0],loc);
256
    # OUTPORT
257
    elif re.match(r'\s*OUTPORT\b',line):
258
      if not config.Exists('architecture'):
259
        raise SSBCCException('"OUTPORT"s cannot be defined before the "ARCHITECTURE" is defined at %s' % loc);
260
      config.ProcessOutport(line,loc);
261
    # PARAMETER
262
    elif re.match(r'\s*PARAMETER\b',line):
263
      cmd = re.findall(r'\s*PARAMETER\s+(G_\w+)\s+(\S+)$',line);
264
      if (not cmd) or (len(cmd[0]) != 2):
265
        raise SSBCCException('Malformed PARAMETER configuration command at %s: "%s"' % (loc,line,));
266
      cmd = cmd[0];
267
      config.AddParameter(cmd[0],cmd[1],loc);
268
    # PERIPHERAL
269
    elif re.match(r'\s*PERIPHERAL\b',line):
270
      if not config.Exists('architecture'):
271
        raise SSBCCException('"PERIPHERAL"s cannot be defined before the "ARCHITECTURE" is defined at %s' % loc);
272
      config.ProcessPeripheral(loc,line);
273
    # PORTCOMMENT
274
    elif re.match(r'\s*PORTCOMMENT\b',line):
275
      cmd = re.findall(r'\s*PORTCOMMENT\s+(.*)',line);
276
      config.AddIO(cmd[0],0,'comment',loc);
277
    # RETURN_STACK
278
    elif re.match(r'\s*RETURN_STACK\b',line):
279
      if config.Exists('return_stack'):
280
        raise SSBCCException('RETURN_STACK already specified before %s' % loc);
281
      cmd = re.findall(r'\s*RETURN_STACK\s+([1-9]\d*)',line);
282
      if not cmd:
283
        raise SSBCCException('Malformed "RETURN_STACK" configuration command at %s: "%s"' % (loc,line,));
284
      config.Set('return_stack',int(cmd[0]));
285
    # SRAM_WIDTH
286
    elif re.match(r'\s*SRAM_WIDTH\b',line):
287
      if config.Exists('sram_width'):
288
        raise SSBCCException('SRAM_WIDTH already specified before %s' % loc);
289
      cmd = re.findall(r'\s*SRAM_WIDTH\s+([1-9]\d*)',line);
290
      if not cmd:
291
        raise SSBCCException('Malformed "SRAM_WIDTH" configuration command %s: "%s"' % (loc,line,));
292
      config.Set('sram_width',int(cmd[0]));
293
    # USER_HEADER
294
    elif re.match(r'\s*USER_HEADER\b',line):
295
      user_header_done = False;
296 3 sinclairrf
      while configList:
297
        (line,ixLine) = configList.pop(0);
298
        if re.match(r'\s*END_USER_HEADER\b',line):
299 2 sinclairrf
          user_header_done = True;
300
          break;
301
        user_header.append(line);
302
      if not user_header_done:
303
        raise SSBCCException('No "END_USER_HEADER" found for "USER_HEADER" at %s' % loc);
304
    # error
305
    else:
306
      raise SSBCCException('Unrecognized configuration command at %s: "%s"' % (loc,line,));
307
  if bufLine:
308
    raise SSBCCException('Malformed last line(s): "%s"' % bufLine);
309
 
310
  if ifstack:
311
    raise SSBCCException('%d unmatched conditional(s) at end of %s' % (len(ifstack),filename,));
312
 
313
  #
314
  # Incorporate command-line specified parameter and localparam values.
315
  #
316
 
317
  if argList.G:
318
    for parameter in argList.G:
319
      if not re.match(r'[LG]_\w+=\S+$',parameter):
320
        raise SSBCCException('Malformed parameter specification: "%s"' % parameter);
321
      cmd = re.findall(r'([LG]_\w+)=(\S+)',parameter);
322
      cmd = cmd[0];
323
      config.OverrideParameter(cmd[0],cmd[1]);
324
 
325
  #
326
  # Append peripherals from command-line.
327
  #
328
 
329
  if argList.P:
330
    for peripheral in argList.P:
331
      config.ProcessPeripheral(-1,'PERIPHERAL '+peripheral);
332
 
333
  #
334
  # Set unspecified default values
335
  #
336
 
337
  if not config.Exists('sram_width'):
338
    config.Set('sram_width',9);
339
  if not config.Exists('invertReset'):
340
    config.Set('invertReset',False);
341
 
342
  #
343
  # end-of-file processing
344
  #
345
 
346
  if not config.Exists('architecture'):
347
    raise SSBCCException('Required ARCHITECTURE configuration command missing');
348
  if not config.Exists('data_stack'):
349
    raise SSBCCException('Required DATA_STACK configuration command missing');
350
  if not config.Exists('nInstructions'):
351
    raise SSBCCException('Required INSTRUCTION configuration command missing');
352
  if not config.Exists('return_stack'):
353
    raise SSBCCException('Required RETURN_STACK configuration command missing');
354
 
355
  # Ensure reasonable values
356
  if config.Get('nInstructions')['length'] > 2**13:
357
    raise SSBCCException('Instruction space cannot exceed %d at %s: "%s"' % (2**13,loc,line,));
358
 
359
  # Add memories that are not combined into singleton entries in the "combined"
360
  # list and complete the address range assignments.
361
  config.CompleteCombines();
362
 
363
  ################################################################################
364
  #
365
  # Compile the processor code and read the tables it generated.
366
  #
367
  ################################################################################
368
 
369
  # Generate peripheral libraries (if any).
370
  for ix in range(len(config.peripheral)):
371
    config.peripheral[ix].GenAssembly(config);
372
 
373
  # Compute the file name to store the assembler output
374
  assemblerOutput = os.path.splitext(argList.filename.name)[0]+'.9x8-meta'
375
 
376
  # Compute the command to invoke the compiler.
377
  if not compiler:
378
    raise SSBCCException('ASSEMBLY configuration command is missing');
379
  cmd = os.path.join(config.Get('corepath'), compiler[0]);
380
  for name in config.constants:
381
    cmd += (' -C %s=%s' % (name,config.constants[name],));
382
  for ix in range(len(config.parameters)):
383
    cmd += (' -G %s' % config.parameters[ix][0]);
384
  for ix in range(config.NInports()):
385
    cmd += (' -I %s=%d' % (config.inports[ix][0],ix));
386
  for ix in range(config.NOutports()):
387
    if config.IsStrobeOnlyOutport(config.outports[ix]):
388
      cmd += (' -R %s=%d' % (config.outports[ix][0],ix));
389
    else:
390
      cmd += (' -O %s=%d' % (config.outports[ix][0],ix));
391
  for memNameLength in config.MemoryNameLengthList():
392
    cmd += (' -S %s=%d' % memNameLength);
393
  for signalNameLength in config.SignalLengthList():
394
    cmd += (' -S %s=%d' % signalNameLength);
395
  cmd += ' -o ' + assemblerOutput;
396
  for stack_name in ('data_stack','return_stack',):
397
    cmd += ' -s %s=%d' % (stack_name,config.config[stack_name],);
398 3 sinclairrf
  cmd += ' -L %s' % os.path.join(sys.path[0],'lib','9x8');
399
  if argList.M:
400
    for path in argList.M:
401
      cmd += ' -M %s' % path;
402
  cmd += ' -M %s' % os.path.join(sys.path[0],'macros','9x8');
403 2 sinclairrf
  if argList.I:
404
    for pathString in argList.I:
405
      cmd += ' -L %s' % pathString;
406
  cmd += ' ' + compiler[1];
407
 
408
  # Invoke the compiler and exit if it failed.
409
  if not argList.q:
410
    print 'Invoking the assember with the following command:  ' + cmd;
411
  cmdStatus = os.system(cmd);
412
  if cmdStatus != 0:
413
    raise SSBCCException('Running the assembler');
414
 
415
  # Read the assembler output tables.
416
  fpAssemberOutput = open(assemblerOutput,'r');
417
  ixLine = 0;
418
  programBody = list();
419
  programBodyLength = 0;
420
  for line in fpAssemberOutput:
421
    ixLine = ixLine + 1;
422
    # blank line
423
    if re.match('^\s*$',line):
424
      continue;
425
    # memory type, name, index, and length
426
    elif re.match(':memory',line):
427
      cmd = re.findall(':memory (\S+) (\S+) (\S+) (\S+)',line);
428
      cmd = cmd[0];
429
      memName = cmd[1];
430
      if not config.IsMemory(memName):
431
        raise SSBCCException('%s "%s" not declared in %s' % (cmd[0],memName,argList.filename,));
432
      memParam = config.GetMemoryParameters(memName);
433
      if cmd[0] != memParam['type']:
434
        raise SSBCCException('Type of memory "%s" is inconsistent' % memName);
435
      if int(cmd[3]) > memParam['maxLength']:
436
        raise SSBCCException('Length of memory "%s" is %s which exceeds limit of %d' % (memName,cmd[3],memParam['maxLength'],));
437
      memoryBody = list();
438
      for line in fpAssemberOutput:
439
        ixLine = ixLine + 1;
440
        if len(line) > 1:
441
          memoryBody.append(line)
442
        else:
443
          break;
444
      config.SetMemoryParameters(memParam,dict(bank=int(cmd[2]),length=int(cmd[3]),body=memoryBody));
445
    # program .main, optional .interrupt, and length
446
    elif re.match(':program',line):
447
      cmd = re.findall(':program (\d+) (\S+) (\d+)',line);
448
      mainStart = int(cmd[0][0]);
449
      if cmd[0][1] == '[]':
450
        interruptStart = -1;
451
      else:
452
        interruptStart = int(cmd[0][1]);
453
      mainLength = int(cmd[0][2]);
454
      for line in fpAssemberOutput:
455
        ixLine = ixLine + 1;
456
        while line and line[-1] in ('\n','\r',):
457
          line = line[:-1];
458
        if not line:
459
          break;
460
        programBody.append(line);
461
        if line[0] != '-':
462
          programBodyLength = programBodyLength + 1;
463
      if programBodyLength != mainLength:
464
        raise SSBCCException('Program Bug:  program length doesn\'t match declared length');
465
      maxProgramBodyLength = config.Get('nInstructions')['length'];
466
      if programBodyLength > maxProgramBodyLength:
467
        raise SSBCCException('Program body length = %d is longer than the allocated instruction table = %d' % (programBodyLength,maxProgramBodyLength,));
468
    else:
469
      raise Exception('Program Bug:  Unrecognized line at %s:%d :  "%s"' % (fpAssemberOutput.filename,ixLine,line,));
470
 
471
  ################################################################################
472
  #
473
  # Ensure the processor has been consistently defined.
474
  #
475
  ################################################################################
476
 
477
  # Ensure all memories are used.
478
  for ixMem in range(config.NMemories()):
479
    memParam = config.GetMemoryParameters(ixMem);
480
    if 'length' not in memParam:
481
      raise SSBCCException('Memory "%s" not used in program' % memParam['name']);
482
 
483
  ################################################################################
484
  #
485
  # Generate the processor core.
486
  #
487
  ################################################################################
488
 
489
  #
490
  # Access the language-specific core generator and core.
491
  #
492
 
493
  if config.Get('hdl') == 'Verilog':
494
    ssbccGenFile = 'ssbccGenVerilog.py';
495
  elif config.Get('hdl') == 'VHDL':
496
    ssbccGenFile = 'ssbccGenVHDL.py';
497
  else:
498
    raise SSBCCException('Unrecognized hdl = "%s"' % config.Get('hdl'));
499
 
500
  ssbccGenFile = os.path.join(config.Get('corepath'),ssbccGenFile);
501
  if not os.path.isfile(ssbccGenFile):
502
    raise SSBCCException('Core generator "%s" missing for hdl = "%s"' % (ssbccGenFile,config.Get('hdl'),));
503
  execfile(ssbccGenFile);
504
 
505
  rawCoreName = os.path.join(config.Get('corepath'),genCoreName());
506
  if not os.path.isfile(rawCoreName):
507
    raise SSBCCException('Core "%s% missing for hdl = "%s"' % (rawCoreName,config.Get('hdl'),));
508
  fpRawCore = open(rawCoreName,'r');
509
 
510
  outName = genOutName(config.Get('outCoreName'));
511
  fpOutCore = open(outName,'wt');
512
 
513
  memFileName = re.sub(r'\.v.*','.mem',outName);
514
  fpMemFile = open(memFileName,'wt');
515
 
516
  #
517
  # Loop through the core, copying or filling in the file as required.
518
  #
519
 
520
  for line in fpRawCore:
521
    if not re.match(r'..@SSBCC@',line):
522
      if re.match(r'\s*(reg|wire)\s',line):
523
        cmd = re.findall(r'\s*(reg|wire)\s+([[][^]]+]\s+)?(\w+)\b',line);
524
        if config.IsSymbol(cmd[0][-1]):
525
          raise SSBCCException('Symbol "%s" is used by the core and cannot be used by peripherals, etc.' % cmd[0][-1]);
526
      fpOutCore.write(line);
527
      continue;
528
    fillCommand = re.findall(r'..@SSBCC@\s+(\S+)',line)[0];
529
    # functions and tasks
530
    if fillCommand == "functions":
531
      genFunctions(fpOutCore,config);
532
    # inports
533
    elif fillCommand == 'inports':
534
      genInports(fpOutCore,config);
535
    # localparam
536
    elif fillCommand == 'localparam':
537
      genLocalParam(fpOutCore,config);
538
    # memories
539
    elif fillCommand == 'memories':
540
      genMemories(fpOutCore,fpMemFile,config,programBody);
541
    # module
542
    elif fillCommand == 'module':
543
      genModule(fpOutCore,config);
544
    # outports
545
    elif fillCommand == 'outports':
546
      genOutports(fpOutCore,config);
547
    # peripherals
548
    elif fillCommand == 'peripherals':
549
      if not config.peripheral:
550
        fpOutCore.write('//\n// No peripherals\n//\n');
551
      for ix in range(len(config.peripheral)):
552
        if ix != 0:
553
          fpOutCore.write('\n');
554
        config.peripheral[ix].GenHDL(fpOutCore,config);
555
    # "s_memory" declaration
556
    elif fillCommand == 's_memory':
557
      if config.NMemories() == 0:
558
        fpOutCore.write('wire [7:0] s_memory = 8\'h00;\n');
559
      else:
560
        fpOutCore.write('wire [7:0] s_memory;\n');
561
    # additional signals
562
    elif fillCommand == 'signals':
563
      genSignals(fpOutCore,config);
564
    # user_header
565
    elif fillCommand == 'user_header':
566
      genUserHeader(fpOutCore,user_header);
567
    # Verilator tracing on/off
568
    elif fillCommand == "verilator_tracing":
569
      if config.Get('verilator_tracing_on'):
570
        fpOutCore.write('/* verilator tracing_on */\n');
571
      else:
572
        fpOutCore.write('/* verilator tracing_off */\n');
573
    # error
574
    else:
575
      print 'WARNING:  Unimplemented command ' + fillCommand;
576
 
577
  #
578
  # Write package file (for use in VHDL or mixed-language projects)
579
  #
580
 
581
  import ssbccGenVhdlPkg
582
  ssbccGenVhdlPkg.genVhdlPkg(config);
583
 
584
################################################################################
585
#
586
# Terminating except clause
587
#
588
################################################################################
589
 
590
except SSBCCException, msg:
591
  print >> sys.stderr, 'FATAL ERROR:  ' + str(msg);
592
  exit(1);

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.