Skip to content

Commit

Permalink
[master] add --print-expansions command line option (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhrr committed Apr 14, 2015
1 parent d618532 commit 97c88c3
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 27 deletions.
Binary file modified man/dalec.1.gz
Binary file not shown.
8 changes: 5 additions & 3 deletions src/dale/Generator/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ Generator::run(std::vector<const char *> *file_paths,
int no_dale_stdlib,
int static_mods_all,
int enable_cto,
int print_expansions,
std::vector<std::string> *shared_object_paths,
FILE *output_file)
{
Expand Down Expand Up @@ -306,9 +307,10 @@ Generator::run(std::vector<const char *> *file_paths,
}

Units units(&mr);
units.cto = enable_cto;
units.no_common = no_common;
units.no_dale_stdlib = no_dale_stdlib;
units.cto = enable_cto;
units.no_common = no_common;
units.no_dale_stdlib = no_dale_stdlib;
units.print_expansions = print_expansions;

Context *ctx = NULL;
llvm::Module *mod = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/dale/Generator/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class Generator
* @param enable_cto Whether the module being compiled is a
* compile-time-only module (equivalent to (attr
* cto)).
* @param print_expansions Whether to print macro expansions.
* @param shared_object_paths The paths to shared objects against which
* the output file has to be linked
* (populated by this function).
Expand All @@ -74,6 +75,7 @@ class Generator
int no_dale_stdlib,
int static_mods_all,
int enable_cto,
int print_expansions,
std::vector<std::string> *shared_object_paths,
FILE *output_file);

Expand Down
19 changes: 18 additions & 1 deletion src/dale/MacroProcessor/MacroProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ MacroProcessor::setPoolfree()
}

Node *
MacroProcessor::parseMacroCall(Node *n, Function *macro_to_call)
MacroProcessor::parseMacroCall_(Node *n, Function *macro_to_call)
{
std::vector<Node *> *lst = n->list;

Expand Down Expand Up @@ -170,6 +170,23 @@ MacroProcessor::parseMacroCall(Node *n, Function *macro_to_call)
return result_node;
}

Node *
MacroProcessor::parseMacroCall(Node *n, Function *macro_to_call)
{
Node *result = parseMacroCall_(n, macro_to_call);
if (result && units->print_expansions) {
printf("%s:%d:%d: expansion: ",
n->filename,
n->getBeginPos()->getLineNumber(),
n->getBeginPos()->getColumnNumber());
n->print();
printf(" -> ");
result->print();
printf("\n");
}
return result;
}

Node *
MacroProcessor::parsePotentialMacroCall(Node *n)
{
Expand Down
10 changes: 10 additions & 0 deletions src/dale/MacroProcessor/MacroProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ class MacroProcessor
private:
Units *units;
Context *ctx;
/*! Parse a macro call.
* @param n The node list.
* @param macro_to_call The macro to call.
*
* parseMacroCall is a wrapper around this function: the reason
* for the split is that parseMacroCall will print the macro and
* the macro expansion, if the corresponding compilation option
* has been enabled and the macro was able to be expanded.
*/
Node* parseMacroCall_(Node *n, Function *macro_to_call);

public:
llvm::ExecutionEngine *ee;
Expand Down
9 changes: 6 additions & 3 deletions src/dale/Node/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,23 @@ Node::print()
{
if (is_token) {
if (token->type == TokenType::StringLiteral) {
printf("\"%s\" ", token->str_value.c_str());
printf("\"%s\"", token->str_value.c_str());
} else if (token->type == TokenType::Int
|| token->type == TokenType::String
|| token->type == TokenType::FloatingPoint) {
printf("%s ", token->str_value.c_str());
printf("%s", token->str_value.c_str());
} else {
printf("(Unknown) ");
printf("(Unknown)");
}
} else if (is_list) {
printf("(");
for (std::vector<Node *>::iterator b = list->begin(),
e = list->end();
b != e; ++b) {
(*b)->print();
if ((b + 1) != e) {
printf(" ");
}
}
printf(")");
} else {
Expand Down
2 changes: 2 additions & 0 deletions src/dale/Units/Units.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Units
/*! Whether the standard library (libdrt) should be imported into
* each new unit. */
bool no_dale_stdlib;
/*! Whether macro expansions should be printed to standard output. */
bool print_expansions;

/*! Construct a new Units object.
* @param mr A module reader.
Expand Down
43 changes: 23 additions & 20 deletions src/dale/dalec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,33 @@ main(int argc, char **argv)
int produce = ASM;
int optlevel = 0;

int produce_set = 0;
int no_linking = 0;
int debug = 0;
int no_dale_stdlib = 0;
int no_stdlib = 0;
int remove_macros = 0;
int no_common = 0;
int static_mods_all = 0;
int found_sm = 0;
int found_ctom = 0;
int enable_cto = 0;
int version = 0;
int produce_set = 0;
int no_linking = 0;
int debug = 0;
int no_dale_stdlib = 0;
int no_stdlib = 0;
int remove_macros = 0;
int no_common = 0;
int static_mods_all = 0;
int found_sm = 0;
int found_ctom = 0;
int enable_cto = 0;
int version = 0;
int print_expansions = 0;

int option_index = 0;
int forced_remove_macros = 0;

static struct option long_options[] = {
{ "no-dale-stdlib", no_argument, &no_dale_stdlib, 1 },
{ "no-common", no_argument, &no_common, 1 },
{ "no-stdlib", no_argument, &no_stdlib, 1 },
{ "static-modules", no_argument, &static_mods_all, 1 },
{ "static-module", required_argument, &found_sm, 1 },
{ "cto-module", required_argument, &found_ctom, 1 },
{ "enable-cto", no_argument, &enable_cto, 1 },
{ "version", no_argument, &version, 1 },
{ "no-dale-stdlib", no_argument, &no_dale_stdlib, 1 },
{ "no-common", no_argument, &no_common, 1 },
{ "no-stdlib", no_argument, &no_stdlib, 1 },
{ "static-modules", no_argument, &static_mods_all, 1 },
{ "static-module", required_argument, &found_sm, 1 },
{ "cto-module", required_argument, &found_ctom, 1 },
{ "enable-cto", no_argument, &enable_cto, 1 },
{ "version", no_argument, &version, 1 },
{ "print-expansions", no_argument, &print_expansions, 1 },
{ 0, 0, 0, 0 }
};

Expand Down Expand Up @@ -315,6 +317,7 @@ main(int argc, char **argv)
no_dale_stdlib,
static_mods_all,
enable_cto,
print_expansions,
&so_paths,
output_file);
if (!generated) {
Expand Down

0 comments on commit 97c88c3

Please sign in to comment.