EDIFCelling:
CEDAR
PROGRAM
IMPORTS Asserting, Atom, EDIFAndCore, EDIFAndCorePrivate, HashTable, IO, Rope
EXPORTS EDIFAndCorePrivate
= {OPEN EDIFAndCore, EDIFAndCorePrivate;
ParseCell:
PUBLIC
PROC [ec: EDIFConversion, lexed:
LORA, context:
ROPE]
RETURNS [ct: CoreCellType] = {
me: ROPE ← Rope.Cat["a cell definition in ", context];
cc: CellConversion =
NEW [CellConversionPrivate ← [
ec: ec,
views: HashTable.Create[equal: HashTable.RopeEqualModCase, hash: HashTable.HashRopeModCase]
]];
stdTail: StdTail ← [];
nameATOM: ATOM;
name: ROPE;
CheckLength[lexed, me, 2];
CheckHead[lexed, $cell, me];
nameATOM ← ToATOM[lexed.rest.first, me.Concat[" doesn't have a sensible name"]];
name ← Atom.GetPName[nameATOM];
me ← Rope.Cat["cell ", name, " in ", context];
FOR lexed ← lexed.rest.rest, lexed.rest
WHILE lexed #
NIL
DO
innerMe: ROPE = Rope.Cat["statement in ", me];
part: LORA = ToLORA[lexed.first, me.Cat[" contains a non-statement"]];
key: ATOM;
CheckLength[part, innerMe, 1];
key ← ToATOM[part.first, innerMe.Cat[" doesn't begin with a keyword"]];
SELECT LcA[key]
FROM
$status => {
IF cc.status # NIL THEN Error[Rope.Cat["Multiple status specifications in ", me]];
cc.status ← ParseStatus[part, me];
};
$viewmap => {
IF cc.viewMap # NIL THEN Error[Rope.Cat["Multiple view maps in ", me]];
cc.viewMap ← ParseViewMap[ec, part, me];
};
$view => {
ParseView[cc, part, me];
};
$comment => {
c: Comment = ParseComment[part, me];
[cc.comments, stdTail.c] ← CAppend[cc.comments, stdTail.c, c];
};
$userdata => {
ue: UserExtension = ParseUserExtension[part, me];
[cc.ues, stdTail.ues] ← UEAppend[cc.ues, stdTail.ues, ue];
};
ENDCASE => Error[IO.PutFR["%g statement found in %g", [atom[key]], [rope[me]] ]];
ENDLOOP;
ec ← ec;
};
ParseView:
PROC [cc: CellConversion, lexed:
LORA, context:
ROPE] = {
me: ROPE ← Rope.Cat["a view of ", context];
stdTail: StdTail ← [];
typeATOM, nameATOM: ATOM;
type: ViewType;
name: ROPE;
v: View;
CheckLength[lexed, me, 3];
CheckHead[lexed, $view, me];
typeATOM ← ToATOM[lexed.rest.first, me.Concat[" doesn't have a sensible ViewType"]];
type ←
SELECT LcA[typeATOM]
FROM
$masklayout => MaskLayout,
$netlist => Netlist,
$schematic => Schematic,
$symbolic => Symbolic,
$behavior => Behavior,
$document => Document,
$stranger => Stranger,
ENDCASE => Error[me.Concat[" doesn't have a sensible ViewType"]];
nameATOM ← ToATOM[lexed.rest.rest.first, me.Concat[" doesn't have a sensible name"]];
name ← Atom.GetPName[nameATOM];
me ← Rope.Cat["cell ", name, " in ", context];
v ←
NEW [ViewPrivate ← [
type: type,
name: name
]];
FOR lexed ← lexed.rest.rest.rest, lexed.rest
WHILE lexed #
NIL
DO
innerMe: ROPE = Rope.Cat["statement in ", me];
part: LORA = ToLORA[lexed.first, me.Cat[" contains a non-statement"]];
key: ATOM;
CheckLength[part, innerMe, 1];
key ← ToATOM[part.first, innerMe.Cat[" doesn't begin with a keyword"]];
SELECT LcA[key]
FROM
$status => {
IF v.status # NIL THEN Error[Rope.Cat["Multiple status specifications in ", me]];
v.status ← ParseStatus[part, me];
};
$interface => {
IF v.interfaceSeen THEN Error[Rope.Cat["Multiple interfaces to ", me]];
v.interfaceSeen ← TRUE;
Handle[cc, v, part, Interface, me];
};
$contents => {
IF v.contentsSeen THEN Error[Rope.Cat["Multiple contents to ", me]];
v.contentsSeen ← TRUE;
Handle[cc, v, part, Contents, me];
};
$comment => {
c: Comment = ParseComment[part, me];
[v.comments, stdTail.c] ← CAppend[v.comments, stdTail.c, c];
};
$userdata => {
ue: UserExtension = ParseUserExtension[part, me];
[v.ues, stdTail.ues] ← UEAppend[v.ues, stdTail.ues, ue];
};
ENDCASE => Error[IO.PutFR["%g statement found in %g", [atom[key]], [rope[me]] ]];
ENDLOOP;
cc ← cc;
};
Handle:
PROC [cc: CellConversion, v: View, lexed:
LORA, pub: Publicity, context:
ROPE] = {
me:
ROPE = Rope.Cat[
SELECT pub FROM Interface => "interface of ", Contents => "Contents of ", ENDCASE => ERROR,
context];
FOR lexed ← lexed.rest, lexed.rest
WHILE lexed #
NIL
DO
innerMe: ROPE = Rope.Cat["statement in ", me];
part: LORA = ToLORA[lexed.first, me.Cat[" contains a non-statement"]];
converter: Converter;
key: ATOM;
CheckLength[part, innerMe, 1];
key ← ToATOM[part.first, innerMe.Cat[" doesn't begin with a keyword"]];
converter ← GetConverter[key, pub];
SELECT converter
FROM
=NIL => Error[IO.PutFR["%g statement found in %g", [atom[key]], [rope[me]] ]];
#NIL => converter.Convert[converter.converterData, cc, v, part, pub, context];
ENDCASE => ERROR;
ENDLOOP;
cc ← cc;
};
GetConverter:
PROC [key:
ATOM, pub: Publicity]
RETURNS [c: Converter] = {
c ← NARROW[Atom.GetProp[key, converterKeys[pub]]];
};
SetConverter:
PUBLIC
PROC [key:
ATOM, pub: Publicity, c: Converter] = {
Atom.PutProp[key, converterKeys[pub], c];
};
converterKeys:
ARRAY Publicity
OF
ATOM = [
Interface: $EDIFCellingInterfacePartHandler,
Contents: $EDIFCellingContentsPartHandler];
ConvertComment:
PROC [converterData:
REF
ANY, cc: CellConversion, v: View, part:
LORA, pub: Publicity, context:
ROPE] = {
c: Comment = ParseComment[part, context];
[v.std[pub].head.comments, v.std[pub].tail.comments] ← CAppend[v.std[pub].head.comments, v.std[pub].tail.comments, c];
};
ConvertUserExtension:
PROC [converterData:
REF
ANY, cc: CellConversion, v: View, part:
LORA, pub: Publicity, context:
ROPE] = {
ue: UserExtension = ParseUserExtension[part, context];
[v.std[pub].head.ues, v.std[pub].tail.ues] ← UEAppend[v.std[pub].head.ues, v.std[pub].tail.ues, ue];
};
boredomKey: ATOM = $EDIFCellingViewBoringParts;
boredomKeys:
ARRAY Publicity
OF
ATOM = [
Interface: $EDIFCellingInterfaceBoringParts,
Contents: $EDIFCellingContentsBoringParts];
ConvertUninteresting:
PROC [converterData:
REF
ANY, cc: CellConversion, v: View, part:
LORA, pub: Publicity, context:
ROPE] = {
v.assns[pub] ← Asserting.Assert[
reln: boredomKey,
terms: part,
inAdditionTo: v.assns[pub]
];
};
RegisterDisinterest:
PROC [key:
ATOM] = {
FOR pub: Publicity
IN Publicity
DO
SetConverter[key, pub, NEW [ConverterPrivate ← [ConvertUninteresting]]];
SetConverter[key, pub, NEW [ConverterPrivate ← [ConvertUninteresting]]];
ENDLOOP;
};
Start:
PROC = {
FOR pub: Publicity
IN Publicity
DO
SetConverter[$comment, pub, NEW [ConverterPrivate ← [ConvertComment]]];
SetConverter[$userdata, pub, NEW [ConverterPrivate ← [ConvertUserExtension]]];
ENDLOOP;
RegisterDisinterest[$annotate];
RegisterDisinterest[$arrayrelatedinfo];
RegisterDisinterest[$body];
RegisterDisinterest[$criticalsignal];
RegisterDisinterest[$figuregroup];
RegisterDisinterest[$logicmodel];
RegisterDisinterest[$measured];
RegisterDisinterest[$portimplementation];
RegisterDisinterest[$required];
RegisterDisinterest[$section];
RegisterDisinterest[$simulate];
RegisterDisinterest[$timing];
RegisterDisinterest[$wire];
};
}.