|
|
|
|
|
|
|
|
|
|
Re: How to select an event from numerous events [message #1794033 is a reply to message #1794032] |
Wed, 22 August 2018 17:45 |
Stevo McLaren Messages: 26 Registered: July 2018 |
Junior Member |
|
|
I have uploaded the Grammar, Codegenerator and Eclipse App(code.vhdl). I hope thats all you need. I want my codegenerator to produce this:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity m_Kaffeemaschine is
Port ( Fuellstand : in STD_LOGIC;
Verschluss : in STD_LOGIC;
Start : in STD_LOGIC;
Pad_ID : in STD_LOGIC_VECTOR (1 downto 0);
clk : in STD_LOGIC;
reset : in STD_LOGIC;
led_enable : in STD_LOGIC;
LED_out : out STD_LOGIC_VECTOR (2 downto 0));
end m_Kaffeemaschine;
architecture Behavioral of m_Kaffeemaschine is
type zustand is (warte, Verschlussstand, ID_Test, Reinigen, Kaffee, Latte, Error, Fill);
signal z, z_next : zustand := warte;
signal led, led_next : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');
signal delay_count : INTEGER range 0 to 59999 := 0;
z <= z_next
delay_count <= delay_count
z_next <= Verschlussstand
z_next <= Fill
z <= warte
[Updated on: Wed, 22 August 2018 17:48] Report message to a moderator
|
|
|
|
|
|
|
Re: How to select an event from numerous events [message #1794039 is a reply to message #1794033] |
Wed, 22 August 2018 18:16 |
|
Hi,
first of all your current dsl and the target are very diffent from each other.
thus you need to do all that .get(x) cause you currently dont know about the parameter types etc and need to hardcode that.
i am not sure if this modus operandi is good or if you should first focus on enhancing your dsl and then starting generation
here is some snippet for your transitions (they suffer from a bad grammar too)
class MyDslGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
resource.allContents.filter(typeof(Statemachine)).forEach[it.generateMachine(fsa)]
}
def void generateMachine(Statemachine machine, IFileSystemAccess2 fsa){
fsa.generateFile(machine.name+".vhdl",machine.generate)
}
def CharSequence generate(Statemachine machine)
'''
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity «machine.name» is
Port(
// TODO why is this list hardcoded
«machine.ports.head.names.get(0)» : in STD_LOGIC;
«machine.ports.head.names.get(1)» : in STD_LOGIC;
«machine.ports.head.names.get(2)» : in STD_LOGIC;
«machine.ports.head.names.get(3)» : in STD_LOGIC;
«machine.ports.head.names.get(4)» : in STD_LOGIC_VECTOR (1 downto 0);
«machine.ports.head.names.get(5)» : in STD_LOGIC;
«machine.ports.head.names.get(6)» : in STD_LOGIC;
«machine.ports.head.names.get(7)» : out STD_LOGIC_VECTOR (2 downto 0));
end «machine.name»;
architecture Behavioral of «machine.name» is
type zustand is («FOR s:machine.states SEPARATOR ","» «s.name»«ENDFOR»)
// TODO why are these 3 hardcoded
signal «machine.events.get(0).name», «machine.events.get(1).name» : zustand := «machine.states.get(1).name»;
signal «machine.events.get(2).name», «machine.events.get(3).name» : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');
signal «machine.events.get(4).name» : INTEGER range 0 to 59999 := 0;
«FOR transition : machine.transitions»
«IF transition.event !== null»
«IF transition.target instanceof State»
««« your grammar is bad here better introduce a common supertype like "Thingy:State|Event;" and use "target=[Thingy]"
«transition.event.name» <= «(transition.target as State).name»
«ENDIF»
«ELSE»
// TODO what to generate hene
«ENDIF»
«ENDFOR»
'''
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
Re: How to select an event from numerous events [message #1794047 is a reply to message #1794046] |
Wed, 22 August 2018 19:46 |
|
machines.transitions.get(1) gives you an object of type transition (the impl call is transitionimpl)
=> you need to actually examine the contents event/target as i do it
«IF transition.event !== null»
«IF transition.target instanceof State»
««« your grammar is bad here better introduce a common supertype like "Thingy:State|Event;" and use "target=[Thingy]"
«transition.event.name» <= «(transition.target as State).name»
«ENDIF»
«ELSE»
// TODO what to generate hene
«ENDIF»
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
Re: How to select an event from numerous events [message #1794059 is a reply to message #1794058] |
Thu, 23 August 2018 05:13 |
|
maybe you did not get that xtend is a GPL and your should use the same concepts as you would use in java (e.g. separation into methods
class MyDslGenerator extends AbstractGenerator {
override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
resource.allContents.filter(typeof(Statemachine)).forEach[it.generateMachine(fsa)]
}
def void generateMachine(Statemachine machine, IFileSystemAccess2 fsa) {
fsa.generateFile(machine.name + ".vhdl", machine.generate)
}
def CharSequence generate(Statemachine machine) '''
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity «machine.name» is
Port(
// TODO why is this list hardcoded
«machine.ports.head.names.get(0)» : in STD_LOGIC;
«machine.ports.head.names.get(1)» : in STD_LOGIC;
«machine.ports.head.names.get(2)» : in STD_LOGIC;
«machine.ports.head.names.get(3)» : in STD_LOGIC;
«machine.ports.head.names.get(4)» : in STD_LOGIC_VECTOR (1 downto 0);
«machine.ports.head.names.get(5)» : in STD_LOGIC;
«machine.ports.head.names.get(6)» : in STD_LOGIC;
«machine.ports.head.names.get(7)» : out STD_LOGIC_VECTOR (2 downto 0));
end «machine.name»;
architecture Behavioral of «machine.name» is
type zustand is («FOR s : machine.states SEPARATOR ","» «s.name»«ENDFOR»)
// TODO why are these 3 hardcoded
signal «machine.events.get(0).name», «machine.events.get(1).name» : zustand := «machine.states.get(1).name»;
signal «machine.events.get(2).name», «machine.events.get(3).name» : STD_LOGIC_VECTOR(2 downto 0) := (others => '0');
signal «machine.events.get(4).name» : INTEGER range 0 to 59999 := 0;
«FOR transition : machine.transitions»
«transition.doSomethingWithATransition»
«ENDFOR»
//here is your special second transition thing
«machine.transitions.get(1).doSomethingWithATransition»
'''
def doSomethingWithATransition(Transition transition) {
'''
«IF transition.event !== null»
«IF transition.target instanceof State»
««« your grammar is bad here better introduce a common supertype like "Thingy:State|Event;" and use "target=[Thingy]"
«transition.event.name» <= «(transition.target as State).name»
«ENDIF»
«ELSE»
// TODO what to generate hene
«ENDIF»
'''
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.06578 seconds