kconfig2sat: $(OBJ_CC) $(OBJ_C)
g++ $(CXXFLAGS) $(CFLAGS) -o $@ $^
-%.o: %.c
- gcc -c $(CFLAGS) -o $@ $^
+%.o: %.c *.h kconfig/*.h
+ gcc -c $(CFLAGS) -o $@ $<
-%.o: %.cc
- g++ -c $(CXXFLAGS) $(CFLAGS) -o $@ $^
+%.o: %.cc *.h kconfig/*.h
+ g++ -c $(CXXFLAGS) $(CFLAGS) -o $@ $<
%.hash.c: %.gperf
gperf -t --output-file $@ -a -C -E -g -k '1,3,$$' -p -t $<
#include "kconfig/lkc.h"
#include "lcp_utils.h"
+#include <vector>
+
+using namespace std;
+
int verbosity = 0;
enum options {
if (!prompt) {
fprintf(stderr, "%s:%d: Warning: Symbol %s is internal (has no prompt)\n", varfile, lineno, sym_name);
}
+ sym->lcp->variable = 1;
}
+ fclose(f);
}
+void write_dimacs_cnf(const char *cnf)
+{
+ FILE *f = fopen(cnf, "w");
+
+ if (!f) {
+ perror(cnf);
+ exit(EXIT_FAILURE);
+ }
+
+ fclose(f);
+}
+
+struct SatLiteral {
+ struct symbol *sym;
+ struct expr *expr;
+
+ SatLiteral(struct symbol *s) : sym(s), expr(nullptr) {}
+ SatLiteral(struct expr *e) : sym(nullptr), expr(e) {}
+};
+
+struct SatClause {
+ // TODO
+};
+
+class SatLiterals : public vector<struct SatLiteral>
+{
+public:
+ int fixed = {0};
+ SatLiterals() { push_back(SatLiteral((struct symbol*)nullptr)); reserve(20000); }
+ int count() const { return size() - 1; }
+};
+
+class SatData {
+ SatLiterals literals = {};
+ vector<SatClause> clauses = {};
+public:
+
+ SatData() {
+ int i;
+ struct symbol *sym;
+
+ for_all_symbols(i, sym) {
+ if (sym->type == S_BOOLEAN || sym->type == S_TRISTATE) {
+ literals.push_back(SatLiteral(sym));
+ sym->lcp = new lcp_symbol;
+ memset(sym->lcp, 0, sizeof(*sym->lcp));
+ sym->lcp->sat_id = literals.count();
+ }
+ }
+ }
+
+ void write_dimacs_cnf(const char *cnf) {
+ int i;
+ FILE *f = fopen(cnf, "w");
+
+ if (!f) {
+ perror(cnf);
+ exit(EXIT_FAILURE);
+ }
+
+ fprintf(f, "p cnf %d %lu\n", literals.count(), clauses.size() + literals.fixed);
+
+ for (i = 1; i <= literals.count(); i++) {
+ SatLiteral &l = literals[i];
+ if (l.sym)
+ fprintf(f, "c SYM %d %s\n", l.sym->lcp->sat_id, l.sym->name);
+ if (l.sym && l.sym->flags & SYMBOL_VALID && !l.sym->lcp->variable)
+ fprintf(f, "%d 0\n", l.sym->curr.tri != no ? l.sym->lcp->sat_id : -l.sym->lcp->sat_id);
+ }
+ fclose(f);
+ }
+};
+
+
int main(int argc, char **argv)
{
int c;
textdomain(PACKAGE);
conf_parse_path(kconfig);
+ SatData sat_data;
if (baseconf)
conf_read(baseconf);
if (dump)
do_dump();
-// char *rules_file, *symbol_map_file, *variable_count_file;
-// asprintf(&rules_file, "%s/%s", folder, DEFAULT_RULES_FILE);
-// asprintf(&symbol_map_file, "%s/%s", folder, DEFAULT_SYMBOL_MAP_FILE);
-// asprintf(&variable_count_file, "%s/%s", folder,
-// DEFAULT_VARIABLE_COUNT_FILE);
-// output_init(rules_file, symbol_map_file);
-// build_symlist();
-// cpy_dep();
-
-// output_write_variable_count(variable_count_file,
-// gsymlist->lastsym - 1, gsymlist->pos);
+ if (cnf) {
+ sat_data.write_dimacs_cnf(cnf);
+ }
-// output_finish();
return EXIT_SUCCESS;
}