LLVM 用于 Recipe 风格的语言
LLVM For a Recipe-style language
我想学习 LLVM。我想尝试使用以下食谱风格的语言来做到这一点:
Ingredients:
x-unit Flour
y-unit Yeast
z-unit Water
a-unit Sugar
Instructions:
bowl = mix flour with yeast for 30 seconds
bowl = mix bowl with sugar for 25 seconds
bowl = mix bowl with water for 1 minute
heat bowl for 3 hours
dough = split bowl into 3 parts
heat dough[n] at 450 f for 1 hour
由于这是一次学习经历,我不确定 LLVM 是否能够处理一种语言,其中 time/volume 是可以计算的维度。在阅读了一些文档之后,我不确定这是否是我想要做的事情的正确工具。
我想采用这种语言,对其进行编译,并将其转换为有效的 C/Python 代码,这样我就可以使用 RPi 或 Arduino 来执行程序。从本质上讲,我想尝试通过用这种语言表达基本食谱来实现自动化,运行 一个小厨房。
以不同的方式提出问题:LLVM 如何处理特定于时间的指令。那么我如何在 LLVM IR 中表达指令 mix flour with yeast for 30 seconds
?
I'm not sure if LLVM would be capable of handling a language where time/volume are dimensions that can be computed upon.
一般来说,你可以在 LLVM 中做你在 C 中可以做的任何事情。毕竟 clang 将 C 编译为 LLVM。
I would like to take this language, compile it, and transform it to valid C/Python code
如果你想生成 C and/or Python,就这样做吧。如果目标是机器 code/assembly,则通过 LLVM。 LLVM 不会帮助您生成 C 或 Python 代码。
How does LLVM handle time-specific instructions
您只需调用相应的 OS 或 libc 函数(或嵌入式平台上的等效函数)——就像在 C 中一样。例如,在 POSIX 上等待 30 秒系统,您将生成对 sleep
:
的调用
call i32 (i32) @sleep(i32 30)
您还必须为函数生成声明:
declare i32 @sleep(i32)
所以基本上你做的事情与你在手写 C 程序中所做的完全相同,除了使用 LLVM 的函数调用和声明语法而不是 C 的语法。
我想学习 LLVM。我想尝试使用以下食谱风格的语言来做到这一点:
Ingredients:
x-unit Flour
y-unit Yeast
z-unit Water
a-unit Sugar
Instructions:
bowl = mix flour with yeast for 30 seconds
bowl = mix bowl with sugar for 25 seconds
bowl = mix bowl with water for 1 minute
heat bowl for 3 hours
dough = split bowl into 3 parts
heat dough[n] at 450 f for 1 hour
由于这是一次学习经历,我不确定 LLVM 是否能够处理一种语言,其中 time/volume 是可以计算的维度。在阅读了一些文档之后,我不确定这是否是我想要做的事情的正确工具。
我想采用这种语言,对其进行编译,并将其转换为有效的 C/Python 代码,这样我就可以使用 RPi 或 Arduino 来执行程序。从本质上讲,我想尝试通过用这种语言表达基本食谱来实现自动化,运行 一个小厨房。
以不同的方式提出问题:LLVM 如何处理特定于时间的指令。那么我如何在 LLVM IR 中表达指令 mix flour with yeast for 30 seconds
?
I'm not sure if LLVM would be capable of handling a language where time/volume are dimensions that can be computed upon.
一般来说,你可以在 LLVM 中做你在 C 中可以做的任何事情。毕竟 clang 将 C 编译为 LLVM。
I would like to take this language, compile it, and transform it to valid C/Python code
如果你想生成 C and/or Python,就这样做吧。如果目标是机器 code/assembly,则通过 LLVM。 LLVM 不会帮助您生成 C 或 Python 代码。
How does LLVM handle time-specific instructions
您只需调用相应的 OS 或 libc 函数(或嵌入式平台上的等效函数)——就像在 C 中一样。例如,在 POSIX 上等待 30 秒系统,您将生成对 sleep
:
call i32 (i32) @sleep(i32 30)
您还必须为函数生成声明:
declare i32 @sleep(i32)
所以基本上你做的事情与你在手写 C 程序中所做的完全相同,除了使用 LLVM 的函数调用和声明语法而不是 C 的语法。