-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
896 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module main | ||
|
||
import v.builder.qbebuilder | ||
|
||
fn main() { | ||
qbebuilder.start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
```bash | ||
# compile qbe_builder | ||
v cmd/tools/builders/qbe_builder.v -g -path "./vlib|@vmodules" -o ./qbe_builder | ||
|
||
# generate IL | ||
VTMP=./tmp ./qbe_builder qbe-test.v -skip-unused -no-builtin | ||
|
||
# oneliner for above | ||
v cmd/tools/builders/qbe_builder.v -g -path "./vlib|@vmodules" -o ./qbe_builder -v && VTMP=./tmp ./qbe_builder qbe-test.v -skip-unused -no-builtin -g -v | ||
|
||
# generate assembly | ||
../qbe/qbe tmp/qbe-test.ssa > tmp/qbe-test.s | ||
|
||
# final compilation | ||
cc -g -Lc tmp/qbe-test.s -o tmp/qbe-test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
module qbebuilder | ||
|
||
import v.pref | ||
import v.util | ||
import v.builder | ||
import v.gen.qbe | ||
import os | ||
|
||
pub fn start() { | ||
mut args_and_flags := util.join_env_vflags_and_os_args()[1..] | ||
prefs, _ := pref.parse_args([], args_and_flags) | ||
builder.compile('build', prefs, compile_qbe) | ||
} | ||
|
||
pub fn compile_qbe(mut b builder.Builder) { | ||
mut files := b.get_builtin_files() | ||
files << b.get_user_files() | ||
b.set_module_lookup_paths() | ||
if b.pref.is_verbose { | ||
println('all .v files:') | ||
println(files) | ||
} | ||
out_name := b.pref.out_name | ||
|
||
// TODO: replace latter with get_vtmp_filename below | ||
vtmp := os.vtmp_dir() | ||
fname := os.file_name(os.real_path(out_name)) + '.tmp.ssa' | ||
out_name_ssa := os.real_path(os.join_path(vtmp, fname)) | ||
// out_name_ssa := b.get_vtmp_filename(b.pref.out_name, '.tmp.ssa') | ||
out_name_s := out_name_ssa#[..-3] + 'S' | ||
build_qbe(mut b, files, out_name_ssa) | ||
if !os.exists_in_system_path('qbe') { | ||
eprintln('qbe executable not found in PATH!') | ||
eprintln('Please install it from https://c9x.me/compile/releases.html') | ||
return | ||
} | ||
// QBE suports amd64_sysv (default), amd64_apple, arm64, arm64_apple, rv64 | ||
// arch := if b.pref.arch in [.amd64, .arm64, .rv64] { | ||
// b.pref.arch.str() | ||
// } else { | ||
// eprintln('Unsuported architecture ${b.pref.arch}') | ||
// exit(1) | ||
// } | ||
// os := match b.pref.os { | ||
// .linux { 'sysv' } | ||
// .macos { 'apple' } | ||
// } | ||
// target := '${arch}_' | ||
res := os.execute('qbe ${out_name_ssa} > ${out_name_s}') | ||
if res.exit_code != 0 { | ||
eprintln(res.output) | ||
exit(res.exit_code) | ||
} | ||
res_cc := os.execute('cc -g -Lc ${out_name_s} -o ${out_name}') | ||
if res_cc.exit_code != 0 { | ||
eprintln(res_cc.output) | ||
exit(res_cc.exit_code) | ||
} | ||
} | ||
|
||
pub fn build_qbe(mut b builder.Builder, v_files []string, out_file string) { | ||
b.front_and_middle_stages(v_files) or { return } | ||
util.timing_start('QBE GEN') | ||
qbe.gen(b.parsed_files, mut b.table, out_file, b.pref) | ||
util.timing_measure('QBE GEN') | ||
} |
Oops, something went wrong.