Skip to content
This repository has been archived by the owner on Jul 23, 2021. It is now read-only.

Commit

Permalink
cQuark is wrong, just using keyword quark to merge an instant into th…
Browse files Browse the repository at this point in the history
…e module
  • Loading branch information
stacksmith committed Sep 20, 2012
1 parent 361523a commit 94eef2b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ this->dump(stderr,"DUMPING");
Occasionally we need an item that is just a reference to an existing
name:value pair. Clone does just that.
******************************************************************************/
//TODO: rename to addRef
int CLASS::addClone(const char* str,cDatum* dat){
name[size]=(char*)str;
data[size]=dat;
return size++;

}

void CLASS::solidify(){
//replace builder with properly sized copy of the array
name= (char**)realloc(name,size*sizeof(char*));
Expand Down
2 changes: 2 additions & 0 deletions cModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ CLASS::~CLASS(){

cSub* CLASS::getSub(char*name){
int i = psubs->find(name);
if(-1==i)
return NULL;
cDatum* r = psubs->getDatum(i);
if(TYPE_SUB!=r->type)
return r->valSub;
Expand Down
97 changes: 90 additions & 7 deletions cParse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "cParse.h"
#include <ctype.h>
#include "cModule.h"
#include "cQuark.h"
#include "cSub.h"
#define CLASS cParse
#include "cDevice.h"
Expand Down Expand Up @@ -610,6 +611,50 @@ fprintf(stderr,"merging inst %s\n",inst->name);
pins->solidify();
inst->pins=pins;
}

/******************************************************************************
parsemergeQuark - merge the quark with the module itself!
******************************************************************************/
void CLASS::parseMergeQuark(cModule*module){
ws(true);
int size=cnt();
//find the quark name
cProto* proto = pDevice->findProto(ptr,size); //find prototype by name
if(!proto){
errorIn(__func__);
fprintf(stderr,"Quark %.*s has not been defined\n",size,ptr);
error(1);
}
ptr+=size;
//TODO:merge parameter names, without duplication...
//merge pins TODO: if dup, check direction and keep old one.
int i; for(i=0;i<proto->pins->size;i++){
module->pins->addClone(proto->pins->name[i],proto->pins->data[i]);
}
//merge instances TODO: must be a dup! just add params
for(i=0;i<proto->psubs->size;i++){
cSub* oldsub = module->getSub(proto->psubs->name[i]);
if(!oldsub){
//reference the merging sub TODO: is this really OK?
module->psubs->add(proto->psubs->name[i],
strlen(proto->psubs->name[i]),
proto->psubs->data[i]);
} else {
//it exists, so merge parameters
int j;
cSub* srcSub = proto->psubs->data[i]->valSub;
for(j=0;j<srcSub->pparams->size;j++){
//TODO: check parameters for duplication - not allowed.
oldsub->pparams->add(srcSub->pparams->name[j],
strlen(srcSub->pparams->name[j]),
srcSub->pparams->data[j]);
}
}
}

fprintf(stderr,"merging quark type %s\n",proto->name);
}
/******************************************************************************
parseModule
Expand All @@ -628,6 +673,7 @@ cModule* CLASS::parseModule(){
}
cModule* module = new cModule(ptr,size); //it will check for dups
ptr+=size;
//---------------------factor---
// parameter names
parseParamNames(module);
//Now inputs and outputs
Expand All @@ -647,9 +693,10 @@ cModule* CLASS::parseModule(){
}
ws(true );size=cnt();
}
//----------------------------------------------------------------
// now parse insts and wiring...
module->pwires=new cWires(module); //there may be many wires...
//---------------------factor---
//----------------------------------------------------------------

int idxInst=-1; //keep track of most recent instance index for 'his'
cSub* pinst=0;
Expand All @@ -661,8 +708,14 @@ cModule* CLASS::parseModule(){
} else if(tokAnything("merge",size)){
parseMerge(module,pinst);
} else {
pinst=parseSub(module,size);
idxInst++;
if(tokAnything("quark",size)){
//merge quark into the module definition!
parseMergeQuark(module);

} else {
pinst=parseSub(module,size);
idxInst++;
}
}
ws(true );size=cnt();

Expand All @@ -688,7 +741,37 @@ cModule* CLASS::parseModule(){
******************************************************************************/
bool CLASS::parseQuark(){
fprintf(stderr,"parseQuark not yet implemented\n");
ws(true);
int size=cnt();
cParseStream::validateName(size);
//TODO: check for duplicates
cQuark* quark = new cQuark(ptr,size);
ptr+=size;
//---------------------factor---

//Now inputs and outputs
ws(true); size=cnt();
while(!tokAnything("{",size)){
if(tokAnything("input",size)){
optionalColon();
parsePins(quark->pins,0); //inputs
}else if(tokAnything("output",size)){
optionalColon();
parsePins(quark->pins,1); //outputs
}
else {
errorIn("parseQuark()");
fprintf(stderr,"Quark header must contain only input:() output:() or ;\n");
error(1);
}
ws(true );size=cnt();
}
//Let's use paramnames as actual merge parameters here...
// pparamnames = new cCollection();
//---------------------factor---
quark->pins->solidify();
// psubs are not used and are nil.
// wires are not used and are nil.
return 1;
}
/******************************************************************************
Expand All @@ -709,9 +792,9 @@ void CLASS::parseModules(){
if(handleInclude(len)) continue;
if(pDevice){
/* If device is parsed, a quark or module is expected. */
if(tokAnything("quark",5))
iterate = parseQuark();
else
// if(tokAnything("quark",5))
// iterate = parseQuark();
// else
iterate=parseModule();
} else {
errorIn("parseModules()");
Expand Down
3 changes: 2 additions & 1 deletion cParse.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class cParse: public cParseStream {
//data
cModule* topModule; //keep track of the last module - it is top.

private:
protected:
void parseModules();
bool handleInclude(int len);
void validateName(int len,cModule* module);
Expand All @@ -49,6 +49,7 @@ class cParse: public cParseStream {
cDatum* parseParamData(cModule*module,const char* prepend);
sWireEndpoint parseWireEndpoint(cModule* module,int idxInst,cSub*pinst);
void parseWire(cModule* module,int idxInst,cSub*pinst);
void parseMergeQuark(cModule* module);

cSub* parseSub(cModule* module,int len);
void parseMerge(cModule* module,cSub* pinst);
Expand Down
2 changes: 2 additions & 0 deletions cQuark.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
constructs that may be instantiated in Verilog, and is used in conversion to
verilog. Modules using quarks instead of instantiating primitives can be
converted to verilog.
A quark is instantiated inside a module, and merges its own cfg data and pins
with those of the module.
******************************************************************************/
#pragma once
#include "cProto.h"
Expand Down
2 changes: 1 addition & 1 deletion cSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ CLASS::~CLASS(){
******************************************************************************/
void CLASS::init(cProto* theType){
type=theType;
//Now initialize our pins to be proto's
//Now initialize our pins to be proto's TODO: really?
pins=type->pins;
}
/******************************************************************************
Expand Down

0 comments on commit 94eef2b

Please sign in to comment.