commit ca29c4b2bd36d3b2cf91138e833d90ebd70c16d9
parent 97bfa84664dfa183e3b76f9b0e0d162d398d5f98
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 6 Mar 2021 16:31:13 -0500
Refactor schedule planning code
Diffstat:
M | main.ha | | | 36 | +++--------------------------------- |
M | plan.ha | | | 44 | +++++++++++++++++++++++++++++++++++++++++++- |
2 files changed, 46 insertions(+), 34 deletions(-)
diff --git a/main.ha b/main.ha
@@ -12,18 +12,18 @@ export fn main() void = {
fmt::fatal("Usage: {} <path>", os::args[0]);
};
+ let plan = plan { ... };
let ctx = module::context_init([module::tag{
name = os::machine(),
mode = module::tag_mode::INCLUSIVE,
}]);
+
let ver = match (module::scan(&ctx, os::args[1])) {
ver: module::version => ver,
err: module::error => fmt::fatal("Error scanning module: {}",
module::errstr(err)),
};
- let plan = plan { ... };
-
for (let i = 0z; i < len(ver.depends); i += 1z) {
const dep = ver.depends[i];
let ident = ast::ident_unparse_s(dep);
@@ -44,20 +44,7 @@ export fn main() void = {
};
};
- let harec = alloc(task {
- status = status::SCHEDULED,
- inputs = ver.inputs,
- output = "hare.ssa",
- cmd = alloc(["harec"]),
- ...
- });
-
- for (let i = 0z; i < len(ver.inputs); i += 1) {
- let path = ver.inputs[i].path as str;
- append(harec.cmd, path);
- };
-
- append(plan.scheduled, harec);
+ sched_hare_exe(&plan, ver.inputs, "hare.ssa", []);
for (len(plan.scheduled) != 0) {
let next: nullable *task = null;
@@ -87,20 +74,3 @@ export fn main() void = {
append(plan.complete, task);
};
};
-
-fn execute(
- ctx: *module::context,
- task: *task,
-) (void | exec::error | exec::exit_status!) = {
- for (let i = 0z; i < len(task.cmd); i += 1) {
- fmt::errorf("{} ", task.cmd[i]);
- };
- fmt::errorln();
-
- let cmd = exec::cmd(task.cmd[0], task.cmd[1..]...)?;
- exec::setenv(&cmd, "HARECACHE", ctx.cache as str);
-
- let proc = exec::start(&cmd)?;
- let st = exec::wait(&proc)?;
- return exec::check(&st)?;
-};
diff --git a/plan.ha b/plan.ha
@@ -1,4 +1,6 @@
+use fmt;
use hare::module;
+use os::exec;
type status = enum {
SCHEDULED,
@@ -9,7 +11,7 @@ type task = struct {
status: status,
inputs: []module::input,
depend: []*task,
- output: str,
+ output: path::path,
cmd: []str,
};
@@ -17,3 +19,43 @@ type plan = struct {
scheduled: []*task,
complete: []*task,
};
+
+fn sched_hare_exe(
+ plan: *plan,
+ inputs: []module::input,
+ output: path::path,
+ depend: []*task,
+) *task = {
+ // TODO: Schedule the qbe, as, and ld tasks
+ let task = alloc(task {
+ status = status::SCHEDULED,
+ inputs = inputs,
+ output = output,
+ depend = depend,
+ // TODO: Get harec from environment
+ cmd = alloc(["harec", "-o", output as str]),
+ });
+ for (let i = 0z; i < len(inputs); i += 1) {
+ let path = inputs[i].path as str;
+ append(task.cmd, path);
+ };
+ append(plan.scheduled, task);
+ return task;
+};
+
+fn execute(
+ ctx: *module::context,
+ task: *task,
+) (void | exec::error | exec::exit_status!) = {
+ for (let i = 0z; i < len(task.cmd); i += 1) {
+ fmt::errorf("{} ", task.cmd[i]);
+ };
+ fmt::errorln();
+
+ let cmd = exec::cmd(task.cmd[0], task.cmd[1..]...)?;
+ exec::setenv(&cmd, "HARECACHE", ctx.cache as str);
+
+ let proc = exec::start(&cmd)?;
+ let st = exec::wait(&proc)?;
+ return exec::check(&st)?;
+};