The src/task Directory

Namespace task, delivered for TC-1.

Tasks are what handles the execution of components of our compiler. It is a bridge between command-line arguments passed to tc and Tiger modules. In TC, tasks implementation follows the Command pattern.

Tasks can be combined to create a complete execution pipeline. For example tc --parse --ast-display --bidings-compute --ast-display 1+1.tig will parse the input file (TC-1 libparse), then display its AST (TC-2 libast), then compute its bindings (TC-3 libbind) and finally re-display its AST.

However, we can also handle things smarter by allowing tasks to have dependencies over other tasks: when we compute the bindings of our AST, we expect that the input program has been parsed and put into the form of an AST. Thus, bindings-compute task has a dependency over parse. When processing tasks, the task-register will trigger parse before triggering bindings-compute. To have more information about the task pipeline your input is going by, you can use libtask’s tasks.

$ tc --task-selection --asm-compute 1+1.tig
List of Task Order:
	* task-selection
	* parse
	* bindings-compute
	* types-compute
	* typed
	* hir-compute
	* canon-compute
	* traces-compute
	* lir-compute
	* target-mips
	* targeted
	* inst-compute
	* asm-compute
$ echo $?
0

To go further

Tasks generation is handled through various macros defined in src/tasks. These macros take care of:

  • creating a class specific to each task.

  • instantiate a static object of this class.

  • register this object to a global vector of registered tasks.

These registered tasks will be enabled through the main function, depending on the arguments passed to the program. Tasks which are enabled have their execute method run. If no task is enabled, parse is enabled as fallback.

flowchart TD S[Preprocessing: Expand macros in tasks.hh] S --> T[Instanciate Task class associated] A[Execution: main function is called] A --> B[parse_arg: build \n vector of enabled tasks] B --> D{Execute Tasks: run \nexecute method from tasks} D --> J[End of program]

File: libtask.hh

Exports task instantiation macros.

TASK_GROUP(Name)
  • Name: The task group name

define the current task group’s name.

TASK_DECLARE(Name, Help, Routine, Deps)
  • Name: The task’s name

  • Help: The string showed in tc --help for this task

  • Routine: The function executed when the task is used (usually defined in tasks.cc)

  • Deps: The task’s dependencies (tasks that will be executed before this one)

The most frequent task in Tiger. It executes the Routine when used.

BOOLEAN_TASK_DECLARE(Name, Help, Flag, Deps)
  • Name: The task’s name

  • Help: The string showed in tc --help for this task

  • Flag: The boolean that will be set by the task

  • Deps: The task’s dependencies (tasks that will be executed before this one)

This tasks is used to enable some behaviour with the Flag.

INT_TASK_DECLARE(Name, Min, Max, Help, Flag, Deps)
  • Name: The task’s name

  • Min: The minimum value of the int stored in the task.

  • Max: The maximum value of the int stored in the task.

  • Help: The string showed in tc --help for this task

  • Flag: The int that will be set by the task

  • Deps: The task’s dependencies (tasks that will be executed before this one)

Initialize Flag to the int value given by the command line.

STRING_TASK_DECLARE(Name, Default, Help, Flag, Deps)
  • Name: The task’s name

  • Default: The default value of the Flag

  • Help: The string showed in tc --help for this task

  • Flag: The string that will be set by the task

  • Deps: The task’s dependencies (tasks that will be executed before this one)

Set the Flag to the string value given by the command line.

MULTIPLE_STRING_TASK_DECLARE(Name, Help, Routine, Deps)
  • Name: The task’s name

  • Help: The string showed in tc --help for this task

  • Routine: The function executed when the task is used (usually defined in tasks.cc) with the next word in the command line as an argument

  • Deps: The task’s dependencies (tasks that will be executed before this one)

Execute the Routine with, as an argument, the next value given in the command line.

DISJUNCTIVE_TASK_DECLARE(Name, Help, Deps)
  • Name: The task’s name

  • Help: The string showed in tc --help for this task

  • Deps: List of dependencies from which the disjunctive task have to choose depending of the context

This task use the right task from the Deps, depending on which flags were set.

File: task-register.{hh|hxx}

The brain behind tasks. It is responsible for collecting tasks and organize their execution using their dependencies (like make).

File: simple-task.{cc|hh}

Represents tasks that cannot hold an argument.

File: function-task.{cc|hh}

A simple task that invokes a callback function. This is the most frequently used task, as it is the one that can actually run things.

File: disjunctive-task.{cc|hh}

A simple task that makes sure that at least one of its dependencies is scheduled.

File: argument-task.{cc|hh}

Represents tasks that can hold an argument.

File: {boolean|int|string}-task.{cc|hh}

An argument task that sets a Boolean / Integer / String variable to true.

File: multiple-string-task.{cc|hh}

An argument task that invokes a callback function with string arguments.

File: tasks.{cc|hh}

Contains libtask related tasks.