Skip to content

Commit

Permalink
Added initial netlist export. Probably not fully functional for conne…
Browse files Browse the repository at this point in the history
…ctivity; definitely does not support attributes yet.
azonenberg committed Aug 7, 2017
1 parent a99a604 commit d245e0e
Showing 4 changed files with 182 additions and 5 deletions.
12 changes: 12 additions & 0 deletions src/greenpak4/Greenpak4BitstreamEntity.cpp
Original file line number Diff line number Diff line change
@@ -124,6 +124,18 @@ bool Greenpak4BitstreamEntity::IsGeneralFabricInput(string port) const
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Load/save helpers

vector<string> Greenpak4BitstreamEntity::GetAllInputPorts() const
{
//default to just getting the fabric ports
return GetInputPorts();
}

vector<string> Greenpak4BitstreamEntity::GetAllOutputPorts() const
{
//default to just getting the fabric ports
return GetOutputPorts();
}

vector<string> Greenpak4BitstreamEntity::GetOutputPortsFiltered(bool* /*bitstream*/) const
{
return GetOutputPorts();
8 changes: 7 additions & 1 deletion src/greenpak4/Greenpak4BitstreamEntity.h
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ class Greenpak4BitstreamEntity
virtual void SetInput(std::string port, Greenpak4EntityOutput src) =0;

/**
@brief Gets the input with the given name.
@brief Gets the signal driving the specified input
*/
virtual Greenpak4EntityOutput GetInput(std::string port) const =0;

@@ -132,6 +132,12 @@ class Greenpak4BitstreamEntity
//Calls GetOutputPorts() then filters the output to only include ports valid in the current configuration
virtual std::vector<std::string> GetOutputPortsFiltered(bool* bitstream) const;

//Get a list of all input ports on this node, including those which do not go to general fabric routing
virtual std::vector<std::string> GetAllInputPorts() const;

//Get a list of all output ports on this node, including those which do not go to general fabric routing
virtual std::vector<std::string> GetAllOutputPorts() const;

//Commit changes from the assigned PAR graph node to us
virtual bool CommitChanges() =0;

154 changes: 151 additions & 3 deletions src/greenpak4/Greenpak4Device.cpp
Original file line number Diff line number Diff line change
@@ -1370,17 +1370,165 @@ bool Greenpak4Device::WriteToJSON(string fname, string top)
else
fprintf(fp, ",\n");

//TODO
vector<string> inputs = cell->GetAllInputPorts();
vector<string> outputs = cell->GetAllOutputPorts();
vector<string> inouts;

//The only primitive with an inout port is GP_IOBUF.
//All other ports are unidirectional.
string type = cell->GetPrimitiveName();
if(type == "GP_IOBUF")
inouts.push_back("IO");

//TODO: parameters and attributes
fprintf(fp, " \"%s\": {\n", cell->GetDescription().c_str());
fprintf(fp, " \"hide_name\": 0,\n");
fprintf(fp, " \"type\": \"%s\",\n", cell->GetPrimitiveName().c_str());
fprintf(fp, " \"type\": \"%s\",\n", type.c_str());
fprintf(fp, " \"parameters\": {\n");
fprintf(fp, " },\n");
fprintf(fp, " \"attributes\": {\n");
fprintf(fp, " },\n");

//Port directions based on which list we're in
bool pfirst = true;
fprintf(fp, " \"port_directions\": {\n");
fprintf(fp, " },\n");
for(auto i : inputs)
{
//Add comma if we're not the first one
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

fprintf(fp, " \"%s\": \"input\"", i.c_str());
}
for(auto o : outputs)
{
//Add comma if we're not the first one
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

fprintf(fp, " \"%s\": \"output\"", o.c_str());
}
for(auto io : inouts)
{
//Add comma if we're not the first one
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

fprintf(fp, " \"%s\": \"inout\"", io.c_str());
}
fprintf(fp, "\n },\n");


//Port connections for inputs
pfirst = true;
fprintf(fp, " \"connections\": {\n");

//Inputs
for(auto i : inputs)
{
//Skip this port if nothing's hooked up
auto source = cell->GetInput(i);
if(source.IsNull())
continue;

//Add comma if we're not the first one
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

//Look up the net number, allocate a new one if needed
int netnum;
if(netnums.find(source) != netnums.end())
netnum = netnums[source];
else
{
netnum = nextNetnum ++;
netnums[source] = netnum;
}

//TODO: Get width of the signal and handle vectors properly!!

//Done, save it
//Special case for 0/1 constant nets!
if( (netnum == 0) || (netnum == 1) )
fprintf(fp, " \"%s\": [ \"%d\" ]", i.c_str(), netnum);
else
fprintf(fp, " \"%s\": [ %d ]", i.c_str(), netnum);
}

//Outputs
for(auto o : outputs)
{
//Skip this port if nothing's hooked up
auto dest = cell->GetOutput(o);
if(dest.IsNull())
continue;

//Add comma if we're not the first one
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

//Look up the net number, allocate a new one if needed
int netnum;
if(netnums.find(dest) != netnums.end())
netnum = netnums[dest];
else
{
netnum = nextNetnum ++;
netnums[dest] = netnum;
}

//TODO: Get width of the signal and handle vectors properly!!

//Done, save it
fprintf(fp, " \"%s\": [ %d ]",
o.c_str(),
netnum);
}

//Hook up top level ports
if(type == "GP_IBUF")
{
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

auto iob = dynamic_cast<Greenpak4IOB*>(cell);
fprintf(fp, " \"IN\": [ %d ]\n", padToNet[iob->GetPinNumber()]);
}
else if(type == "GP_OBUF")
{
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

auto iob = dynamic_cast<Greenpak4IOB*>(cell);
fprintf(fp, " \"OUT\": [ %d ]\n", padToNet[iob->GetPinNumber()]);
}
else if(type == "GP_IOBUF")
{
if(pfirst)
pfirst = false;
else
fprintf(fp, ",\n");

auto iob = dynamic_cast<Greenpak4IOB*>(cell);
fprintf(fp, " \"IO\": [ %d ]\n", padToNet[iob->GetPinNumber()]);
}

//TODO: other connections to top level ports

fprintf(fp, " }\n");
fprintf(fp, " }");
}
13 changes: 12 additions & 1 deletion src/greenpak4/Greenpak4EntityOutput.h
Original file line number Diff line number Diff line change
@@ -74,7 +74,18 @@ class Greenpak4EntityOutput

//comparison operator for std::map
bool operator<(const Greenpak4EntityOutput& rhs) const
{ return GetOutputName() < rhs.GetOutputName(); }
{
//Null is always less than anything
if(IsNull())
return true;
if(rhs.IsNull())
return false;

return GetOutputName() < rhs.GetOutputName();
}

bool IsNull() const
{ return (m_src == NULL); }

public:
Greenpak4BitstreamEntity* m_src;

0 comments on commit d245e0e

Please sign in to comment.