提交 3c4a4c96 编写于 作者: 3 3dgen

Merge branch 'master' of https://gitee.com/wa-lang/wa

#! /bin/bash
wa native --target=avr arduino_blink.wa
wa native array_0.wa
wa native array_1.wa
wa native array_2.wa
wa native bitwise_logic.wa
wa native compare.wa
wa native convert_0.wa
wa native convert_1.wa
wa native convert_2.wa
wa native convert_3.wa
wa native float32.wa
wa native global_constant.wa
wa native global_variable_0.wa
wa native global_variable_1.wa
wa native heart.wa
wa native internal_function.wa
wa native loop_0.wa
wa native loop_1.wa
wa native multi_ret.wa
wa native pointer.wa
wa native prime.wa
wa native print_0.wa
wa native print_1.wa
wa native print_2.wa
wa native print_3.wa
wa native shift.wa
wa native struct_0.wa
wa native struct_1.wa
wa native struct_2.wa
wa native struct_3.wa
wa native unconditional_jump.wa
rm -f *.ll *.s
# Test the llvm backend.
# Test anonymous functions and closure functions.
fn main() {
print("Hello, ")
fn() {
println("World!")
}()
var i: int
show := fn() {
println("i = ", i)
}
for i = 0; i < 10; i++ {
show()
}
}
......@@ -44,6 +44,9 @@ func (opt *Option) Config() *config.Config {
case "arm64":
cfg.WaSizes.MaxAlign = 8
cfg.WaSizes.WordSize = 8
case "native":
cfg.WaSizes.MaxAlign = 8
cfg.WaSizes.WordSize = 8
default:
panic("todo")
}
......
......@@ -21,6 +21,7 @@ type Compiler struct {
output strings.Builder
debug bool
fmts []FmtStr
anofn []*ssa.Function
}
func New(target string, debug bool) *Compiler {
......@@ -142,6 +143,14 @@ func (p *Compiler) compilePackage(pkg *ssa.Package) error {
}
}
// Generate LLVM-IR for each internal function.
for _, v := range p.anofn {
if err := p.compileFunction(v); err != nil {
return err
}
}
p.anofn = []*ssa.Function{}
return nil
}
......
......@@ -387,6 +387,10 @@ func (p *Compiler) compileCall(val *ssa.Call) error {
// Emit the function name.
p.output.WriteString(" @")
callee := val.Call.StaticCallee()
// This callee is an internal function, whose body will be genereated later.
if callee.Parent() != nil {
p.anofn = append(p.anofn, callee)
}
if len(callee.LinkName()) > 0 {
p.output.WriteString(callee.LinkName())
} else {
......
......@@ -304,7 +304,7 @@ func main() {
}
infile = c.Args().First()
ctx := app.NewApp(build_Options(c))
ctx := app.NewApp(build_Options(c, true))
if err := ctx.LLVM(infile, outfile, target, debug); err != nil {
fmt.Println(err)
os.Exit(1)
......@@ -472,6 +472,7 @@ func build_Options(c *cli.Context, isLLVMBackend ...bool) *app.Option {
opt.TargetArch = "wasm"
if len(isLLVMBackend) > 0 && isLLVMBackend[0] {
opt.TargetArch = "native"
return opt
}
switch c.String("target") {
case "wa", config.WaOS_Walang:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册