Skip to content

Commit

Permalink
[cpp] buildmeta - added add_source function, which adds a path to a…
Browse files Browse the repository at this point in the history
…n input file to the current build. note that this is a path relative to the cwd of the running psyc.
  • Loading branch information
harrand committed May 23, 2024
1 parent 3ede2f8 commit 76fc16f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
25 changes: 24 additions & 1 deletion cpp/src/build.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,19 @@ void set_output_name(const char* name)
cur_build_info->link_name = name;
}

void add_source(const char* name)
{
cur_build_info->extra_input_files.push_back(name);
}

void install_functions(llvm::ExecutionEngine& exe)
{
exe.addGlobalMapping("set_linkage_type", reinterpret_cast<std::uintptr_t>(&set_linkage_type));
exe.addGlobalMapping("set_build_type", reinterpret_cast<std::uintptr_t>(&set_build_type));
exe.addGlobalMapping("set_output_name", reinterpret_cast<std::uintptr_t>(&set_output_name));
exe.addGlobalMapping("add_source", reinterpret_cast<std::uintptr_t>(&add_source));
}


namespace build
{

Expand Down Expand Up @@ -229,6 +234,24 @@ namespace build
.is_extern = true
}
});
ret.root.children.push_back(ast::node
{
.payload = ast::function_definition
{
.func_name = "add_source",
.params =
{
ast::variable_declaration
{
.var_name = "filename",
.type_name = "i8&",
.initialiser = ast::expression{.expr = ast::null_literal{}}
},
},
.ret_type = "u0",
.is_extern = true
}
});

// same with some globals.
for(int i = 0; i < (int)build::linkage_type::_count; i++)
Expand Down
1 change: 1 addition & 0 deletions cpp/src/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ namespace lex
tokenise_state state;

std::ifstream fstr(psy_file);
diag::assert_that(fstr.good(), error_code::badargs, "could not open input file \"{}\"", psy_file.string());
// slurp the whole file into a string.
std::stringstream buffer;
buffer << fstr.rdbuf();
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/psyc_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ int main(int argc, char** argv)
std::size_t metacodegen = 0;
binfo = build::gather(args, &metalex, &metaparse, &metasemal, &metacodegen);
t.buildmeta = metalex + metaparse + metasemal + metacodegen;

for(std::filesystem::path extra : binfo.extra_input_files)
{
binfo.compiler_args.input_files.push_back(extra);
}
}
// remember: binfo might have extra input files than was specified in the command line.
// this is because build meta regions are allowed to add extra inputs.
Expand Down

0 comments on commit 76fc16f

Please sign in to comment.