Search in sources :

Example 1 with Context

use of de.neemann.digital.hdl.hgs.Context in project Digital by hneemann.

the class ApplicationVHDLStdIO method createVHDL.

/**
 * Creates vhdl code
 *
 * @param label   the name of the vhdl code
 * @param code    the vhdl code
 * @param inputs  the inputs
 * @param outputs the outputs
 * @return the vhdl code
 * @throws HGSEvalException HGSEvalException
 */
public String createVHDL(String label, String code, PortDefinition inputs, PortDefinition outputs) throws HGSEvalException {
    Context context = new Context().declareVar("entityName", label).declareVar("code", code).declareVar("inputs", inputs).declareVar("outputs", outputs);
    TEMPLATE.execute(context);
    return context.toString();
}
Also used : Context(de.neemann.digital.hdl.hgs.Context)

Example 2 with Context

use of de.neemann.digital.hdl.hgs.Context in project Digital by hneemann.

the class ElementAttributesTest method testDataField.

/**
 * Ensures that the DataField is accessible from within the template engine
 */
public void testDataField() throws IOException, ParserException, HGSEvalException {
    DataField d = new DataField(5).setData(0, 1).setData(1, 7).setData(2, 4).setData(3, 8).setData(4, 2);
    Context c = new Context().declareVar("d", d);
    new Parser("(<? for(i:=0;i<sizeOf(d);i++) { if (i>0) print(\"-\"); print(d[i]);} ?>)").parse().execute(c);
    assertEquals("(1-7-4-8-2)", c.toString());
}
Also used : Context(de.neemann.digital.hdl.hgs.Context) DataField(de.neemann.digital.core.memory.DataField) Parser(de.neemann.digital.hdl.hgs.Parser)

Example 3 with Context

use of de.neemann.digital.hdl.hgs.Context in project Digital by hneemann.

the class ElementAttributesTest method testElementAttibutes.

/**
 * Ensures that the ElementAttributes is accessible from within the template engine
 */
public void testElementAttibutes() throws IOException, ParserException, HGSEvalException {
    ElementAttributes attr = new ElementAttributes().set(Keys.BITS, 5);
    final Context c = new Context().declareVar("elem", attr);
    new Parser("bits=<?=elem.Bits?>;").parse().execute(c);
    assertEquals("bits=5;", c.toString());
}
Also used : Context(de.neemann.digital.hdl.hgs.Context) Parser(de.neemann.digital.hdl.hgs.Parser)

Aggregations

Context (de.neemann.digital.hdl.hgs.Context)3 Parser (de.neemann.digital.hdl.hgs.Parser)2 DataField (de.neemann.digital.core.memory.DataField)1