import { Port } from "../ir1/ports/port" ; import { printPortData } from "../print" ; export function makeNode ( id , name , location , inPorts , outPorts , subGraph = "" ) { const genFunction = ( prefix , quantity ) => { return ( Array . from ( new Array ( quantity ) , ( val , index ) => "<port name=\"" + prefix + String ( index ) + "\" />" ) . join ( "" ) ) ; } ; return `<node id="${ id }">
            <data key="type">${ name }</data>
            <data key="location">${ location }</data>` + genFunction ( "in" , inPorts ) + genFunction ( "out" , outPorts ) + subGraph + "</node>" ; } export function makeEdge ( idFrom , portFrom , idTo , portTo , port , inner = false ) { let portVal = "" ; printPortData ( port , ( s ) => portVal += s ) ; return `<edge source="${ idFrom }" target="${ idTo }" sourceport="out${ portFrom }" ` + `targetport="` + ( inner ? "out" : "in" ) + portTo + `">
            <data key="value">${ portVal }</data>
         </edge>` ; } export function makeDocument ( contents ) { return `<?xml version="1.0" encoding="UTF-8"?>
  <graphml xmlns="http://graphml.graphdrawing.org/xmlns"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns
          http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
    <key id="type" for="node" attr.name="nodetype" attr.type="string" />
    <key id="location" for="node" attr.name="location" attr.type="string" />
${ contents }
</graphml>` ; } export function makeGraph ( id , contents ) { return `<graph id="${ id }" edgedefault="directed">${ contents }</graph>` ; }