From 94318b1287a5a9e13d30edd726578b3461d70461 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Fri, 22 Nov 2019 18:33:02 +0300 Subject: [PATCH] x64: use correct exe name and set +x --- .github/workflows/ci.yml | 2 +- tools/fast/{main.js => fast_main.js} | 0 vlib/compiler/gen_x64.v | 21 +-------------------- vlib/compiler/main.v | 20 ++++++++++++++++++++ vlib/compiler/x64/elf.v | 3 ++- 5 files changed, 24 insertions(+), 22 deletions(-) rename tools/fast/{main.js => fast_main.js} (100%) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a3075e203f..6b9a1fa3bd 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,7 +46,7 @@ jobs: - name: Bare metal run: ./v -freestanding -o bare vlib/os/bare/bare_example_linux.v - name: x64 machine code generation - run: ./v -x64 examples/x64/hello_world.v + run: cd examples/x64 && ./v -x64 hello_world.v && ./hello_world build-ubuntu-tcc: runs-on: ubuntu-18.04 diff --git a/tools/fast/main.js b/tools/fast/fast_main.js similarity index 100% rename from tools/fast/main.js rename to tools/fast/fast_main.js diff --git a/vlib/compiler/gen_x64.v b/vlib/compiler/gen_x64.v index 8638ea4830..963863306d 100644 --- a/vlib/compiler/gen_x64.v +++ b/vlib/compiler/gen_x64.v @@ -1,25 +1,6 @@ module compiler -import filepath +//import filepath //import compiler.x64 -pub fn (v mut V) compile_x64() { - $if !linux { - println('v -x64 can only generate Linux binaries for now') - println('You are not on a Linux system, so you will not ' + - 'be able to run the resulting executable') - } - - v.files << v.v_files_from_dir(filepath.join(v.pref.vlib_path, 'builtin', 'bare')) - v.files << v.dir - v.x64.generate_elf_header() - for f in v.files { - v.parse(f, .decl) - } - for f in v.files { - v.parse(f, .main) - } - v.x64.generate_elf_footer() - -} diff --git a/vlib/compiler/main.v b/vlib/compiler/main.v index 9e6eac667e..e101a039e5 100644 --- a/vlib/compiler/main.v +++ b/vlib/compiler/main.v @@ -347,6 +347,26 @@ pub fn (v mut V) compile() { v.cc() } +pub fn (v mut V) compile_x64() { + $if !linux { + println('v -x64 can only generate Linux binaries for now') + println('You are not on a Linux system, so you will not ' + + 'be able to run the resulting executable') + } + + v.files << v.v_files_from_dir(filepath.join(v.pref.vlib_path, 'builtin', 'bare')) + v.files << v.dir + v.x64.generate_elf_header() + for f in v.files { + v.parse(f, .decl) + } + for f in v.files { + v.parse(f, .main) + } + v.x64.generate_elf_footer() + +} + fn (v mut V) generate_init() { $if js { return } if v.pref.build_mode == .build_module { diff --git a/vlib/compiler/x64/elf.v b/vlib/compiler/x64/elf.v index e79260a2dd..04dbd62949 100644 --- a/vlib/compiler/x64/elf.v +++ b/vlib/compiler/x64/elf.v @@ -88,7 +88,8 @@ pub fn (g mut Gen) generate_elf_footer() { g.write64_at(file_size, g.file_size_pos) // set file size 64 bit value g.write64_at(file_size, g.file_size_pos+8) // Create the binary - f := os.create('out.bin') or { panic(err) } + f := os.create(g.out_name) or { panic(err) } + C.chmod(g.out_name.str, 0775) f.write_bytes(g.buf.data, g.buf.len) f.close() println('x64 elf binary has been successfully generated')