LoginSignup
1
0

More than 1 year has passed since last update.

paiza.ioでelixir その221

Last updated at Posted at 2023-05-06

概要

paiza.ioでelixirやってみた。
練習問題、やってみた。

練習問題

gtkwaveのvcdファイルを生成せよ。

サンプルコード

defmodule Va do
	use Agent
	def start_link() do
		Agent.start_link(fn ->
			0
		end, name: __MODULE__)
	end
	def get() do
		Agent.get(__MODULE__, fn v ->
			v
		end)
	end
	def inc() do
		Agent.update(__MODULE__, fn v ->
			v + 1
		end)
	end
	def set(x) do
		Agent.update(__MODULE__, fn v ->
			x
		end)
	end
end

defmodule Main do
    def main(src) do
        IO.puts "$date"
        IO.puts "  Sat Mar 27 16:11:10 2022"
        IO.puts "$end"
        IO.puts "$version"
        IO.puts "  plunker"
        IO.puts "$end"
        IO.puts "$timescale"
        IO.puts "  1ms"
        IO.puts "$end"
        IO.puts "$scope module test $end"
        IO.puts "$var reg 1 ! a $end"
        IO.puts "$upscope $end"
        IO.puts "$enddefinitions $end"
        IO.puts "#0"
        IO.puts "$dumpvars"
        IO.puts "x!"
        IO.puts "$end"
        IO.puts "x!"
        0..2
        |> Enum.map(fn i ->
	        Enum.map(String.split(src, ""), fn x ->
	            if x != "" do
	                Va.inc 
	                IO.puts "##{Va.get}"
	                IO.puts "#{x}!"
	            end
	        end)
        end)
    end
end

Va.start_link
Main.main("111111111000")




成果物

gtkwaveで見る手順

windows10

image.png

  • iverilogをインストールする。
    iverilog-v12-20220611-x64_setup
  • パスを通す。
  • 結果をtest0.vcdでセーブする。
  • gtkwave test0.vcdで実行する。

以上。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0