mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-20 12:31:40 +00:00
Allow (set_option SwitchOption, true).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91997 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
76d2f9a4db
commit
e0b6570d24
@ -1,4 +1,4 @@
|
|||||||
// Test for the OptionPreprocessor and any*.
|
// Test for the OptionPreprocessor and related functionality.
|
||||||
// RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
|
// RUN: tblgen -I %p/../../include --gen-llvmc %s -o %t
|
||||||
// RUN: FileCheck -input-file %t %s
|
// RUN: FileCheck -input-file %t %s
|
||||||
// RUN: %compile_cxx -fexceptions -x c++ %t
|
// RUN: %compile_cxx -fexceptions -x c++ %t
|
||||||
@ -26,13 +26,18 @@ def Preprocess : OptionPreprocessor<
|
|||||||
(unset_option "foo_p"), (unset_option "foo_l")],
|
(unset_option "foo_p"), (unset_option "foo_l")],
|
||||||
// CHECK: W2
|
// CHECK: W2
|
||||||
// CHECK: foo = true;
|
// CHECK: foo = true;
|
||||||
|
// CHECK: bar = true;
|
||||||
|
// CHECK: baz = false;
|
||||||
// CHECK: foo_p = "asdf";
|
// CHECK: foo_p = "asdf";
|
||||||
// CHECK: foo_l.clear();
|
// CHECK: foo_l.clear();
|
||||||
// CHECK: foo_l.push_back("qwert");
|
// CHECK: foo_l.push_back("qwert");
|
||||||
// CHECK: foo_l.push_back("yuiop");
|
// CHECK: foo_l.push_back("yuiop");
|
||||||
// CHECK: foo_l.push_back("asdf");
|
// CHECK: foo_l.push_back("asdf");
|
||||||
(and (switch_on ["foo", "bar"]), (any_empty ["foo_p", "bar_p"])),
|
(and (switch_on ["foo", "bar"]), (any_empty ["foo_p", "bar_p"])),
|
||||||
[(warning "W2"), (set_option "foo"), (set_option "foo_p", "asdf"),
|
[(warning "W2"), (set_option "foo"),
|
||||||
|
(set_option "bar", true),
|
||||||
|
(set_option "baz", false),
|
||||||
|
(set_option "foo_p", "asdf"),
|
||||||
(set_option "foo_l", ["qwert", "yuiop", "asdf"])],
|
(set_option "foo_l", ["qwert", "yuiop", "asdf"])],
|
||||||
// CHECK: W3
|
// CHECK: W3
|
||||||
// CHECK: foo = true;
|
// CHECK: foo = true;
|
||||||
|
@ -690,13 +690,16 @@ specified, ``-O2`` is enabled.
|
|||||||
|
|
||||||
``OptionPreprocessor`` is basically a single big ``case`` expression, which is
|
``OptionPreprocessor`` is basically a single big ``case`` expression, which is
|
||||||
evaluated only once right after the plugin is loaded. The only allowed actions
|
evaluated only once right after the plugin is loaded. The only allowed actions
|
||||||
in ``OptionPreprocessor`` are ``error``, ``warning`` and two special actions:
|
in ``OptionPreprocessor`` are ``error``, ``warning``, and two special actions:
|
||||||
``unset_option`` and ``set_option``. As their names suggest, they can be used to
|
``unset_option`` and ``set_option``. As their names suggest, they can be used to
|
||||||
set or unset a given option. To set a parameter option with ``set_option``, use
|
set or unset a given option. To set an option with ``set_option``, use the
|
||||||
the two-argument form: ``(set_option "parameter", "value")``. For convenience,
|
two-argument form: ``(set_option "parameter", VALUE)``. Here, ``VALUE`` can be
|
||||||
``set_option`` and ``unset_option`` also work on lists (that is, instead of
|
either a string, a string list, or a boolean constant.
|
||||||
``[(unset_option "A"), (unset_option "B")]`` you can use ``(unset_option ["A",
|
|
||||||
"B"])``).
|
For convenience, ``set_option`` and ``unset_option`` also work on lists. That
|
||||||
|
is, instead of ``[(unset_option "A"), (unset_option "B")]`` you can use
|
||||||
|
``(unset_option ["A", "B"])``. Obviously, ``(set_option ["A", "B"])`` is valid
|
||||||
|
only if both ``A`` and ``B`` are switches.
|
||||||
|
|
||||||
|
|
||||||
More advanced topics
|
More advanced topics
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
#include "llvm/ADT/IntrusiveRefCntPtr.h"
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/ADT/StringSet.h"
|
#include "llvm/ADT/StringSet.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
@ -89,6 +90,17 @@ const std::string GetOperatorName(const DagInit& D) {
|
|||||||
return D.getOperator()->getAsString();
|
return D.getOperator()->getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// CheckBooleanConstant - Check that the provided value is a boolean constant.
|
||||||
|
void CheckBooleanConstant(const Init* I) {
|
||||||
|
const DefInit& val = dynamic_cast<const DefInit&>(*I);
|
||||||
|
const std::string& str = val.getAsString();
|
||||||
|
|
||||||
|
if (str != "true" && str != "false") {
|
||||||
|
throw "Incorrect boolean value: '" + str +
|
||||||
|
"': must be either 'true' or 'false'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// checkNumberOfArguments - Ensure that the number of args in d is
|
// checkNumberOfArguments - Ensure that the number of args in d is
|
||||||
// greater than or equal to min_arguments, otherwise throw an exception.
|
// greater than or equal to min_arguments, otherwise throw an exception.
|
||||||
void checkNumberOfArguments (const DagInit& d, unsigned minArgs) {
|
void checkNumberOfArguments (const DagInit& d, unsigned minArgs) {
|
||||||
@ -2309,8 +2321,8 @@ class EmitPreprocessOptionsCallback :
|
|||||||
|
|
||||||
const OptionDescriptions& OptDescs_;
|
const OptionDescriptions& OptDescs_;
|
||||||
|
|
||||||
void onListOrDag(HandlerImpl h,
|
void onListOrDag(const DagInit& d, HandlerImpl h,
|
||||||
const DagInit& d, unsigned IndentLevel, raw_ostream& O) const
|
unsigned IndentLevel, raw_ostream& O) const
|
||||||
{
|
{
|
||||||
checkNumberOfArguments(d, 1);
|
checkNumberOfArguments(d, 1);
|
||||||
const Init* I = d.getArg(0);
|
const Init* I = d.getArg(0);
|
||||||
@ -2350,12 +2362,12 @@ class EmitPreprocessOptionsCallback :
|
|||||||
void onUnsetOption(const DagInit& d,
|
void onUnsetOption(const DagInit& d,
|
||||||
unsigned IndentLevel, raw_ostream& O) const
|
unsigned IndentLevel, raw_ostream& O) const
|
||||||
{
|
{
|
||||||
this->onListOrDag(&EmitPreprocessOptionsCallback::onUnsetOptionImpl,
|
this->onListOrDag(d, &EmitPreprocessOptionsCallback::onUnsetOptionImpl,
|
||||||
d, IndentLevel, O);
|
IndentLevel, O);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSetListOrParameter(const DagInit& d,
|
void onSetOptionImpl(const DagInit& d,
|
||||||
unsigned IndentLevel, raw_ostream& O) const {
|
unsigned IndentLevel, raw_ostream& O) const {
|
||||||
checkNumberOfArguments(d, 2);
|
checkNumberOfArguments(d, 2);
|
||||||
const std::string& OptName = InitPtrToString(d.getArg(0));
|
const std::string& OptName = InitPtrToString(d.getArg(0));
|
||||||
const Init* Value = d.getArg(1);
|
const Init* Value = d.getArg(1);
|
||||||
@ -2371,13 +2383,18 @@ class EmitPreprocessOptionsCallback :
|
|||||||
<< InitPtrToString(*B) << "\");\n";
|
<< InitPtrToString(*B) << "\");\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (OptDesc.isSwitch()) {
|
||||||
|
CheckBooleanConstant(Value);
|
||||||
|
O.indent(IndentLevel) << OptDesc.GenVariableName()
|
||||||
|
<< " = " << Value->getAsString() << ";\n";
|
||||||
|
}
|
||||||
else if (OptDesc.isParameter()) {
|
else if (OptDesc.isParameter()) {
|
||||||
const std::string& Str = InitPtrToString(Value);
|
const std::string& Str = InitPtrToString(Value);
|
||||||
O.indent(IndentLevel) << OptDesc.GenVariableName()
|
O.indent(IndentLevel) << OptDesc.GenVariableName()
|
||||||
<< " = \"" << Str << "\";\n";
|
<< " = \"" << Str << "\";\n";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw "set_option: -" + OptName + ": is not a list or parameter option!";
|
throw "Can't apply 'set_option' to alias option -" + OptName + " !";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2397,15 +2414,15 @@ class EmitPreprocessOptionsCallback :
|
|||||||
{
|
{
|
||||||
checkNumberOfArguments(d, 1);
|
checkNumberOfArguments(d, 1);
|
||||||
|
|
||||||
// Two arguments: (set_option "parameter", VALUE), where VALUE is either a
|
// Two arguments: (set_option "parameter", VALUE), where VALUE can be a
|
||||||
// string or a string list.
|
// boolean, a string or a string list.
|
||||||
if (d.getNumArgs() > 1)
|
if (d.getNumArgs() > 1)
|
||||||
this->onSetListOrParameter(d, IndentLevel, O);
|
this->onSetOptionImpl(d, IndentLevel, O);
|
||||||
// One argument: (set_option "switch")
|
// One argument: (set_option "switch")
|
||||||
// or (set_option ["switch1", "switch2", ...])
|
// or (set_option ["switch1", "switch2", ...])
|
||||||
else
|
else
|
||||||
this->onListOrDag(&EmitPreprocessOptionsCallback::onSetSwitch,
|
this->onListOrDag(d, &EmitPreprocessOptionsCallback::onSetSwitch,
|
||||||
d, IndentLevel, O);
|
IndentLevel, O);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user