Line 6... |
Line 6... |
#
|
#
|
################################################################################
|
################################################################################
|
|
|
import math
|
import math
|
import os
|
import os
|
|
import random
|
import re
|
import re
|
|
|
from ssbccUtil import *;
|
from ssbccUtil import *;
|
|
|
################################################################################
|
################################################################################
|
Line 185... |
Line 186... |
for ixBlock in range(instructionMemory['nBlocks']):
|
for ixBlock in range(instructionMemory['nBlocks']):
|
if instructionMemory['nBlocks'] == 1:
|
if instructionMemory['nBlocks'] == 1:
|
memName = 's_opcodeMemory';
|
memName = 's_opcodeMemory';
|
else:
|
else:
|
memName = instructionMemNameFormat % ixBlock;
|
memName = instructionMemNameFormat % ixBlock;
|
|
if config.Get('synth_instr_mem'):
|
|
fp.write('%s ' % config.Get('synth_instr_mem'));
|
fp.write('reg [%d:0] %s[%d:0];\n' % (instruction_mem_width-1,memName,instructionMemory['blockSize']-1,));
|
fp.write('reg [%d:0] %s[%d:0];\n' % (instruction_mem_width-1,memName,instructionMemory['blockSize']-1,));
|
# Declare data stack RAM and return stacks RAM if they aren't combined into other memories.
|
# Declare data stack RAM and return stacks RAM if they aren't combined into other memories.
|
for memType in ('DATA_STACK','RETURN_STACK',):
|
for memType in ('DATA_STACK','RETURN_STACK',):
|
(combined,port,packing) = config.GetPacking(memType);
|
(combined,port,packing) = config.GetPacking(memType);
|
if combined['port'][0]['packing'][0]['name'] != memType:
|
if combined['port'][0]['packing'][0]['name'] != memType:
|
Line 214... |
Line 217... |
else:
|
else:
|
memName = instructionMemNameFormat % ixBlock;
|
memName = instructionMemNameFormat % ixBlock;
|
if nbits == 9:
|
if nbits == 9:
|
formatp = ' %s[\'h%%0%dX] = { 1\'b1, %%s };' % (memName,instructionAddrWidth,);
|
formatp = ' %s[\'h%%0%dX] = { 1\'b1, %%s };' % (memName,instructionAddrWidth,);
|
formatn = ' %s[\'h%%0%dX] = 9\'h%%s; // %%s\n' % (memName,instructionAddrWidth,);
|
formatn = ' %s[\'h%%0%dX] = 9\'h%%s; // %%s\n' % (memName,instructionAddrWidth,);
|
formate = ' %s[\'h%%0%dX] = 9\'h000;\n' % (memName,instructionAddrWidth,);
|
formate = ' %s[\'h%%0%dX] = 9\'h%%03x;\n' % (memName,instructionAddrWidth,);
|
else:
|
else:
|
formatp = ' %s[\'h%%0%dX] = { %d\'d0, 1\'b1, %%s };' % (memName,instructionAddrWidth,nbits-9,);
|
formatp = ' %s[\'h%%0%dX] = { %d\'d0, 1\'b1, %%s };' % (memName,instructionAddrWidth,nbits-9,);
|
formatn = ' %s[\'h%%0%dX] = { %d\'d0, 9\'h%%s }; // %%s\n' % (memName,instructionAddrWidth,nbits-9,);
|
formatn = ' %s[\'h%%0%dX] = { %d\'d0, 9\'h%%s }; // %%s\n' % (memName,instructionAddrWidth,nbits-9,);
|
formate = ' %s[\'h%%0%dX] = { %d\'d0, 9\'h000 };\n' % (memName,instructionAddrWidth,nbits-9,);
|
formate = ' %s[\'h%%0%dX] = { %d\'d0, 9\'h%%03x };\n' % (memName,instructionAddrWidth,nbits-9,);
|
|
rand_instr_mem = config.Get('rand_instr_mem');
|
for ixMem in range(instructionMemory['blockSize']):
|
for ixMem in range(instructionMemory['blockSize']):
|
memAddr = instructionMemory['blockSize']*ixBlock+ixMem;
|
memAddr = instructionMemory['blockSize']*ixBlock+ixMem;
|
if ixRecordedBody < len(programBody):
|
if ixRecordedBody < len(programBody):
|
for ixRecordedBody in range(ixRecordedBody,len(programBody)):
|
for ixRecordedBody in range(ixRecordedBody,len(programBody)):
|
if programBody[ixRecordedBody][0] == '-':
|
if programBody[ixRecordedBody][0] == '-':
|
Line 239... |
Line 243... |
fp.write(formatn % (ixMem,programBody[ixRecordedBody][0:3],programBody[ixRecordedBody][4:]));
|
fp.write(formatn % (ixMem,programBody[ixRecordedBody][0:3],programBody[ixRecordedBody][4:]));
|
fpMemFile.write('@%04X %s\n' % (memAddr,programBody[ixRecordedBody][0:3],));
|
fpMemFile.write('@%04X %s\n' % (memAddr,programBody[ixRecordedBody][0:3],));
|
break;
|
break;
|
ixRecordedBody = ixRecordedBody + 1;
|
ixRecordedBody = ixRecordedBody + 1;
|
elif ixInstruction < instructionBodyLength:
|
elif ixInstruction < instructionBodyLength:
|
fp.write(formate % ixMem);
|
fp.write(formate % (ixMem,0 if not rand_instr_mem else random.randint(0,2**9-1),));
|
fpMemFile.write('@%04X 000\n' % memAddr);
|
fpMemFile.write('@%04X 000\n' % memAddr);
|
else:
|
else:
|
break;
|
break;
|
ixInstruction = ixInstruction + 1;
|
ixInstruction = ixInstruction + 1;
|
# Save the last memory name for memories combined at the end of the instruction memory.
|
# Save the last memory name for memories combined at the end of the instruction memory.
|
Line 525... |
Line 529... |
values.append(thisValue);
|
values.append(thisValue);
|
curOffset = 0;
|
curOffset = 0;
|
while curOffset < port['packing'][0]['length']:
|
while curOffset < port['packing'][0]['length']:
|
addr = port['offset']+port['ratio']*curOffset+packing['lane']+thisRatio;
|
addr = port['offset']+port['ratio']*curOffset+packing['lane']+thisRatio;
|
thisFill.append({ 'assign':(formate % addr) });
|
thisFill.append({ 'assign':(formate % addr) });
|
thisValue.append('0');
|
thisValue.append(0);
|
curOffset += 1;
|
curOffset += 1;
|
else:
|
else:
|
memParam = config.GetMemoryByName(thisMemName);
|
memParam = config.GetMemoryByName(thisMemName);
|
if not memParam:
|
if not memParam:
|
raise Exception('Program bug -- memory "%s" not found' % thisMemName);
|
raise Exception('Program bug -- memory "%s" not found' % thisMemName);
|
Line 544... |
Line 548... |
varName = line[2:-1];
|
varName = line[2:-1];
|
continue;
|
continue;
|
addr = port['offset']+port['ratio']*curOffset+packing['lane'];
|
addr = port['offset']+port['ratio']*curOffset+packing['lane'];
|
thisFill.append({ 'assign':(formatd % (addr,line[0:2],)) });
|
thisFill.append({ 'assign':(formatd % (addr,line[0:2],)) });
|
thisFill[-1]['comment'] = varName if varName else '.';
|
thisFill[-1]['comment'] = varName if varName else '.';
|
thisValue.append(line[0:2]);
|
thisValue.append(int(line[0:2],16));
|
varName = None;
|
varName = None;
|
curOffset += 1;
|
curOffset += 1;
|
if (curOffset > packing['nWords']):
|
if (curOffset > packing['nWords']):
|
raise Exception('Program Bug -- memory body longer than allocated memory space');
|
raise Exception('Program Bug -- memory body longer than allocated memory space');
|
while curOffset < packing['length']:
|
while curOffset < packing['length']:
|
addr = port['ratio']*curOffset+port['offset'];
|
addr = port['ratio']*curOffset+port['offset'];
|
thisFill.append({ 'assign':(formate % addr) });
|
thisFill.append({ 'assign':(formate % addr) });
|
thisValue.append('0');
|
thisValue.append(0);
|
curOffset += 1;
|
curOffset += 1;
|
endLength = port['nWords']/port['ratio'];
|
endLength = port['nWords']/port['ratio'];
|
for ixFill in range(len(fills)):
|
for ixFill in range(len(fills)):
|
thisFill = fills[ixFill];
|
thisFill = fills[ixFill];
|
thisValue = values[ixFill];
|
thisValue = values[ixFill];
|
curOffset = len(thisFill);
|
curOffset = len(thisFill);
|
if curOffset < endLength:
|
if curOffset < endLength:
|
addr = port['ratio']*curOffset+port['offset']+ixFill;
|
addr = port['ratio']*curOffset+port['offset']+ixFill;
|
thisFill.append({ 'assign':(formate % addr), 'comment':'***' });
|
thisFill.append({ 'assign':(formate % addr), 'comment':'***' });
|
thisValue.append('0');
|
thisValue.append(0);
|
curOffset += 1;
|
curOffset += 1;
|
while curOffset < endLength:
|
while curOffset < endLength:
|
addr = port['ratio']*curOffset+port['offset']+ixFill;
|
addr = port['ratio']*curOffset+port['offset']+ixFill;
|
thisFill.append({ 'assign':(formate % addr) });
|
thisFill.append({ 'assign':(formate % addr) });
|
thisValue.append('0');
|
thisValue.append(0);
|
curOffset += 1;
|
curOffset += 1;
|
for thisFill in fills:
|
for thisFill in fills:
|
commentLengths = [len(entry['comment']) for entry in thisFill if 'comment' in entry];
|
commentLengths = [len(entry['comment']) for entry in thisFill if 'comment' in entry];
|
if not commentLengths:
|
if not commentLengths:
|
formatc = '%s';
|
formatc = '%s';
|